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 RemoteKubernetesCluster finalizer #2272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zimnx
Copy link
Collaborator

@zimnx zimnx commented Dec 16, 2024

Description of your changes:

Controller reconciles finalizer on RemoteKubernetesCluster, preventing from premature deletion. It waits until all ScyllaDBClusters using particular RemoteKubernetesCluster are deleted.

Which issue is resolved by this Pull Request:
Resolves #2277

@zimnx zimnx added kind/feature Categorizes issue or PR as related to a new feature. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Dec 16, 2024
Copy link
Contributor

@zimnx: GitHub didn't allow me to request PR reviews from the following users: zimnx.

Note that only scylladb members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Description of your changes:

Controller reconciles finalizer on RemoteKubernetesCluster, preventing from premature deletion. It waits until all ScyllaDBClusters using particular RemoteKubernetesCluster are deleted.

Which issue is resolved by this Pull Request:
Resolves #

/cc

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@scylla-operator-bot scylla-operator-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 16, 2024
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zimnx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@scylla-operator-bot scylla-operator-bot bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 16, 2024
Controller reconciles finalizer on RemoteKubernetesCluster, preventing from premature deletion.
It waits until all ScyllaDBClusters using particular RemoteKubernetesCluster are deleted.
@zimnx zimnx force-pushed the remotekubernetescluster-finalizer branch from c422af5 to 846eef0 Compare December 17, 2024 13:12
@zimnx zimnx changed the title [WIP] Add RemoteKubernetesCluster protection controller Add RemoteKubernetesCluster protection controller Dec 17, 2024
@scylla-operator-bot scylla-operator-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 17, 2024
@zimnx
Copy link
Collaborator Author

zimnx commented Dec 17, 2024

Ready to review

/cc rzetelskik
/cc tnozicka

@zimnx zimnx changed the title Add RemoteKubernetesCluster protection controller Add RemoteKubernetesCluster finalizer Dec 17, 2024
var _ = g.Describe("RemoteKubernetesCluster finalizer", func() {
f := framework.NewFramework("remotekubernetescluster")

g.It("should block deletion when there are referencing ScyllaDBClusters", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
g.It("should block deletion when there are referencing ScyllaDBClusters", func() {
g.It("should block deletion when there are ScyllaDBClusters referencing the object", func() {

or ScyllaDBCluster referents?
nit

rkc, err := cluster.ScyllaAdminClient().ScyllaV1alpha1().RemoteKubernetesClusters().Create(ctx, originalRKC, metav1.CreateOptions{})
o.Expect(err).NotTo(o.HaveOccurred())

framework.By("Waiting for the RemoteKubernetesCluster %q to rollout (RV=%s)", rkc.Name, rkc.ResourceVersion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
framework.By("Waiting for the RemoteKubernetesCluster %q to rollout (RV=%s)", rkc.Name, rkc.ResourceVersion)
framework.By("Waiting for the RemoteKubernetesCluster %q to roll out (RV=%s)", rkc.Name, rkc.ResourceVersion)

applies globally

Comment on lines +66 to +79
framework.By("Deleting RemoteKubernetesCluster %q", rkc.Name)
err = cluster.ScyllaAdminClient().ScyllaV1alpha1().RemoteKubernetesClusters().Delete(ctx, rkcName, metav1.DeleteOptions{})
o.Expect(err).NotTo(o.HaveOccurred())

framework.By("Awaiting RemoteKubernetesCluster %q deletion", rkc.Name)
err = framework.WaitForObjectDeletion(ctx, f.DynamicAdminClient(), scyllav1alpha1.GroupVersion.WithResource("remotekubernetesclusters"), rkc.Namespace, rkc.Name, nil)
o.Expect(err).NotTo(o.HaveOccurred())

framework.By("Recreating RemoteKubernetesCluster %q", rkcName)
rkc = originalRKC.DeepCopy()
rkc, err = cluster.ScyllaAdminClient().ScyllaV1alpha1().RemoteKubernetesClusters().Create(ctx, rkc, metav1.CreateOptions{})
o.Expect(err).NotTo(o.HaveOccurred())

framework.By("Waiting for the RemoteKubernetesCluster %q to rollout (RV=%s)", rkc.Name, rkc.ResourceVersion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

cond := meta.FindStatusCondition(rkc.Status.Conditions, "RemoteKubernetesClusterFinalizerProgressing")
return cond != nil && cond.Reason == "RemoteKubernetesClusterFinalizerProgressing_IsBeingUsed", nil
}
framework.By("Awaiting is being used condition on RemoteKubernetesCluster %q", rkc.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
framework.By("Awaiting is being used condition on RemoteKubernetesCluster %q", rkc.Name)
framework.By("Awaiting 'IsBeingUsed' condition on RemoteKubernetesCluster %q", rkc.Name)

nit, difficult to read now

Comment on lines +112 to +113
cond := meta.FindStatusCondition(rkc.Status.Conditions, "RemoteKubernetesClusterFinalizerProgressing")
return cond != nil && cond.Reason == "RemoteKubernetesClusterFinalizerProgressing_IsBeingUsed", nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you check for generation and status as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, looking at sync_finalizer implementation, shouldn't the reason just say IsBeingUsed?

@@ -0,0 +1,82 @@
// Copyright (c) 2024 ScyllaDB.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't the file be named finalizer.go, as we already have controllerhelpers/annotation.go doing a very similar thing?

"k8s.io/klog/v2"
)

func (rkcc *Controller) syncFinalizer(ctx context.Context, rkc *scyllav1alpha1.RemoteKubernetesCluster) ([]metav1.Condition, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall your previous PRs in the enterprise repo having a separate protection controller in a dedicated file subtree - why the change?

)
}

func (rkcc *Controller) enqueueScyllaDBCluster(depth int, obj kubeinterfaces.ObjectInterface, op controllerhelpers.HandlerOperationType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name of the func is misleading, in the end you are enqueuing an RKC - should it say enqueueRemoteKubernetesClustersReferencedByScyllaDBCluster or something along these lines?

for _, dc := range sc.Spec.Datacenters {
rkc, err := rkcc.remoteKubernetesClusterLister.Get(dc.RemoteKubernetesClusterName)
if err != nil {
utilruntime.HandleError(fmt.Errorf("couldn't find RemoteKubernetesCluster with name %q", dc.RemoteKubernetesClusterName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
utilruntime.HandleError(fmt.Errorf("couldn't find RemoteKubernetesCluster with name %q", dc.RemoteKubernetesClusterName))
utilruntime.HandleError(fmt.Errorf("couldn't get RemoteKubernetesCluster %q: %w", dc.RemoteKubernetesClusterName, err))

rkc, err := rkcc.remoteKubernetesClusterLister.Get(dc.RemoteKubernetesClusterName)
if err != nil {
utilruntime.HandleError(fmt.Errorf("couldn't find RemoteKubernetesCluster with name %q", dc.RemoteKubernetesClusterName))
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add finalizer to RemoteKubernetesCluster protecting too early deletion #47
2 participants