find and replace

This commit is contained in:
Daniel Smith 2022-03-17 18:50:38 +00:00
parent a3d0dbbf60
commit e405ae9ec8
12 changed files with 41 additions and 41 deletions

View File

@ -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(),
},
}

View File

@ -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"))...)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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())
}

View File

@ -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)

View File

@ -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()))

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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 {