Skip to content

Add a webhook for namespace deletion #719

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

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

qbarrand
Copy link
Contributor

This commit makes KMM set the kmm.node.k8s.io/contains-modules label on all namespaces that contain at least one Module.
It also adds a new webhook to the bundle and the corresponding handler in the manager.
The new webhook rejects namespace deletions if the kmm.node.k8s.io/contains-modules label is present on the namespace. This avoids entering situations where the namespace is being deleted and KMM cannot create unloading Pods to honor Module deletion.

Fixes #708

/cc @mresvanis @yevgeny-shnaidman @ybettan

Copy link

netlify bot commented Jan 30, 2024

Deploy Preview for kubernetes-sigs-kmm ready!

Name Link
🔨 Latest commit 304f486
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kmm/deploys/65c1fe583671c30008b4edc8
😎 Deploy Preview https://deploy-preview-719--kubernetes-sigs-kmm.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qbarrand

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 Jan 30, 2024
@qbarrand qbarrand force-pushed the ns-deletion-finalizer branch from a49e36c to 2574a94 Compare January 31, 2024 13:06
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2024

Codecov Report

Attention: 22 lines in your changes are missing coverage. Please review.

Comparison is base (5fc673e) 79.09% compared to head (304f486) 78.88%.
Report is 9 commits behind head on main.

Files Patch % Lines
internal/controllers/module_nmc_reconciler.go 63.15% 9 Missing and 5 partials ⚠️
internal/webhook/namespace_deletion.go 61.53% 5 Missing ⚠️
internal/meta/labels.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #719      +/-   ##
==========================================
- Coverage   79.09%   78.88%   -0.21%     
==========================================
  Files          51       52       +1     
  Lines        5109     3998    -1111     
==========================================
- Hits         4041     3154     -887     
+ Misses        882      653     -229     
- Partials      186      191       +5     

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

- do not delete any namespace containing at least a `Module` resource.
To avoid situations where KMM is unable to unload the kernel module from nodes, make sure those resources are not
deleted while the `Module` resource is still present in the cluster in any state, including `Terminating`.
KMM ships with an admission webhook that rejects the deletion of namespaces that contain at least one `Module`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
KMM ships with an admission webhook that rejects the deletion of namespaces that contain at least one `Module`
KMM ships with a validating admission webhook that rejects the deletion of namespaces that contain at least one `Module`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks!

This commit makes KMM set the kmm.node.k8s.io/contains-modules label on
all namespaces that contain at least one Module.
It also adds a new webhook to the bundle and the corresponding handler
in the manager.
The new webhook rejects namespace deletions if the
kmm.node.k8s.io/contains-modules label is present on the namespace.
This avoids entering situations where the namespace is being deleted and
KMM cannot create unloading Pods to honor Module deletion.
@qbarrand qbarrand force-pushed the ns-deletion-finalizer branch from 2574a94 to 304f486 Compare February 6, 2024 09:39
@qbarrand
Copy link
Contributor Author

qbarrand commented Feb 6, 2024

@mresvanis @yevgeny-shnaidman @ybettan PTAL 🙂

@yevgeny-shnaidman
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2024
@k8s-ci-robot k8s-ci-robot merged commit c50978c into kubernetes-sigs:main Feb 6, 2024
@qbarrand qbarrand deleted the ns-deletion-finalizer branch February 6, 2024 09:54
qbarrand added a commit to qbarrand/kernel-module-management that referenced this pull request Mar 6, 2024
This commit makes KMM set the kmm.node.k8s.io/contains-modules label on
all namespaces that contain at least one Module.
It also adds a new webhook to the bundle and the corresponding handler
in the manager.
The new webhook rejects namespace deletions if the
kmm.node.k8s.io/contains-modules label is present on the namespace.
This avoids entering situations where the namespace is being deleted and
KMM cannot create unloading Pods to honor Module deletion.
k8s-ci-robot pushed a commit that referenced this pull request Mar 6, 2024
* Add a webhook for namespace deletion (#719)

This commit makes KMM set the kmm.node.k8s.io/contains-modules label on
all namespaces that contain at least one Module.
It also adds a new webhook to the bundle and the corresponding handler
in the manager.
The new webhook rejects namespace deletions if the
kmm.node.k8s.io/contains-modules label is present on the namespace.
This avoids entering situations where the namespace is being deleted and
KMM cannot create unloading Pods to honor Module deletion.

* Restrict checks for image existence (#734)

Before populating the NodeModulesConfig object, only check if built or
signed image exist on the registry.
Add a log message when the NodeModulesConfig is not populated for that
reason.

* Make slight changes to the CRDs (#736)

Module: make moduleName an optional field.
ManagedClusterModule: make spokeNamespace a required field.
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

Handle namespace deletion and Module finalization
6 participants