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

Sidecar terminator ignore the exit code of the sidecar container #1303

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

diannaowa
Copy link
Contributor

@diannaowa diannaowa commented Jun 2, 2023

Ⅰ. Describe what this PR does

Pods are not allowed to transition out of terminal phases when kubelet report the pod status.(ref)
Base on this context, the proposal as bellow:
In the sidecar terminator controller:
1,Calculate the Pod phase from the exit-code of the main container:
the pod phase will be Succeeded, if all main containers are succeeded .
the pod phase will be failed ,if at least one main container is failed(the exitCode is not zero) .
2, Terminate it if the job pod is complete.

3, Terminate the pod and set the condition of the pod as the bellow:

- lastProbeTime: null
    lastTransitionTime: "2023-06-06T14:06:08Z"
    status: "True"
    type: SidecarTerminated

4, If the job pod is completed, we will skip terminating the pod. Check whether a job is complete by:

func isJobPodCompleted(pod *corev1.Pod) bool {
	mainContainers := getMain(pod)
	if !containersCompleted(pod, mainContainers) {
		return false
	}
	if containersSucceeded(pod, mainContainers) {
		return pod.Status.Phase == corev1.PodSucceeded
	} else {
		return pod.Status.Phase == corev1.PodFailed
	}
}

Native controller actions:

1 .Job controller update the status of the job when pod phase is updated.
2. As we said above, kubelet only update the container status and do not update the pod phase since it is terminal phase. And the pod will reach a final state.
3. Kubelet will kill the containers that are not in terminal phase, after the pod the terminated by sidecar terminator.

Ⅱ. Does this pull request fix one issue?

fixes #1285

Ⅲ. Describe how to verify it

Ⅳ. Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2023

Codecov Report

Attention: Patch coverage is 79.06977% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 47.89%. Comparing base (209d476) to head (a66d98f).

Files Patch % Lines
...sidecarterminator/sidecar_terminator_controller.go 77.50% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1303      +/-   ##
==========================================
+ Coverage   47.82%   47.89%   +0.06%     
==========================================
  Files         161      161              
  Lines       23395    23428      +33     
==========================================
+ Hits        11188    11220      +32     
- Misses      10993    10995       +2     
+ Partials     1214     1213       -1     
Flag Coverage Δ
unittests 47.89% <79.06%> (+0.06%) ⬆️

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.

@diannaowa diannaowa force-pushed the feat_1285 branch 2 times, most recently from 64b8f72 to da6496f Compare June 5, 2023 07:13
@kruise-bot kruise-bot added size/L size/L: 100-499 and removed size/XL size/XL: 500-999 labels Jun 5, 2023
@veophi
Copy link
Member

veophi commented Oct 30, 2023

@diannaowa Can we set Pod.Status.Phase to Succeeded/Failed BEFORE killing sidecars?

Copy link

stale bot commented Jan 29, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 29, 2024
@diannaowa
Copy link
Contributor Author

will do

@stale stale bot removed the wontfix This will not be worked on label Jan 29, 2024
@diannaowa diannaowa force-pushed the feat_1285 branch 2 times, most recently from 048e9da to 01f9580 Compare March 8, 2024 07:49
// after the pod is terminated by the sidecar terminator, kubelet will kill the containers that are not in the terminal phase
// 1. sidecar container terminate with non-zero exit code
// 2. sidecar container is not in a terminal phase (still running or waiting)
if !containersSucceeded(pod, sidecars) {
Copy link
Member

Choose a reason for hiding this comment

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

plz reverse the checking to reduce code indentation, e..g

if containersSucceeded(pod, sidecars) {
   return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)

func GetHost() string {
return os.Getenv("WEBHOOK_HOST")
return os.Getenv("$1ST")
Copy link
Member

Choose a reason for hiding this comment

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

why change the env ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, my fault. Test code.
Done.

@diannaowa diannaowa force-pushed the feat_1285 branch 3 times, most recently from 14ae299 to a1465b5 Compare March 12, 2024 11:50
@zmberg
Copy link
Member

zmberg commented Mar 12, 2024

/lgtm

Signed-off-by: liuzhenwei <[email protected]>

add ut

Signed-off-by: liuzhenwei <[email protected]>

add some comments and simplified some code

Signed-off-by: liuzhenwei <[email protected]>

remove unnecessary pod status operations

Signed-off-by: liuzhenwei <[email protected]>

change pod to terminal phase before create crr

Signed-off-by: liuzhenwei <[email protected]>

reverse the checking to reduce code indentation

Signed-off-by: liuzhenwei <[email protected]>

simplified some logic

Signed-off-by: liuzhenwei <[email protected]>

remove unesd code and rename function avoid misleading

Signed-off-by: liuzhenwei <[email protected]>
Copy link
Member

@furykerry furykerry left a comment

Choose a reason for hiding this comment

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

/lgtm

@furykerry
Copy link
Member

/approve

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: furykerry

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 861818e into openkruise:master Mar 13, 2024
27 checks passed
ppbits pushed a commit to ppbits/kruise that referenced this pull request Apr 4, 2024
…nkruise#1303)

add ut



add some comments and simplified some code



remove unnecessary pod status operations



change pod to terminal phase before create crr



reverse the checking to reduce code indentation



simplified some logic



remove unesd code and rename function avoid misleading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] Sidecar terminator ignore the exit code of the sidecar container
6 participants