Skip to content

Commit 0b4275b

Browse files
authored
Merge pull request kubernetes#74760 from apelisse/add-mangerfield-flag
Add "fieldManager" to flag to PATCH/CREATE/UPDATE
2 parents b150560 + 92d8b19 commit 0b4275b

File tree

24 files changed

+3123
-207
lines changed

24 files changed

+3123
-207
lines changed

api/openapi-spec/swagger.json

Lines changed: 2436 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kubectl/cmd/apply/apply.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type ApplyOptions struct {
6868

6969
ServerSideApply bool
7070
ForceConflicts bool
71+
FieldManager string
7172
Selector string
7273
DryRun bool
7374
ServerDryRun bool
@@ -196,14 +197,15 @@ func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions
196197
func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
197198
o.ServerSideApply = cmdutil.GetServerSideApplyFlag(cmd)
198199
o.ForceConflicts = cmdutil.GetForceConflictsFlag(cmd)
200+
o.FieldManager = cmdutil.GetFieldManagerFlag(cmd)
199201
o.DryRun = cmdutil.GetDryRunFlag(cmd)
200202

201203
if o.ForceConflicts && !o.ServerSideApply {
202-
return fmt.Errorf("--force-conflicts only works with --server-side")
204+
return fmt.Errorf("--experimental-force-conflicts only works with --experimental-server-side")
203205
}
204206

205207
if o.DryRun && o.ServerSideApply {
206-
return fmt.Errorf("--dry-run doesn't work with --server-side")
208+
return fmt.Errorf("--dry-run doesn't work with --experimental-server-side (did you mean --server-dry-run instead?)")
207209
}
208210

209211
if o.DryRun && o.ServerDryRun {
@@ -393,7 +395,8 @@ func (o *ApplyOptions) Run() error {
393395
return cmdutil.AddSourceToErr("serverside-apply", info.Source, err)
394396
}
395397
options := metav1.PatchOptions{
396-
Force: &o.ForceConflicts,
398+
Force: &o.ForceConflicts,
399+
FieldManager: o.FieldManager,
397400
}
398401
if o.ServerDryRun {
399402
options.DryRun = []string{metav1.DryRunAll}

pkg/kubectl/cmd/diff/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func (o *DiffOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
402402
o.ServerSideApply = cmdutil.GetServerSideApplyFlag(cmd)
403403
o.ForceConflicts = cmdutil.GetForceConflictsFlag(cmd)
404404
if o.ForceConflicts && !o.ServerSideApply {
405-
return fmt.Errorf("--force-conflicts only works with --server-side")
405+
return fmt.Errorf("--experimental-force-conflicts only works with --experimental-server-side")
406406
}
407407

408408
if !o.ServerSideApply {

pkg/kubectl/cmd/util/helpers.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ func AddDryRunFlag(cmd *cobra.Command) {
406406
}
407407

408408
func AddServerSideApplyFlags(cmd *cobra.Command) {
409-
cmd.Flags().Bool("server-side", false, "If true, apply runs in the server instead of the client. This is an alpha feature and flag.")
410-
cmd.Flags().Bool("force-conflicts", false, "If true, server-side apply will force the changes against conflicts. This is an alpha feature and flag.")
409+
cmd.Flags().Bool("experimental-server-side", false, "If true, apply runs in the server instead of the client. This is an alpha feature and flag.")
410+
cmd.Flags().Bool("experimental-force-conflicts", false, "If true, server-side apply will force the changes against conflicts. This is an alpha feature and flag.")
411+
cmd.Flags().String("experimental-field-manager", "kubectl", "Name of the manager used to track field ownership. This is an alpha feature and flag.")
411412
}
412413

413414
func AddIncludeUninitializedFlag(cmd *cobra.Command) {
@@ -484,11 +485,15 @@ func DumpReaderToFile(reader io.Reader, filename string) error {
484485
}
485486

486487
func GetServerSideApplyFlag(cmd *cobra.Command) bool {
487-
return GetFlagBool(cmd, "server-side")
488+
return GetFlagBool(cmd, "experimental-server-side")
488489
}
489490

490491
func GetForceConflictsFlag(cmd *cobra.Command) bool {
491-
return GetFlagBool(cmd, "force-conflicts")
492+
return GetFlagBool(cmd, "experimental-force-conflicts")
493+
}
494+
495+
func GetFieldManagerFlag(cmd *cobra.Command) string {
496+
return GetFlagString(cmd, "experimental-field-manager")
492497
}
493498

494499
func GetDryRunFlag(cmd *cobra.Command) bool {

staging/src/k8s.io/apiextensions-apiserver/test/integration/apply_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ values:
7171
result, err := rest.Patch(types.ApplyPatchType).
7272
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
7373
Name("mytest").
74+
Param("fieldManager", "apply_test").
7475
Body(yamlBody).
7576
DoRaw()
7677
if err != nil {
@@ -90,6 +91,7 @@ values:
9091
result, err = rest.Patch(types.ApplyPatchType).
9192
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
9293
Name("mytest").
94+
Param("fieldManager", "apply_test").
9395
Body(yamlBody).
9496
DoRaw()
9597
if err == nil {
@@ -108,6 +110,7 @@ values:
108110
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
109111
Name("mytest").
110112
Param("force", "true").
113+
Param("fieldManager", "apply_test").
111114
Body(yamlBody).
112115
DoRaw()
113116
if err != nil {

staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, name
176176
allErrs = append(allErrs, field.Invalid(fldPath.Child("clusterName"), meta.GetClusterName(), msg))
177177
}
178178
}
179+
for _, entry := range meta.GetManagedFields() {
180+
allErrs = append(allErrs, v1validation.ValidateFieldManager(entry.Manager, fldPath.Child("fieldManager"))...)
181+
}
179182
allErrs = append(allErrs, ValidateNonnegativeField(meta.GetGeneration(), fldPath.Child("generation"))...)
180183
allErrs = append(allErrs, v1validation.ValidateLabels(meta.GetLabels(), fldPath.Child("labels"))...)
181184
allErrs = append(allErrs, ValidateAnnotations(meta.GetAnnotations(), fldPath.Child("annotations"))...)
@@ -239,6 +242,9 @@ func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *f
239242
allErrs = append(allErrs, field.Invalid(fldPath.Child("generation"), newMeta.GetGeneration(), "must not be decremented"))
240243
}
241244

245+
for _, entry := range newMeta.GetManagedFields() {
246+
allErrs = append(allErrs, v1validation.ValidateFieldManager(entry.Manager, fldPath.Child("fieldManager"))...)
247+
}
242248
allErrs = append(allErrs, ValidateImmutableField(newMeta.GetName(), oldMeta.GetName(), fldPath.Child("name"))...)
243249
allErrs = append(allErrs, ValidateImmutableField(newMeta.GetNamespace(), oldMeta.GetNamespace(), fldPath.Child("namespace"))...)
244250
allErrs = append(allErrs, ValidateImmutableField(newMeta.GetUID(), oldMeta.GetUID(), fldPath.Child("uid"))...)

0 commit comments

Comments
 (0)