Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add move annotation on objects for cluster move operation #8322

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/clusterctl/api/v1alpha3/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ const (
// Note: Only CRDs that are referenced by core Cluster API CRDs have to comply with the naming scheme.
// See the following issue for more information: https://github.com/kubernetes-sigs/cluster-api/issues/5686#issuecomment-1260897278
SkipCRDNamePreflightCheckAnnotation = "clusterctl.cluster.x-k8s.io/skip-crd-name-preflight-check"

// DeleteForMoveAnnotation will be set to objects that are going to be deleted from the
// source cluster after being moved to the target cluster during the clusterctl move operation.
//
// It will help any validation webhook to take decision based on it.
DeleteForMoveAnnotation = "clusterctl.cluster.x-k8s.io/delete-for-move"
pkbhowmick marked this conversation as resolved.
Show resolved Hide resolved
)
9 changes: 8 additions & 1 deletion cmd/clusterctl/client/cluster/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -1064,7 +1065,8 @@ func (o *objectMover) deleteGroup(group moveGroup) error {
}

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

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

if err := cFrom.Patch(ctx, sourceObj, addDeleteForMoveAnnotationPatch); err != nil {
return errors.Wrapf(err, "error adding delete-for-move annotation from %q %s/%s",
sourceObj.GroupVersionKind(), sourceObj.GetNamespace(), sourceObj.GetName())
}

if len(sourceObj.GetFinalizers()) > 0 {
if err := cFrom.Patch(ctx, sourceObj, removeFinalizersPatch); err != nil {
return errors.Wrapf(err, "error removing finalizers from %q %s/%s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ maintainers of providers and consumers of our Go API.

### Other

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

### Suggested changes for providers

Expand Down