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

refactor(garcedelete webhook): refactor garcedelete webhook with podd… #146

Merged
merged 2 commits into from
Jan 16, 2024
Merged

refactor(garcedelete webhook): refactor garcedelete webhook with podd… #146

merged 2 commits into from
Jan 16, 2024

Conversation

cyh-ant
Copy link
Contributor

@cyh-ant cyh-ant commented Jan 10, 2024

…eletion_controller

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N

2. What is the scope of this PR (e.g. component or file name):

pkg/webhook/server/generic/pod/gracedelete

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains experimental features

The garcedelete webhook is refactored in this PR, to fix that The sts workload is not supported in last version.
In this PR, pod deletion requests are intercepted by the garcedelete webhook firstly, and then label pod to trigger poddeletion_controlelr reconcile.

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test

6. Release note

None

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

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

Comparison is base (08cd567) 63.54% compared to head (26b929f) 63.36%.

❗ Current head 26b929f differs from pull request most recent head d52461f. Consider uploading reports for the commit d52461f to get more accurate results

Files Patch % Lines
.../webhook/server/generic/pod/gracedelete/webhook.go 43.47% 8 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #146      +/-   ##
==========================================
- Coverage   63.54%   63.36%   -0.19%     
==========================================
  Files          72       72              
  Lines        4704     4708       +4     
==========================================
- Hits         2989     2983       -6     
- Misses       1430     1438       +8     
- Partials      285      287       +2     
Flag Coverage Δ
unittests 63.36% <43.47%> (-0.19%) ⬇️

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.

if newPod.Labels[appsv1alpha1.PodDeletionIndicationLabelKey] == "true" {
return nil
}
newPod.Labels[appsv1alpha1.PodDeletionIndicationLabelKey] = "true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you set the label value to a timestamp? It would be better to troubleshoot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The label value has been set to a timestamp.

if newPod.Labels == nil {
newPod.Labels = map[string]string{}
}
if newPod.Labels[appsv1alpha1.PodDeletionIndicationLabelKey] == "true" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The label value would not always be true.

Copy link
Contributor Author

@cyh-ant cyh-ant Jan 15, 2024

Choose a reason for hiding this comment

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

Row 71 has been fixed as
if _, ok := newPod.Labels[appsv1alpha1.PodDeletionIndicationLabelKey]; ok {return nil}

@@ -49,42 +49,44 @@ func (gd *GraceDelete) Name() string {
func (gd *GraceDelete) Validating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error {
// GraceDeleteWebhook FeatureGate defaults to false
// Add '--feature-gates=GraceDeleteWebhook=true' to container args, to enable gracedelete webhook
if !feature.DefaultFeatureGate.Enabled(features.GraceDeleteWebhook) || operation != admissionv1.Delete {
if !feature.DefaultFeatureGate.Enabled(features.GraceDeleteWebhook) || operation != admissionv1.Delete || !utils.ControlledByKusionStack(oldPod) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about changing the oldPod in utils.ControlledByKusionStack(oldPod) to newPod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no newPod for DELETE request, since the oldObject field is nil.

Copy link
Collaborator

@wu8685 wu8685 left a comment

Choose a reason for hiding this comment

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

lgtm

@wu8685 wu8685 merged commit f2fabbb into KusionStack:main Jan 16, 2024
5 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

提供灰度流量的能力
2 participants