Set field manager for kubectl diff --server-side.
Bonus: check diff only dry-runs without persisting. Co-authored-by: Takahiro HATORI <tahatori@zlab.co.jp> Kubernetes-commit: bacc2c49605f608d3f919109e0c37ebf6e1d7036
This commit is contained in:
parent
206f22581e
commit
87fc988437
|
@ -57,7 +57,7 @@ var (
|
|||
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.
|
||||
|
@ -92,6 +92,7 @@ type DiffOptions struct {
|
|||
FilenameOptions resource.FilenameOptions
|
||||
|
||||
ServerSideApply bool
|
||||
FieldManager string
|
||||
ForceConflicts bool
|
||||
|
||||
OpenAPISchema openapi.Resources
|
||||
|
@ -296,6 +297,7 @@ type InfoObject struct {
|
|||
OpenAPI openapi.Resources
|
||||
Force bool
|
||||
ServerSideApply bool
|
||||
FieldManager string
|
||||
ForceConflicts bool
|
||||
genericclioptions.IOStreams
|
||||
}
|
||||
|
@ -316,8 +318,9 @@ func (obj InfoObject) Merged() (runtime.Object, error) {
|
|||
return nil, err
|
||||
}
|
||||
options := metav1.PatchOptions{
|
||||
Force: &obj.ForceConflicts,
|
||||
DryRun: []string{metav1.DryRunAll},
|
||||
Force: &obj.ForceConflicts,
|
||||
FieldManager: obj.FieldManager,
|
||||
DryRun: []string{metav1.DryRunAll},
|
||||
}
|
||||
return resource.NewHelper(obj.Info.Client, obj.Info.Mapping).Patch(
|
||||
obj.Info.Namespace,
|
||||
|
@ -441,6 +444,7 @@ func (o *DiffOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
|
|||
}
|
||||
|
||||
o.ServerSideApply = cmdutil.GetServerSideApplyFlag(cmd)
|
||||
o.FieldManager = cmdutil.GetFieldManagerFlag(cmd)
|
||||
o.ForceConflicts = cmdutil.GetForceConflictsFlag(cmd)
|
||||
if o.ForceConflicts && !o.ServerSideApply {
|
||||
return fmt.Errorf("--force-conflicts only works with --server-side")
|
||||
|
@ -529,6 +533,7 @@ func (o *DiffOptions) Run() error {
|
|||
OpenAPI: o.OpenAPISchema,
|
||||
Force: force,
|
||||
ServerSideApply: o.ServerSideApply,
|
||||
FieldManager: o.FieldManager,
|
||||
ForceConflicts: o.ForceConflicts,
|
||||
IOStreams: o.Diff.IOStreams,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue