-
Notifications
You must be signed in to change notification settings - Fork 246
feat(reset): add cleanup volumes and cleanup-load-balancers flag #3507
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
base: main
Are you sure you want to change the base?
Conversation
c7a1d0b
to
906bca7
Compare
/assign @xmudrii |
906bca7
to
576aa4a
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Signed-off-by: rajaSahil <[email protected]>
576aa4a
to
7c32a02
Compare
There was a problem hiding this 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.
pkg/clientutil/service.go
Outdated
@@ -0,0 +1,71 @@ | |||
/* | |||
Copyright 2020 The KubeOne Authors. |
There was a problem hiding this comment.
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. :)
pkg/clientutil/service.go
Outdated
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.") |
There was a problem hiding this comment.
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 offailed to list services
return fail.KubeClient(err, "failed to list Service.") | |
return fail.KubeClient(err, "listing services") |
pkg/clientutil/service.go
Outdated
} | ||
// 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) |
There was a problem hiding this comment.
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.:
logger.Infof("Deleting SVC : %s/%s\n", service.Namespace, service.Name) | |
logger.Debugf("Deleting LoadBalancer Service \"%s/%s\"", service.Namespace, service.Name) |
pkg/clientutil/service.go
Outdated
} | ||
|
||
func WaitCleanupLbs(ctx context.Context, logger logrus.FieldLogger, c client.Client) error { | ||
logger.Infoln("Waiting for all load balancer services to get deleted...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.Infoln("Waiting for all load balancer services to get deleted...") | |
logger.Infoln("Waiting for all LoadBalancer Services to get deleted...") |
pkg/state/context.go
Outdated
CleanupVolumes bool | ||
CleanupLoadBalancers bool |
There was a problem hiding this comment.
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.
pkg/tasks/reset.go
Outdated
if !s.CleanupLoadBalancers { | ||
return nil | ||
} |
There was a problem hiding this comment.
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
Line 603 in 8b8d794
Predicate: func(s *state.State) bool { return s.Cluster.CloudProvider.Openstack != nil }, |
pkg/tasks/reset.go
Outdated
return nil | ||
} | ||
var lastErr error | ||
s.Logger.Infoln("Deleting load balancer services...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.Logger.Infoln("Deleting load balancer services...") | |
s.Logger.Infoln("Deleting LoadBalancer Services...") |
pkg/tasks/reset.go
Outdated
} | ||
var lastErr error | ||
s.Logger.Infoln("Deleting load balancer services...") | ||
_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed exponential backoff from both functions.
pkg/tasks/reset.go
Outdated
return true, nil | ||
}) | ||
|
||
_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) { |
There was a problem hiding this comment.
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.
Signed-off-by: rajaSahil <[email protected]>
b98e59c
to
e0aa078
Compare
@@ -26,7 +26,7 @@ require ( | |||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 | |||
github.com/sirupsen/logrus v1.9.3 | |||
github.com/spf13/cobra v1.8.1 | |||
github.com/spf13/pflag v1.0.5 | |||
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really necessary to use unreleased version?
if service.DeletionTimestamp != nil { | ||
continue | ||
} | ||
logger.Infof("Cleaning up LoadBalancer Services...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line will appear for each Service in the cluster (LB or not), I believe this is not what you wanted to do.
creatorGetters := []reconciling.NamedValidatingWebhookConfigurationReconcilerFactory{ | ||
creationPreventingWebhook("", VolumeResources), | ||
} | ||
if err := reconciling.ReconcileValidatingWebhookConfigurations(ctx, creatorGetters, "", c); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure we can EASILY create a webhook without reconciling framework, please replace this with a simple object creation.
// We disable the PV & PVC creation so nothing creates new PV's while we delete them | ||
logger.Infoln("Creating ValidatingWebhookConfiguration to disable future PV & PVC creation...") | ||
if err := disablePVCreation(ctx, c); err != nil { | ||
return fail.KubeClient(err, "failed to disable future PV & PVC creation.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all (here and forward) fail.Xyz()
calls please avoid using "failed to do something", use "doing something".
|
||
for _, pod := range pvUsingPods { | ||
if pod.DeletionTimestamp == nil { | ||
if err := DeleteIfExists(ctx, c, pod); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use pod eviction. For more info see:
kubeone/pkg/nodeutils/drain.go
Line 78 in fb64982
func (dr *drainer) drainHelper(ctx context.Context) (*drain.Helper, error) { - https://pkg.go.dev/k8s.io/kubectl/pkg/drain#Helper.EvictPod
|
||
if (pvcList != nil && pvList != nil) && len(pvcList.Items) == 0 && len(pvList.Items) == 0 { | ||
return true, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we don't do anything useful with pvcList
and pvList
besides checking their length, I'm pretty sure we can return this info directly
lastErr = clientutil.WaitCleanupLbs(s.Context, s.Logger, s.DynamicClient) | ||
if lastErr != nil { | ||
s.Logger.Warn("Waiting for all load balancer services to be deleted...") | ||
|
||
return lastErr | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastErr = clientutil.WaitCleanupLbs(s.Context, s.Logger, s.DynamicClient) | |
if lastErr != nil { | |
s.Logger.Warn("Waiting for all load balancer services to be deleted...") | |
return lastErr | |
} | |
lastErr = clientutil.WaitCleanupLbs(s.Context, s.Logger, s.DynamicClient) | |
if lastErr != nil { | |
s.Logger.Warn("Waiting for all load balancer services to be deleted...") | |
} |
lastErr will be returned anyway
lastErr = clientutil.WaitCleanUpVolumes(s.Context, s.Logger, s.DynamicClient) | ||
if lastErr != nil { | ||
s.Logger.Warn("Waiting for all dynamically provisioned and unretained volumes to be deleted...") | ||
|
||
return lastErr | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastErr = clientutil.WaitCleanUpVolumes(s.Context, s.Logger, s.DynamicClient) | |
if lastErr != nil { | |
s.Logger.Warn("Waiting for all dynamically provisioned and unretained volumes to be deleted...") | |
return lastErr | |
} | |
lastErr = clientutil.WaitCleanUpVolumes(s.Context, s.Logger, s.DynamicClient) | |
if lastErr != nil { | |
s.Logger.Warn("Waiting for all dynamically provisioned and unretained volumes to be deleted...") | |
} |
What this PR does / why we need it:
dynamically provisioned and unretained volumes
andload 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:
Documentation: