Skip to content

Commit

Permalink
client.*MergeFrom* now take client.Object instead of runtime.Object
Browse files Browse the repository at this point in the history
  • Loading branch information
timebertt committed Jun 16, 2021
1 parent fce35ae commit eb21aa4
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion extensions/pkg/controller/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (o *operationAnnotationWrapper) Reconcile(ctx context.Context, request reco
}

if annotations[v1beta1constants.GardenerOperation] == v1beta1constants.GardenerOperationReconcile {
withOpAnnotation := obj.DeepCopyObject()
withOpAnnotation := obj.DeepCopyObject().(client.Object)
delete(annotations, v1beta1constants.GardenerOperation)
obj.SetAnnotations(annotations)
if err := o.client.Patch(ctx, obj, client.MergeFrom(withOpAnnotation)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion extensions/pkg/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func GetVerticalPodAutoscalerObject() *unstructured.Unstructured {

// RemoveAnnotation removes an annotation key passed as annotation
func RemoveAnnotation(ctx context.Context, c client.Client, obj client.Object, annotation string) error {
withAnnotation := obj.DeepCopyObject()
withAnnotation := obj.DeepCopyObject().(client.Object)

annotations := obj.GetAnnotations()
delete(annotations, annotation)
Expand Down
6 changes: 3 additions & 3 deletions extensions/pkg/terraformer/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ var _ = Describe("terraformer", func() {
return nil
}),
c.EXPECT().
Patch(gomock.Any(), gomock.AssignableToTypeOf(secret.DeepCopyObject()), gomock.AssignableToTypeOf(client.MergeFromWithOptions(secret.DeepCopyObject(), client.MergeFromWithOptimisticLock{}))),
Patch(gomock.Any(), gomock.AssignableToTypeOf(secret.DeepCopy()), gomock.AssignableToTypeOf(client.MergeFromWithOptions(secret.DeepCopy(), client.MergeFromWithOptimisticLock{}))),

c.EXPECT().
Get(gomock.Any(), kutil.Key(namespace, stateName), gomock.AssignableToTypeOf(&corev1.ConfigMap{})).
Expand All @@ -637,7 +637,7 @@ var _ = Describe("terraformer", func() {
return nil
}),
c.EXPECT().
Patch(gomock.Any(), gomock.AssignableToTypeOf(config.DeepCopyObject()), gomock.AssignableToTypeOf(client.MergeFromWithOptions(config.DeepCopyObject(), client.MergeFromWithOptimisticLock{}))),
Patch(gomock.Any(), gomock.AssignableToTypeOf(config.DeepCopy()), gomock.AssignableToTypeOf(client.MergeFromWithOptions(config.DeepCopy(), client.MergeFromWithOptimisticLock{}))),

c.EXPECT().
Get(gomock.Any(), kutil.Key(namespace, configName), gomock.AssignableToTypeOf(&corev1.ConfigMap{})).
Expand All @@ -646,7 +646,7 @@ var _ = Describe("terraformer", func() {
return nil
}),
c.EXPECT().
Patch(gomock.Any(), gomock.AssignableToTypeOf(state.DeepCopyObject()), gomock.AssignableToTypeOf(client.MergeFromWithOptions(state.DeepCopyObject(), client.MergeFromWithOptimisticLock{}))),
Patch(gomock.Any(), gomock.AssignableToTypeOf(state.DeepCopy()), gomock.AssignableToTypeOf(client.MergeFromWithOptions(state.DeepCopy(), client.MergeFromWithOptimisticLock{}))),
)

Expect(t.RemoveTerraformerFinalizerFromConfig(ctx)).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions pkg/extensions/customresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func RestoreExtensionObjectState(
purpose := extensionObj.GetExtensionSpec().GetExtensionPurpose()
list := gardencorev1alpha1helper.ExtensionResourceStateList(shootState.Spec.Extensions)
if extensionResourceState := list.Get(kind, &resourceName, purpose); extensionResourceState != nil {
patch := client.MergeFrom(extensionObj.DeepCopyObject())
patch := client.MergeFrom(extensionObj.DeepCopyObject().(client.Object))
extensionStatus := extensionObj.GetExtensionStatus()
extensionStatus.SetState(extensionResourceState.State)
extensionStatus.SetResources(extensionResourceState.Resources)
Expand Down Expand Up @@ -465,7 +465,7 @@ func WaitUntilExtensionObjectsMigrated(

// AnnotateObjectWithOperation annotates the object with the provided operation annotation value.
func AnnotateObjectWithOperation(ctx context.Context, w client.Writer, obj client.Object, operation string) error {
patch := client.MergeFrom(obj.DeepCopyObject())
patch := client.MergeFrom(obj.DeepCopyObject().(client.Object))
kutil.SetMetaDataAnnotation(obj, v1beta1constants.GardenerOperation, operation)
kutil.SetMetaDataAnnotation(obj, v1beta1constants.GardenerTimestamp, TimeNow().UTC().String())
return w.Patch(ctx, obj, patch)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/gardener/deletion_confirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func CheckIfDeletionIsConfirmed(obj client.Object) error {
// ConfirmDeletion adds Gardener's deletion confirmation and timestamp annotation to the given object and sends a PATCH
// request. It does not ignore `NotFound` errors while patching.
func ConfirmDeletion(ctx context.Context, w client.Writer, obj client.Object) error {
patch := client.MergeFrom(obj.DeepCopyObject())
patch := client.MergeFrom(obj.DeepCopyObject().(client.Object))
kutil.SetMetaDataAnnotation(obj, ConfirmationDeletion, "true")
kutil.SetMetaDataAnnotation(obj, v1beta1constants.GardenerTimestamp, TimeNow().UTC().String())
return w.Patch(ctx, obj, patch)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var defaultFinalizer = NewFinalizer()

// Finalize removes the finalizers (.meta.finalizers) of given resource.
func (f *finalizer) Finalize(ctx context.Context, c client.Client, obj client.Object) error {
withFinalizers := obj.DeepCopyObject()
withFinalizers := obj.DeepCopyObject().(client.Object)
obj.SetFinalizers(nil)
return c.Patch(ctx, obj, client.MergeFrom(withFinalizers))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func HasMetaDataAnnotation(meta metav1.Object, key, value string) bool {
// SetAnnotationAndUpdate sets the annotation on the given object and updates it.
func SetAnnotationAndUpdate(ctx context.Context, c client.Client, obj client.Object, key, value string) error {
if !HasMetaDataAnnotation(obj, key, value) {
objCopy := obj.DeepCopyObject()
objCopy := obj.DeepCopyObject().(client.Object)
SetMetaDataAnnotation(obj, key, value)
return c.Patch(ctx, obj, client.MergeFrom(objCopy))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/kubernetes/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func tryPatch(ctx context.Context, backoff wait.Backoff, c client.Client, obj cl
if err := c.Get(ctx, client.ObjectKeyFromObject(obj), obj); err != nil {
return false, err
}
beforeTransform := obj.DeepCopyObject()
beforeTransform := obj.DeepCopyObject().(client.Object)
if err := transform(); err != nil {
return false, err
}
Expand Down

0 comments on commit eb21aa4

Please sign in to comment.