( ctx context.Context, cli client.Client, clusterKey client.ObjectKey, value utils.HibernationAnnotationValue, )
| 80 | } |
| 81 | |
| 82 | func 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 | } |
no test coverage detected