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

charts/karmada: automatically clean up the static-resource Job after it completes #5442

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

iawia002
Copy link
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

After #5305, we can now delete the static-resource job directly after its completion.

The new ttlSecondsAfterFinished feature can handle this task elegantly. However, this feature only reached GA in version 1.23. Before this version, the feature requires manually enabling the feature gate, and we cannot assume that users' clusters have this feature gate enabled. Therefore, unlike the #5305 (comment), considering that Karmada needs to run on various versions of Kubernetes, we cannot directly remove the post-install Job. The current strategy is:

  1. For Kubernetes versions 1.23 or higher, use ttlSecondsAfterFinished for cleanup.
  2. For Kubernetes versions lower than 1.23, continue using the post-install Job for cleanup.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

none

/cc @chaosi-zju @RainbowMango

@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Aug 28, 2024
@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 28, 2024
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 31.15%. Comparing base (295dee8) to head (0be1757).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5442   +/-   ##
=======================================
  Coverage   31.14%   31.15%           
=======================================
  Files         640      640           
  Lines       44414    44414           
=======================================
+ Hits        13833    13835    +2     
+ Misses      29581    29579    -2     
  Partials     1000     1000           
Flag Coverage Δ
unittests 31.15% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chaosi-zju
Copy link
Member

Thank you very much for your effort, this is exactly what I want to do, as I mentioned in #5305 (comment)

What surprised me was that you considered the KubeVersion, and you considered it more comprehensively than I did. 👍

@chaosi-zju
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 28, 2024
Comment on lines +105 to +107
## Set a TTL for the static-resource Job, the Job will be automatically cleaned up after this time.
## This only works on Kubernetes version 1.23 or higher.
ttlSecondsAfterFinished: 10
Copy link
Member

Choose a reason for hiding this comment

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

What's the impact if we don't clean the job?

Copy link
Member Author

Choose a reason for hiding this comment

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

The finished Pod holds extra resources, e.g., IP. Since this Job is useless, we need to release those resources.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean the Pod IP, right? Yeah, I agree that we should try to clean up temporary resources after the installation.
I'm asking because I want to evaluate the benefit we can get from this. Thanks for the clarification.

@@ -11,6 +11,9 @@ metadata:
spec:
parallelism: 1
completions: 1
{{- if semverCompare ">=1.23.0-0" .Capabilities.KubeVersion.GitVersion }}
Copy link
Member

Choose a reason for hiding this comment

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

Where does the .Capabilities.KubeVersion.GitVersion come from?

Is this version always comparable? I mean I can't assume all Kubernetes version format is x.x.y-0xxx.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where does the .Capabilities.KubeVersion.GitVersion come from?

It's helm's built-in objects.

Is this version always comparable? I mean I can't assume all Kubernetes version format is x.x.y-0xxx.

Yes, don't worry about the Kubernetes version format, it is semantic versioning. So the -0 suffix here is used to find pre-release versions, e.g., 1.24-beta.1 will still be considered greater than 1.23, see https://masterminds.github.io/sprig/semver.html for more information.

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve
Thanks.

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 29, 2024
@karmada-bot karmada-bot merged commit c9e0ad7 into karmada-io:master Aug 29, 2024
13 checks passed
@iawia002 iawia002 deleted the job-clean branch August 29, 2024 02:39
@@ -1,3 +1,4 @@
{{- if semverCompare "<1.23.0-0" .Capabilities.KubeVersion.GitVersion }}
Copy link
Contributor

Choose a reason for hiding this comment

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

any particular reason why this was added here?

Copy link
Contributor

Choose a reason for hiding this comment

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

❯ kubectl version
Credentials expired, trying refresh token .. success
Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.6

This Job is no longer rendering for me

Copy link
Member Author

@iawia002 iawia002 Aug 30, 2024

Choose a reason for hiding this comment

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

We don't need this Job for K8s version higher than 1.23, the static-resource Job will be cleaned automatically by ttlSecondsAfterFinished. Please read the description of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

This Job is no longer rendering for me

Do you mean it can't be installed on your side?

Copy link
Contributor

@a7i a7i Aug 30, 2024

Choose a reason for hiding this comment

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

It is no longer rendered (via helm template).

The explanation makes sense. I didn't realize post-install was split into static-resources and post-install, essentially making the latter useless if using ttlSecondsAfterFinished.

Copy link
Member

Choose a reason for hiding this comment

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

Is there anything we need to do regarding this?

By the way, I pined you on the slack @a7i about the chart ownership thing :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing ❤️

@RainbowMango RainbowMango added this to the v1.11 milestone Aug 31, 2024
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants