MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / annotateCluster

Function annotateCluster

internal/cmd/plugin/hibernate/cmd.go:82–111  ·  view source on GitHub ↗
(
	ctx context.Context,
	cli client.Client,
	clusterKey client.ObjectKey,
	value utils.HibernationAnnotationValue,
)

Source from the content-addressed store, hash-verified

80}
81
82func annotateCluster(
83 ctx context.Context,
84 cli client.Client,
85 clusterKey client.ObjectKey,
86 value utils.HibernationAnnotationValue,
87) error {
88 var cluster apiv1.Cluster
89
90 if err := cli.Get(ctx, clusterKey, &cluster); err != nil {
91 return fmt.Errorf("failed to get cluster %s: %w", clusterKey.Name, err)
92 }
93
94 if cluster.Annotations == nil {
95 cluster.SetAnnotations(make(map[string]string))
96 }
97
98 origCluster := cluster.DeepCopy()
99
100 cluster.Annotations[utils.HibernationAnnotationName] = string(value)
101
102 if cluster.Annotations[utils.HibernationAnnotationName] == origCluster.Annotations[utils.HibernationAnnotationName] {
103 return fmt.Errorf("cluster %s is already in the requested state", clusterKey.Name)
104 }
105
106 if err := cli.Patch(ctx, &cluster, client.MergeFrom(origCluster)); err != nil {
107 return fmt.Errorf("failed to patch cluster %s: %w", clusterKey.Name, err)
108 }
109
110 return nil
111}

Callers 2

cmd.goFile · 0.85
cmd_test.goFile · 0.85

Calls 3

DeepCopyMethod · 0.95
GetMethod · 0.45
PatchMethod · 0.45

Tested by

no test coverage detected