Skip to content

Commit 4ac5f3d

Browse files
committed
Add move annotation on objects for cluster move operation
Signed-off-by: Pulak Kanti Bhowmick <[email protected]>
1 parent 6e151b5 commit 4ac5f3d

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

cmd/clusterctl/api/v1alpha3/annotations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ const (
2525
// Note: Only CRDs that are referenced by core Cluster API CRDs have to comply with the naming scheme.
2626
// See the following issue for more information: https://github.com/kubernetes-sigs/cluster-api/issues/5686#issuecomment-1260897278
2727
SkipCRDNamePreflightCheckAnnotation = "clusterctl.cluster.x-k8s.io/skip-crd-name-preflight-check"
28+
29+
// DeleteForMoveAnnotation will be set to objects that are going to be deleted from the
30+
// source cluster after being moved to the target cluster during the clusterctl move operation.
31+
//
32+
// It will help any validation webhook to take decision based on it.
33+
DeleteForMoveAnnotation = "clusterctl.cluster.x-k8s.io/delete-for-move"
2834
)

cmd/clusterctl/client/cluster/mover.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/client"
3636

3737
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
38+
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3839
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
3940
"sigs.k8s.io/cluster-api/util/conditions"
4041
"sigs.k8s.io/cluster-api/util/patch"
@@ -1064,7 +1065,8 @@ func (o *objectMover) deleteGroup(group moveGroup) error {
10641065
}
10651066

10661067
var (
1067-
removeFinalizersPatch = client.RawPatch(types.MergePatchType, []byte("{\"metadata\":{\"finalizers\":[]}}"))
1068+
removeFinalizersPatch = client.RawPatch(types.MergePatchType, []byte("{\"metadata\":{\"finalizers\":[]}}"))
1069+
addDeleteForMoveAnnotationPatch = client.RawPatch(types.JSONPatchType, []byte(fmt.Sprintf("[{\"op\": \"add\", \"path\":\"/metadata/annotations\", \"value\":{%q:\"\"}}]", clusterctlv1.DeleteForMoveAnnotation)))
10681070
)
10691071

10701072
// deleteSourceObject deletes the Kubernetes object corresponding to the node from the source management cluster, taking care of removing all the finalizers so
@@ -1106,6 +1108,11 @@ func (o *objectMover) deleteSourceObject(nodeToDelete *node) error {
11061108
sourceObj.GroupVersionKind(), sourceObj.GetNamespace(), sourceObj.GetName())
11071109
}
11081110

1111+
if err := cFrom.Patch(ctx, sourceObj, addDeleteForMoveAnnotationPatch); err != nil {
1112+
return errors.Wrapf(err, "error adding delete-for-move annotation from %q %s/%s",
1113+
sourceObj.GroupVersionKind(), sourceObj.GetNamespace(), sourceObj.GetName())
1114+
}
1115+
11091116
if len(sourceObj.GetFinalizers()) > 0 {
11101117
if err := cFrom.Patch(ctx, sourceObj, removeFinalizersPatch); err != nil {
11111118
return errors.Wrapf(err, "error removing finalizers from %q %s/%s",

docs/book/src/developer/providers/migrations/v1.4-to-v1.5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ maintainers of providers and consumers of our Go API.
2929

3030
### Other
3131

32-
-
32+
- clusterctl move is adding the new annotation `clusterctl.cluster.x-k8s.io/delete-for-move` before object deletion.
3333

3434
### Suggested changes for providers
3535

0 commit comments

Comments
 (0)