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: Support the deletion protection of service and ingress #1269

Conversation

kevin1689-cloud
Copy link
Contributor

Ⅰ. Describe what this PR does

This PR complete a feature: Support the deletion protection of service and ingress resources

Ⅱ. Does this pull request fix one issue?

fixs #1218

Ⅲ. Describe how to verify it

The Cascading judgement of Service and Ingress is whether there are any endpoints exist for the Service or Ingress. The verify steps is as show below:

Service Deleteion Protection
1.Create a Service and label it with "policy.kruise.io/delete-protection=Always"
2.Delete the Service should be rejected
3.Patch the Service with label "policy.kruise.io/delete-protection=Cascading"
4.Create endpoints of the Service
5.Delete the Service should be rejected
6.Delete all endpoints of the Service
7.The Service can be delete successfully

Ingress Deleteion Protection
1.Create a Ingress and label it with "policy.kruise.io/delete-protection=Always"
2.Delete the Ingress should be rejected
3.Patch the Ingress with label "policy.kruise.io/delete-protection=Cascading"
4.Create Service which menotioned in spec.rules.http.paths.backend.service of Ingress spec
5.Create endpoints of the Service
6.Delete the Ingress should be rejected
7.Delete all endpoints of the Service
8.The Ingress can be delete successfully

Ⅳ. Special notes for reviews

None

@kruise-bot kruise-bot requested review from FillZpp and furykerry April 28, 2023 00:59
@kruise-bot kruise-bot added the size/L size/L: 100-499 label Apr 28, 2023
@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch 2 times, most recently from 32d5ece to 66ce4af Compare April 28, 2023 11:09
@kruise-bot kruise-bot added size/XL size/XL: 500-999 and removed size/L size/L: 100-499 labels Apr 28, 2023
@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch from 66ce4af to 0b8567f Compare April 28, 2023 16:42
@kevin1689-cloud
Copy link
Contributor Author

Hi, I saw there are some CI ans E2E checks not successful. I checked my code and found there are indeed some bugs in my code. I'm working on to fix them, it's no need to review my code now. When I'm done, I will leave comment to require for code review. Thanks.

@zmberg
Copy link
Member

zmberg commented May 8, 2023

@kevin1689-cloud tks very much, k8s community also have related PR, I have not yet figured out how to implement this.

@kevin1689-cloud
Copy link
Contributor Author

kevin1689-cloud commented May 18, 2023

@kevin1689-cloud tks very much, k8s community also have related PR, I have not yet figured out how to implement this.

Got it, I'm reading Conversation of the mentioned k8s community PR, the concept of "Lien" is interesting. I‘ve been busy at my company work recently, I thought I could back to working on this pr about 2-3 weeks later and I will fix the bug in my code, read the k8s community PR carefully and give my opinion on that.

@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch 4 times, most recently from 95c0be5 to 43c376f Compare May 27, 2023 13:08
@zmberg
Copy link
Member

zmberg commented Jun 1, 2023

@kevin1689-cloud Should we discuss this at the community meeting next Thursday evening?

@kevin1689-cloud
Copy link
Contributor Author

kevin1689-cloud commented Jun 2, 2023

@kevin1689-cloud Should we discuss this at the community meeting next Thursday evening?

@zmberg Hi, thanks for the invite, how about we discuss this at the community meeting after next Thursday? I have some company project issue to due with in next week, and I'm afraid can't attend the community meeting in time. By the next community meeting, I will be ready.

@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch from 43c376f to dc63b5a Compare July 9, 2023 04:21
@kruise-bot kruise-bot added size/L size/L: 100-499 and removed size/XL size/XL: 500-999 labels Jul 9, 2023
@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch from dc63b5a to 78db319 Compare July 9, 2023 04:32
@kevin1689-cloud
Copy link
Contributor Author

@zmberg Hi, as we discussed, the main scenarios of service&ingress deletion protection is:

  • Avoid the IP address of service&ingress to be changed due to accidental deletion.

So this time we only support the Always delete protection. I noticed there are two E2E checks not successful, but seems they are not caused by this PR.

Please take a look. Thanks!

@@ -474,6 +474,27 @@ webhooks:
resources:
- imagepulljobs
sideEffects: None
- admissionReviewVersions:
Copy link
Member

Choose a reason for hiding this comment

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

add vingress.kb.io and vservice.kb.io in file

@@ -0,0 +1,25 @@
/*
Copyright 2021 The Kruise Authors.
Copy link
Member

Choose a reason for hiding this comment

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

2023

"context"
"net/http"

"github.com/openkruise/kruise/pkg/webhook/util/deletionprotection"
Copy link
Member

Choose a reason for hiding this comment

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

gofmt imports sort

"context"
"net/http"

"github.com/openkruise/kruise/pkg/webhook/util/deletionprotection"
Copy link
Member

Choose a reason for hiding this comment

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

gofmt imports sort.

@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch from 78db319 to ab3a2f7 Compare July 10, 2023 04:26
@kevin1689-cloud
Copy link
Contributor Author

@zmberg Done. Please take a look.

@zmberg
Copy link
Member

zmberg commented Jul 10, 2023

/lgtm

)

func init() {
addHandlers(validating.HandlerMap)
Copy link
Member

Choose a reason for hiding this comment

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

you'd better use addHandlersWithGate

Copy link
Member

Choose a reason for hiding this comment

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

Do not add the handler if corresponding feature-gate is not enabled.

Copy link
Contributor Author

@kevin1689-cloud kevin1689-cloud Aug 8, 2023

Choose a reason for hiding this comment

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

@veophi Done, did the same change as add_service.go.

@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch from ab3a2f7 to 880aaf9 Compare August 8, 2023 01:26
@kruise-bot kruise-bot added size/XL size/XL: 500-999 and removed lgtm size/L size/L: 100-499 labels Aug 8, 2023

func init() {
addHandlersWithGate(validating.HandlerMap, func() (enabled bool) {
if !utilfeature.DefaultFeatureGate.Enabled(features.ResourcesDeletionProtection) {
Copy link

Choose a reason for hiding this comment

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

S1008: should use 'return utilfeature.DefaultFeatureGate.Enabled(features.ResourcesDeletionProtection)' instead of 'if !utilfeature.DefaultFeatureGate.Enabled(features.ResourcesDeletionProtection) { return false }; return true'


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


func init() {
addHandlersWithGate(validating.HandlerMap, func() (enabled bool) {
if !utilfeature.DefaultFeatureGate.Enabled(features.ResourcesDeletionProtection) {
Copy link

Choose a reason for hiding this comment

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

S1008: should use 'return utilfeature.DefaultFeatureGate.Enabled(features.ResourcesDeletionProtection)' instead of 'if !utilfeature.DefaultFeatureGate.Enabled(features.ResourcesDeletionProtection) { return false }; return true'


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

Signed-off-by: kevin1689 <kevinyang1689@163.com>
@kevin1689-cloud kevin1689-cloud force-pushed the service_ingress_deletion_protection branch from 880aaf9 to aa32751 Compare August 8, 2023 02:01
@kruise-bot kruise-bot added size/L size/L: 100-499 and removed size/XL size/XL: 500-999 labels Aug 8, 2023
@kevin1689-cloud kevin1689-cloud requested a review from veophi August 8, 2023 03:07
@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (master@9ccd897). Click here to learn what that means.
Report is 47 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1269   +/-   ##
=========================================
  Coverage          ?   50.26%           
=========================================
  Files             ?      157           
  Lines             ?    23450           
  Branches          ?        0           
=========================================
  Hits              ?    11787           
  Misses            ?    10460           
  Partials          ?     1203           
Flag Coverage Δ
unittests 50.26% <ø> (?)

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.

@zmberg zmberg closed this Jan 5, 2024
@zmberg zmberg reopened this Jan 5, 2024
@zmberg
Copy link
Member

zmberg commented Mar 7, 2024

/lgtm

@kruise-bot kruise-bot added the lgtm label Mar 7, 2024
@zmberg
Copy link
Member

zmberg commented Mar 7, 2024

/approve

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zmberg

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

@kruise-bot kruise-bot merged commit 04254fb into openkruise:master Mar 7, 2024
26 checks passed
@zmberg zmberg modified the milestones: v1.5, 1.6 Mar 7, 2024
ppbits pushed a commit to ppbits/kruise that referenced this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants