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

feat(reset): add cleanup volumes and cleanup-load-balancers flag #3507

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

Conversation

rajaSahil
Copy link
Contributor

@rajaSahil rajaSahil commented Dec 19, 2024

What this PR does / why we need it:

  • add cleanup volumes and cleanup-load-balancers flag to delete dynamically provisioned and unretained volumes and load balancers services from the cluster before resetting.

Which issue(s) this PR fixes:

Fixes #3394

What type of PR is this?

/kind feature

Does this PR introduce a user-facing change? Then add your Release Note here:

Add cleanup-volumes and cleanup-load-balancers flag to delete `dynamically provisioned and unretained volumes` and `load balancer services` before resetting the cluster.

Documentation:

NONE

@kubermatic-bot kubermatic-bot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. docs/none Denotes a PR that doesn't need documentation (changes). dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 19, 2024
@rajaSahil rajaSahil force-pushed the destroy-volumes-svc branch 5 times, most recently from c7a1d0b to 906bca7 Compare December 20, 2024 09:39
@rajaSahil
Copy link
Contributor Author

/assign @xmudrii
Please review.

@kubermatic-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from xmudrii. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Member

@xmudrii xmudrii left a comment

Choose a reason for hiding this comment

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

I did some initial review and testing, I'll have some more comments, but let's start with this and then we can follow up on some other stuff.

@@ -0,0 +1,71 @@
/*
Copyright 2020 The KubeOne Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Please replace 2020 with 2024 2025 in all files that you added in this PR. :)


package clientutil

import (
Copy link
Member

Choose a reason for hiding this comment

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

Take a look here how we order imports:

import (
"context"
"github.com/sirupsen/logrus"
"k8c.io/kubeone/pkg/fail"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/kubectl/pkg/drain"
)

It should be stdlib -> external dependencies -> k8c.io -> k8s.io

Copy link
Member

Choose a reason for hiding this comment

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

This will fix all the imports

go run go.xrstf.de/gimps@latest .

func CleanupLBs(ctx context.Context, logger logrus.FieldLogger, c client.Client) error {
serviceList := &corev1.ServiceList{}
if err := c.List(ctx, serviceList); err != nil {
return fail.KubeClient(err, "failed to list Service.")
Copy link
Member

Choose a reason for hiding this comment

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

A couple of things:

  • we don't use uppercase letters and capitalization in error messages
  • we use gerund form of operation that we do for error messages, e.g. listing services instead of failed to list services
Suggested change
return fail.KubeClient(err, "failed to list Service.")
return fail.KubeClient(err, "listing services")

}
// Only LoadBalancer services incur charges on cloud providers
if service.Spec.Type == corev1.ServiceTypeLoadBalancer {
logger.Infof("Deleting SVC : %s/%s\n", service.Namespace, service.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Let's do this instead (because this might spam logs quite a lot):

  • Have a message before getting into the loop such as Cleaning up LoadBalancer Services...
  • Have this as a debug level message, e.g.:
Suggested change
logger.Infof("Deleting SVC : %s/%s\n", service.Namespace, service.Name)
logger.Debugf("Deleting LoadBalancer Service \"%s/%s\"", service.Namespace, service.Name)

}

func WaitCleanupLbs(ctx context.Context, logger logrus.FieldLogger, c client.Client) error {
logger.Infoln("Waiting for all load balancer services to get deleted...")
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
logger.Infoln("Waiting for all load balancer services to get deleted...")
logger.Infoln("Waiting for all LoadBalancer Services to get deleted...")

Comment on lines +110 to +111
CleanupVolumes bool
CleanupLoadBalancers bool
Copy link
Member

Choose a reason for hiding this comment

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

If you rename flags, make sure to remove this as well.

Comment on lines +36 to +38
if !s.CleanupLoadBalancers {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

We should make this task conditional instead, see an example here

Predicate: func(s *state.State) bool { return s.Cluster.CloudProvider.Openstack != nil },

return nil
}
var lastErr error
s.Logger.Infoln("Deleting load balancer services...")
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
s.Logger.Infoln("Deleting load balancer services...")
s.Logger.Infoln("Deleting LoadBalancer Services...")

}
var lastErr error
s.Logger.Infoln("Deleting load balancer services...")
_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need exponential backoff here I think, each task already has 3 times backoff.

return true, nil
})

_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, this shouldn't be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. docs/none Denotes a PR that doesn't need documentation (changes). kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

kubeone reset: add delete k8s generated cloud resources like Load Balancers and PVs
4 participants