From e405ae9ec8592bf028e351bab44de420908bac0d Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Thu, 17 Mar 2022 18:50:38 +0000 Subject: [PATCH] find and replace --- .../k8s.io/apimachinery/pkg/api/meta/meta.go | 2 +- .../pkg/api/validation/objectmeta.go | 12 +++++------ .../pkg/apis/meta/v1/helpers_test.go | 2 +- .../apimachinery/pkg/apis/meta/v1/meta.go | 8 ++++---- .../apis/meta/v1/unstructured/unstructured.go | 4 ++-- .../meta/v1/unstructured/unstructured_test.go | 4 ++-- ...pis_meta_v1_unstructed_unstructure_test.go | 6 +++--- .../fieldmanager/fieldmanager_test.go | 2 +- .../apiserver/pkg/registry/rest/create.go | 6 +++--- .../pkg/registry/rest/resttest/resttest.go | 20 +++++++++---------- .../apiserver/pkg/registry/rest/update.go | 6 +++--- .../pkg/storage/cacher/caching_object.go | 10 +++++----- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/api/meta/meta.go b/staging/src/k8s.io/apimachinery/pkg/api/meta/meta.go index 6a4116a040b..cf57fc4993a 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/meta/meta.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/meta/meta.go @@ -130,7 +130,7 @@ func AsPartialObjectMetadata(m metav1.Object) *metav1.PartialObjectMetadata { Annotations: m.GetAnnotations(), OwnerReferences: m.GetOwnerReferences(), Finalizers: m.GetFinalizers(), - ClusterName: m.GetClusterName(), + ZZZ_DeprecatedClusterName: m.GetZZZ_DeprecatedClusterName(), ManagedFields: m.GetManagedFields(), }, } diff --git a/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go b/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go index 66e8d677a4e..9a1fe073146 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go @@ -40,8 +40,8 @@ var BannedOwners = map[schema.GroupVersionKind]struct{}{ {Group: "", Version: "v1", Kind: "Event"}: {}, } -// ValidateClusterName can be used to check whether the given cluster name is valid. -var ValidateClusterName = NameIsDNS1035Label +// ValidateZZZ_DeprecatedClusterName can be used to check whether the given cluster name is valid. +var ValidateZZZ_DeprecatedClusterName = NameIsDNS1035Label // ValidateAnnotations validates that a set of annotations are correctly defined. func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList { @@ -184,9 +184,9 @@ func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, name allErrs = append(allErrs, field.Forbidden(fldPath.Child("namespace"), "not allowed on this type")) } } - if len(meta.GetClusterName()) != 0 { - for _, msg := range ValidateClusterName(meta.GetClusterName(), false) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("clusterName"), meta.GetClusterName(), msg)) + if len(meta.GetZZZ_DeprecatedClusterName()) != 0 { + for _, msg := range ValidateZZZ_DeprecatedClusterName(meta.GetZZZ_DeprecatedClusterName(), false) { + allErrs = append(allErrs, field.Invalid(fldPath.Child("clusterName"), meta.GetZZZ_DeprecatedClusterName(), msg)) } } @@ -261,7 +261,7 @@ func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *f allErrs = append(allErrs, ValidateImmutableField(newMeta.GetCreationTimestamp(), oldMeta.GetCreationTimestamp(), fldPath.Child("creationTimestamp"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetDeletionTimestamp(), oldMeta.GetDeletionTimestamp(), fldPath.Child("deletionTimestamp"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetDeletionGracePeriodSeconds(), oldMeta.GetDeletionGracePeriodSeconds(), fldPath.Child("deletionGracePeriodSeconds"))...) - allErrs = append(allErrs, ValidateImmutableField(newMeta.GetClusterName(), oldMeta.GetClusterName(), fldPath.Child("clusterName"))...) + allErrs = append(allErrs, ValidateImmutableField(newMeta.GetZZZ_DeprecatedClusterName(), oldMeta.GetZZZ_DeprecatedClusterName(), fldPath.Child("clusterName"))...) allErrs = append(allErrs, v1validation.ValidateLabels(newMeta.GetLabels(), fldPath.Child("labels"))...) allErrs = append(allErrs, ValidateAnnotations(newMeta.GetAnnotations(), fldPath.Child("annotations"))...) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go index ff22f6babcf..b12cc8a30ce 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go @@ -205,7 +205,7 @@ func TestResetObjectMetaForStatus(t *testing.T) { existingMeta.SetUID(types.UID("")) existingMeta.SetName("") existingMeta.SetNamespace("") - existingMeta.SetClusterName("") + existingMeta.SetZZZ_DeprecatedClusterName("") existingMeta.SetCreationTimestamp(Time{}) existingMeta.SetDeletionTimestamp(nil) existingMeta.SetDeletionGracePeriodSeconds(nil) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/meta.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/meta.go index 2002f91b0cd..c2737b032e8 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/meta.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/meta.go @@ -59,8 +59,8 @@ type Object interface { SetFinalizers(finalizers []string) GetOwnerReferences() []OwnerReference SetOwnerReferences([]OwnerReference) - GetClusterName() string - SetClusterName(clusterName string) + GetZZZ_DeprecatedClusterName() string + SetZZZ_DeprecatedClusterName(clusterName string) GetManagedFields() []ManagedFieldsEntry SetManagedFields(managedFields []ManagedFieldsEntry) } @@ -172,8 +172,8 @@ func (meta *ObjectMeta) GetOwnerReferences() []OwnerReference { return m func (meta *ObjectMeta) SetOwnerReferences(references []OwnerReference) { meta.OwnerReferences = references } -func (meta *ObjectMeta) GetClusterName() string { return meta.ClusterName } -func (meta *ObjectMeta) SetClusterName(clusterName string) { meta.ClusterName = clusterName } +func (meta *ObjectMeta) GetZZZ_DeprecatedClusterName() string { return meta.ZZZ_DeprecatedClusterName } +func (meta *ObjectMeta) SetZZZ_DeprecatedClusterName(clusterName string) { meta.ZZZ_DeprecatedClusterName = clusterName } func (meta *ObjectMeta) GetManagedFields() []ManagedFieldsEntry { return meta.ManagedFields } func (meta *ObjectMeta) SetManagedFields(managedFields []ManagedFieldsEntry) { meta.ManagedFields = managedFields diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured.go index d1903394d7f..f0fad90fd47 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured.go @@ -444,11 +444,11 @@ func (u *Unstructured) SetFinalizers(finalizers []string) { u.setNestedStringSlice(finalizers, "metadata", "finalizers") } -func (u *Unstructured) GetClusterName() string { +func (u *Unstructured) GetZZZ_DeprecatedClusterName() string { return getNestedString(u.Object, "metadata", "clusterName") } -func (u *Unstructured) SetClusterName(clusterName string) { +func (u *Unstructured) SetZZZ_DeprecatedClusterName(clusterName string) { if len(clusterName) == 0 { RemoveNestedField(u.Object, "metadata", "clusterName") return diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go index 7ee74a3eed0..81372162a9b 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go @@ -105,7 +105,7 @@ func TestUnstructuredMetadataOmitempty(t *testing.T) { u.SetAnnotations(nil) u.SetOwnerReferences(nil) u.SetFinalizers(nil) - u.SetClusterName("") + u.SetZZZ_DeprecatedClusterName("") u.SetManagedFields(nil) gotMetadata, _, err := unstructured.NestedFieldNoCopy(u.UnstructuredContent(), "metadata") @@ -147,6 +147,6 @@ func setObjectMetaUsingAccessors(u, uCopy *unstructured.Unstructured) { uCopy.SetAnnotations(u.GetAnnotations()) uCopy.SetOwnerReferences(u.GetOwnerReferences()) uCopy.SetFinalizers(u.GetFinalizers()) - uCopy.SetClusterName(u.GetClusterName()) + uCopy.SetZZZ_DeprecatedClusterName(u.GetZZZ_DeprecatedClusterName()) uCopy.SetManagedFields(u.GetManagedFields()) } diff --git a/staging/src/k8s.io/apimachinery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go b/staging/src/k8s.io/apimachinery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go index 0fb1be7e6dd..f73a45fe8fe 100644 --- a/staging/src/k8s.io/apimachinery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/test/apis_meta_v1_unstructed_unstructure_test.go @@ -245,8 +245,8 @@ func TestUnstructuredGetters(t *testing.T) { if got, want := unstruct.GetFinalizers(), []string{"finalizer.1", "finalizer.2"}; !reflect.DeepEqual(got, want) { t.Errorf("GetFinalizers()=%v, want %v", got, want) } - if got, want := unstruct.GetClusterName(), "cluster123"; got != want { - t.Errorf("GetClusterName()=%v, want %v", got, want) + if got, want := unstruct.GetZZZ_DeprecatedClusterName(), "cluster123"; got != want { + t.Errorf("GetZZZ_DeprecatedClusterName()=%v, want %v", got, want) } if got, want := unstruct.GetDeletionGracePeriodSeconds(), &ten; !reflect.DeepEqual(got, want) { t.Errorf("GetDeletionGracePeriodSeconds()=%v, want %v", got, want) @@ -338,7 +338,7 @@ func TestUnstructuredSetters(t *testing.T) { } unstruct.SetOwnerReferences(newOwnerReferences) unstruct.SetFinalizers([]string{"finalizer.1", "finalizer.2"}) - unstruct.SetClusterName("cluster123") + unstruct.SetZZZ_DeprecatedClusterName("cluster123") unstruct.SetDeletionGracePeriodSeconds(&ten) unstruct.SetGeneration(ten) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go index 137e08fe716..c24b859a306 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/fieldmanager_test.go @@ -267,7 +267,7 @@ func TestApplyStripsFields(t *testing.T) { newObj.SetName("b") newObj.SetNamespace("b") newObj.SetUID("b") - newObj.SetClusterName("b") + newObj.SetZZZ_DeprecatedClusterName("b") newObj.SetGeneration(0) newObj.SetResourceVersion("b") newObj.SetCreationTimestamp(metav1.NewTime(time.Now())) diff --git a/staging/src/k8s.io/apiserver/pkg/registry/rest/create.go b/staging/src/k8s.io/apiserver/pkg/registry/rest/create.go index da203464d68..32ca642cf5f 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/rest/create.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/rest/create.go @@ -123,9 +123,9 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx context.Context, obj runtime. objectMeta.SetManagedFields(nil) } - // ClusterName is ignored and should not be saved - if len(objectMeta.GetClusterName()) > 0 { - objectMeta.SetClusterName("") + // ZZZ_DeprecatedClusterName is ignored and should not be saved + if len(objectMeta.GetZZZ_DeprecatedClusterName()) > 0 { + objectMeta.SetZZZ_DeprecatedClusterName("") } if errs := strategy.Validate(ctx, obj); len(errs) > 0 { diff --git a/staging/src/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go b/staging/src/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go index 962a20de077..ae5b9da512b 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go @@ -168,8 +168,8 @@ func (t *Tester) TestCreate(valid runtime.Object, createFn CreateFunc, getFn Get t.testCreateInvokesValidation(opts, invalid...) t.testCreateValidatesNames(valid.DeepCopyObject(), dryRunOpts) t.testCreateValidatesNames(valid.DeepCopyObject(), opts) - t.testCreateIgnoreClusterName(valid.DeepCopyObject(), dryRunOpts) - t.testCreateIgnoreClusterName(valid.DeepCopyObject(), opts) + t.testCreateIgnoreZZZ_DeprecatedClusterName(valid.DeepCopyObject(), dryRunOpts) + t.testCreateIgnoreZZZ_DeprecatedClusterName(valid.DeepCopyObject(), opts) } // Test updating an object. @@ -190,7 +190,7 @@ func (t *Tester) TestUpdate(valid runtime.Object, createFn CreateFunc, getFn Get t.testUpdatePropagatesUpdatedObjectError(valid.DeepCopyObject(), createFn, getFn, dryRunOpts) t.testUpdatePropagatesUpdatedObjectError(valid.DeepCopyObject(), createFn, getFn, opts) t.testUpdateIgnoreGenerationUpdates(valid.DeepCopyObject(), createFn, getFn) - t.testUpdateIgnoreClusterName(valid.DeepCopyObject(), createFn, getFn) + t.testUpdateIgnoreZZZ_DeprecatedClusterName(valid.DeepCopyObject(), createFn, getFn) } // Test deleting an object. @@ -506,10 +506,10 @@ func (t *Tester) testCreateResetsUserData(valid runtime.Object, opts metav1.Crea } } -func (t *Tester) testCreateIgnoreClusterName(valid runtime.Object, opts metav1.CreateOptions) { +func (t *Tester) testCreateIgnoreZZZ_DeprecatedClusterName(valid runtime.Object, opts metav1.CreateOptions) { objectMeta := t.getObjectMetaOrFail(valid) objectMeta.SetName(t.namer(3)) - objectMeta.SetClusterName("clustername-to-ignore") + objectMeta.SetZZZ_DeprecatedClusterName("clustername-to-ignore") obj, err := t.storage.(rest.Creater).Create(t.TestContext(), valid.DeepCopyObject(), rest.ValidateAllObjectFunc, &opts) if err != nil { @@ -517,8 +517,8 @@ func (t *Tester) testCreateIgnoreClusterName(valid runtime.Object, opts metav1.C } defer t.delete(t.TestContext(), obj) createdObjectMeta := t.getObjectMetaOrFail(obj) - if len(createdObjectMeta.GetClusterName()) != 0 { - t.Errorf("Expected empty clusterName on created object, got '%v'", createdObjectMeta.GetClusterName()) + if len(createdObjectMeta.GetZZZ_DeprecatedClusterName()) != 0 { + t.Errorf("Expected empty clusterName on created object, got '%v'", createdObjectMeta.GetZZZ_DeprecatedClusterName()) } } @@ -790,7 +790,7 @@ func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, create } } -func (t *Tester) testUpdateIgnoreClusterName(obj runtime.Object, createFn CreateFunc, getFn GetFunc) { +func (t *Tester) testUpdateIgnoreZZZ_DeprecatedClusterName(obj runtime.Object, createFn CreateFunc, getFn GetFunc) { ctx := t.TestContext() foo := obj.DeepCopyObject() @@ -808,7 +808,7 @@ func (t *Tester) testUpdateIgnoreClusterName(obj runtime.Object, createFn Create older := storedFoo.DeepCopyObject() olderMeta := t.getObjectMetaOrFail(older) - olderMeta.SetClusterName("clustername-to-ignore") + olderMeta.SetZZZ_DeprecatedClusterName("clustername-to-ignore") _, _, err = t.storage.(rest.Updater).Update(t.TestContext(), olderMeta.GetName(), rest.DefaultUpdatedObjectInfo(older), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{}) if err != nil { @@ -819,7 +819,7 @@ func (t *Tester) testUpdateIgnoreClusterName(obj runtime.Object, createFn Create if err != nil { t.Errorf("unexpected error: %v", err) } - if clusterName := t.getObjectMetaOrFail(updatedFoo).GetClusterName(); len(clusterName) != 0 { + if clusterName := t.getObjectMetaOrFail(updatedFoo).GetZZZ_DeprecatedClusterName(); len(clusterName) != 0 { t.Errorf("Unexpected clusterName update: expected empty, got %v", clusterName) } diff --git a/staging/src/k8s.io/apiserver/pkg/registry/rest/update.go b/staging/src/k8s.io/apiserver/pkg/registry/rest/update.go index 3a98c4c4de2..7c8ec3e2e72 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/rest/update.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/rest/update.go @@ -136,9 +136,9 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx context.Context, obj, old run strategy.PrepareForUpdate(ctx, obj, old) - // ClusterName is ignored and should not be saved - if len(objectMeta.GetClusterName()) > 0 { - objectMeta.SetClusterName("") + // ZZZ_DeprecatedClusterName is ignored and should not be saved + if len(objectMeta.GetZZZ_DeprecatedClusterName()) > 0 { + objectMeta.SetZZZ_DeprecatedClusterName("") } // Use the existing UID if none is provided if len(objectMeta.GetUID()) == 0 { diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go index 9ee5c951f11..2e3ea6a7da6 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/caching_object.go @@ -395,15 +395,15 @@ func (o *cachingObject) SetOwnerReferences(references []metav1.OwnerReference) { func() { o.object.SetOwnerReferences(references) }, ) } -func (o *cachingObject) GetClusterName() string { +func (o *cachingObject) GetZZZ_DeprecatedClusterName() string { o.lock.RLock() defer o.lock.RUnlock() - return o.object.GetClusterName() + return o.object.GetZZZ_DeprecatedClusterName() } -func (o *cachingObject) SetClusterName(clusterName string) { +func (o *cachingObject) SetZZZ_DeprecatedClusterName(clusterName string) { o.conditionalSet( - func() bool { return o.object.GetClusterName() == clusterName }, - func() { o.object.SetClusterName(clusterName) }, + func() bool { return o.object.GetZZZ_DeprecatedClusterName() == clusterName }, + func() { o.object.SetZZZ_DeprecatedClusterName(clusterName) }, ) } func (o *cachingObject) GetManagedFields() []metav1.ManagedFieldsEntry {