Hello experts:
We used below delete()
to delete annoation,
annotation := r.FdbCluster.ObjectMeta.Annotations
if _, ok := annotation[fdbv1.BackupTrigger]; ok {
//Remove post restore annotation
delete(annotation, fdbv1.BackupTrigger)
then need to update the value in API server, so used update()
, but it will cause other parts of spec changes which is not expected, we want to only update the annotation part, not other spec part.
From the update() method
// Update implements client.Client.
func (c *client) Update(ctx context.Context, obj Object, opts ...UpdateOption) error {
defer c.resetGroupVersionKind(obj, obj.GetObjectKind().GroupVersionKind())
switch obj.(type) {
case *unstructured.Unstructured:
return c.unstructuredClient.Update(ctx, obj, opts...)
case *metav1.PartialObjectMetadata:
return fmt.Errorf("cannot update using only metadata -- did you mean to patch?")
default:
return c.typedClient.Update(ctx, obj, opts...)
}
}
It sounds update()
method doesn’t support update annotation. so what API should I use? patch()
? any examples are highly appreciated. thank you.
ps: below is the k8s client version we used.
||k8s.io/client-go v0.21.3|
||sigs.k8s.io/controller-runtime v0.9.6|