-
Notifications
You must be signed in to change notification settings - Fork 779
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
support fix containerrecreaterequest #1182
support fix containerrecreaterequest #1182
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #1182 +/- ##
==========================================
+ Coverage 49.73% 50.05% +0.32%
==========================================
Files 137 143 +6
Lines 19331 19906 +575
==========================================
+ Hits 9614 9964 +350
- Misses 8667 8848 +181
- Partials 1050 1094 +44
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -362,10 +363,25 @@ func (c *Controller) manage(crr *appsv1alpha1.ContainerRecreateRequest) error { | |||
} | |||
return c.patchCRRContainerRecreateStates(crr, newCRRContainerRecreateStates) | |||
} | |||
|
|||
if crr.Spec.Strategy.ForceRecreate { | |||
newForceKilledContainerStatuses = append(newForceKilledContainerStatuses, appsv1alpha1.ContainerRecreateRequestForceKilledContainerStatus{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't have to patch "forcekill" status if the container do not have to be recreated forcefully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if crr.Spec.Strategy.ForceRecreate && state.ShouldBeKilledByForce {
state.IsForceKilled = true
state.ContainerID = kubeContainerStatus.ID.String()
}
config/rbac/daemon_role.yaml
Outdated
@@ -38,6 +38,7 @@ rules: | |||
- get | |||
- list | |||
- watch | |||
- patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is recommended to avoid assign object patch privilege to daemons, so the container id of killed container can be saved in crr status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// Name of the container. | ||
Name string `json:"name"` | ||
// Container is killed by force | ||
IsForceKilled bool `json:"restartCount"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct tag for IsForceKilled should be isForceKilled or something similar. restartCount is considered as something different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
303851d
to
5e15dc1
Compare
@@ -37,6 +37,9 @@ const ( | |||
// ContainerRecreateRequestUnreadyAcquiredKey indicates the Pod has been forced to not-ready. | |||
// It is required if the unreadyGracePeriodSeconds is set in ContainerRecreateRequests. | |||
ContainerRecreateRequestUnreadyAcquiredKey = "crr.apps.kruise.io/unready-acquired" | |||
|
|||
// It is a status key for containers which are be killed by crr | |||
ContainerRecreateRequestForceKilledContainerStatusesKey = "crr.apps.kruise.io/force-killed-container-statuses" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unused key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
@@ -106,6 +109,8 @@ type ContainerRecreateRequestStrategy struct { | |||
FailurePolicy ContainerRecreateRequestFailurePolicyType `json:"failurePolicy,omitempty"` | |||
// OrderedRecreate indicates whether to recreate the next container only if the previous one has recreated completely. | |||
OrderedRecreate bool `json:"orderedRecreate,omitempty"` | |||
// ForceRecreate indicates whether to force kill the container even if the previous container is not running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the previous container is not running -> if the previous container is starting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -158,6 +163,12 @@ type ContainerRecreateRequestContainerRecreateState struct { | |||
Phase ContainerRecreateRequestPhase `json:"phase"` | |||
// A human readable message indicating details about this state. | |||
Message string `json:"message,omitempty"` | |||
// Container should be killed by force | |||
ShouldBeKilledByForce bool `json:"shouldBeKilledByForce"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use crr.Spec.Strategy.ForceRecreate instead? it seems this status field unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShouldBeKilledByForce has been removed in this solution
@@ -172,6 +183,16 @@ type ContainerRecreateRequestSyncContainerStatus struct { | |||
ContainerID string `json:"containerID,omitempty"` | |||
} | |||
|
|||
// ContainerRecreateRequestKilledContainerStatus contains the state of the last killed container. | |||
type ContainerRecreateRequestForceKilledContainerStatus struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
@@ -69,6 +69,8 @@ func getCurrentCRRContainersRecreateStates( | |||
} | |||
|
|||
syncContainerStatuses := getCRRSyncContainerStatuses(crr) | |||
// the statuses of force killed containers for this crr resource | |||
forceKillContainerStatuses := getCRRForceKillContainersStatuses(crr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCRRForceKillContainersStatuses -> getKilledContainersStatuses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -128,6 +136,16 @@ func getCurrentCRRContainersRecreateStates( | |||
return statuses | |||
} | |||
|
|||
func containerIsNotForceKilled(recreateState *appsv1alpha1.ContainerRecreateRequestContainerRecreateState) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
containerIsNotForceKilled -> containerIsForceKilled
plz revert the func logic to make code more easy to understand
|
||
if crr.Spec.Strategy.ForceRecreate && (len(forceKillContainerStatuses) == 0 || | ||
containerIsNotForceKilled(killedContainerStatus)) { | ||
currentState.ShouldBeKilledByForce = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShouldBeKilledByForce -> IsForceKilled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new logic is changed in this code.
@@ -362,6 +362,11 @@ func (c *Controller) manage(crr *appsv1alpha1.ContainerRecreateRequest) error { | |||
} | |||
return c.patchCRRContainerRecreateStates(crr, newCRRContainerRecreateStates) | |||
} | |||
|
|||
if crr.Spec.Strategy.ForceRecreate && state.ShouldBeKilledByForce { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should populate ContainerID even if the container is not killed forcely
@@ -114,7 +118,11 @@ func getCurrentCRRContainersRecreateStates( | |||
syncContainerStatus.Ready { | |||
currentState.Phase = appsv1alpha1.ContainerRecreateRequestSucceeded | |||
} | |||
|
|||
if crr.Spec.Strategy.ForceRecreate && (len(forceKillContainerStatuses) == 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len(forceKillContainerStatuses) checking is not necessary, containerIsNotForceKilled will check whether recreateState == nil , plz remove len(forceKillContainerStatuses) checking
d367244
to
88baf65
Compare
if recreateState.IsForceKilled { | ||
return true | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return recreateState != nil && recreateState.IsForceKilled
@@ -158,6 +160,8 @@ type ContainerRecreateRequestContainerRecreateState struct { | |||
Phase ContainerRecreateRequestPhase `json:"phase"` | |||
// A human readable message indicating details about this state. | |||
Message string `json:"message,omitempty"` | |||
// Container has been killed by force | |||
IsForceKilled bool `json:"isForceKilled,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsRealKilled bool ?
@@ -93,13 +97,21 @@ func getCurrentCRRContainersRecreateStates( | |||
Message: "not found container on Node", | |||
} | |||
|
|||
} else if crr.Spec.Strategy.ForceRecreate && !containerIsForceKilled(killedContainerStatus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if crr.Spec.Strategy.ForceRecreate {
if previousContainerRecreateState == nil || !previousContainerRecreateState.IsRealKilled {
currentState = appsv1alpha1.ContainerRecreateRequestContainerRecreateState{
Name: c.Name,
Phase: appsv1alpha1.ContainerRecreateRequestPending,
Message: "No real kill container yet",
}
statuses = append(statuses, currentState)
continue
}
}
88baf65
to
ab2d8e9
Compare
ab2d8e9
to
7e43eb2
Compare
7e43eb2
to
7a252af
Compare
} | ||
} | ||
|
||
// current: previousContainerRecreateState.IsRealKilled = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsRealKilled -> IsKilled
@@ -85,40 +85,56 @@ func getCurrentCRRContainersRecreateStates( | |||
kubeContainerStatus := podStatus.FindContainerStatusByName(c.Name) | |||
|
|||
var currentState appsv1alpha1.ContainerRecreateRequestContainerRecreateState | |||
|
|||
if crr.Spec.Strategy.ForceRecreate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we skip crr with completed phase in L77.
7a252af
to
d522f61
Compare
d522f61
to
6f60438
Compare
Signed-off-by: jicheng.sk <jicheng.sk@alibaba-inc.com>
6f60438
to
f275bd3
Compare
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[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 |
Signed-off-by: jicheng.sk <jicheng.sk@alibaba-inc.com> Co-authored-by: jicheng.sk <jicheng.sk@alibaba-inc.com>
Signed-off-by: jicheng.sk <jicheng.sk@alibaba-inc.com> Co-authored-by: jicheng.sk <jicheng.sk@alibaba-inc.com>
Co-authored-by: jicheng.sk <jicheng.sk@alibaba-inc.com>
Ⅰ. Describe what this PR does
add the
forceRecreate
to container recreate request feature. When a crr resource is created withforceRecreate
= true, the container will be kill once by forcibly and immediately.Ⅱ. Does this pull request fix one issue?
yes, issue: #1177
Ⅲ. Describe how to verify it
using the container recreate request and the
forceRecreate
is set true.Ⅳ. Special notes for reviews