Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: fails. What you expected to happen: I would expect the PatchOptions to not include FieldManager. The following fix will eliminate the problem. How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment: Kubernetes version (use ): 1.16 and 1.17 Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others:
/sig cli
cc
/wg apply
cc
I agree, we clearly missed that. Would you mind sending the fix in the form of a PR? Also please include a test, because that shouldn't have happened if I had tested my code properly :-(
Clearly we should also cherry-pick that into 1.17. I'll send the PR on Monday if you prefer! Thanks.
Ok, I will send a PR. However, I can't include a test immediately because I don't understand how the test works.
Thanks, I’ll try to show you how to get started!
Any update we clearly need this promptly since code-freeze is coming! Thanks.
I'll send a PR on Monday if you haven't! Thanks.
Sorry, I haven't started working on this test. Thanks.

Discussion:
KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff command. By default, the "diff" command available in your path will be run with "-u" (unified diff) and "-N" (treat absent files as empty) options. Exit status: 0 No differences were found.

FilenameOptions resource.FilenameOptions ServerSideApply bool <ins> FieldManager    string </ins> ForceConflicts  bool OpenAPISchema    openapi.Resources

OpenAPI         openapi.Resources Force           bool ServerSideApply bool <ins> FieldManager    string </ins> ForceConflicts  bool genericclioptions.IOStreams }

return nil, err } options := metav1.PatchOptions{ <del> Force:  &obj.ForceConflicts, DryRun: []string{metav1.DryRunAll}, </del> <ins> Force:        &obj.ForceConflicts, FieldManager: obj.FieldManager, DryRun:       []string{metav1.DryRunAll}, </ins> } return resource.NewHelper(obj.Info.Client, obj.Info.Mapping).Patch( obj.Info.Namespace,

} o.ServerSideApply = cmdutil.GetServerSideApplyFlag(cmd) <ins> o.FieldManager = cmdutil.GetFieldManagerFlag(cmd) </ins> o.ForceConflicts = cmdutil.GetForceConflictsFlag(cmd) if o.ForceConflicts && !o.ServerSideApply { return fmt.Errorf("--force-conflicts only works with --server-side")

OpenAPI:         o.OpenAPISchema, Force:           force, ServerSideApply: o.ServerSideApply, <ins> FieldManager:    o.FieldManager, </ins> ForceConflicts:  o.ForceConflicts, IOStreams:       o.Diff.IOStreams, }

# Test that it works when the live object doesn't exist output_message=$(! kubectl diff -f hack/testdata/pod.yaml) kube::test::if_has_string "${output_message}" 'test-pod' <ins> # Ensure diff only dry-runs and doesn't persist change kube::test::get_object_assert 'pod' "{{range.items}}{{ if eq ${id_field:?} "test-pod" }}found{{end}}{{end}}:" ':' </ins> kubectl apply -f hack/testdata/pod.yaml <ins> kube::test::get_object_assert 'pod' "{{range.items}}{{ if eq ${id_field:?} "test-pod" }}found{{end}}{{end}}:" 'found:' </ins> # Make sure that diffing the resource right after returns nothing (0 exit code). kubectl diff -f hack/testdata/pod.yaml

output_message=$(kubectl diff -f hack/testdata/pod-changed.yaml || test $? -eq 1) kube::test::if_has_string "${output_message}" 'k8s.gcr.io/pause:3.0' <ins> # Test found diff with server-side apply kubectl apply -f hack/testdata/pod.yaml output_message=$(kubectl diff -f hack/testdata/pod-changed.yaml --server-side --force-conflicts || test $? -eq 1) kube::test::if_has_string "${output_message}" 'k8s.gcr.io/pause:3.0' </ins> # Test that we have a return code bigger than 1 if there is an error when diffing kubectl diff -f hack/testdata/invalid-pod.yaml || test $? -gt 1