Skip to content

Instantly share code, notes, and snippets.

@timebertt
Created January 5, 2022 17:03
Show Gist options
  • Save timebertt/3d82c1233b1ef1703ebd9a0748d276fd to your computer and use it in GitHub Desktop.
Save timebertt/3d82c1233b1ef1703ebd9a0748d276fd to your computer and use it in GitHub Desktop.
Updates and patches with controller-runtime clients
var (
ctx context.Context
c client.Client
shoot *gardencorev1beta1.Shoot
)
// update
shoot.Spec.Kubernetes.Version = "1.22"
err := c.Update(ctx, shoot)
// json merge patch
patch := client.MergeFrom(shoot.DeepCopy())
shoot.Spec.Kubernetes.Version = "1.22"
err = c.Patch(ctx, shoot, patch)
// strategic merge patch
patch = client.StrategicMergeFrom(shoot.DeepCopy())
shoot.Spec.Kubernetes.Version = "1.22"
err = c.Patch(ctx, shoot, patch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment