-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Move Initialized() to e2e framework util #83812
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -675,18 +675,18 @@ func ContainerInitInvariant(older, newer runtime.Object) error { | |
if err := initContainersInvariants(newPod); err != nil { | ||
return err | ||
} | ||
oldInit, _, _ := e2epod.Initialized(oldPod) | ||
newInit, _, _ := e2epod.Initialized(newPod) | ||
oldInit, _, _ := initialized(oldPod) | ||
newInit, _, _ := initialized(newPod) | ||
if oldInit && !newInit { | ||
// TODO: we may in the future enable resetting Initialized = false if the kubelet needs to restart it | ||
// TODO: we may in the future enable resetting initialized = false if the kubelet needs to restart it | ||
// from scratch | ||
return fmt.Errorf("pod cannot be initialized and then regress to not being initialized") | ||
} | ||
return nil | ||
} | ||
|
||
func initContainersInvariants(pod *v1.Pod) error { | ||
allInit, initFailed, err := e2epod.Initialized(pod) | ||
allInit, initFailed, err := initialized(pod) | ||
Comment on lines
688
to
+689
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. initContainersInvariants should also be refactored along with |
||
if err != nil { | ||
return err | ||
} | ||
|
@@ -2837,3 +2837,25 @@ func PrettyPrintJSON(metrics interface{}) string { | |
} | ||
return string(formatted.Bytes()) | ||
} | ||
|
||
// initialized checks the state of all init containers in the pod. | ||
func initialized(pod *v1.Pod) (ok bool, failed bool, err error) { | ||
allInit := true | ||
initFailed := false | ||
for _, s := range pod.Status.InitContainerStatuses { | ||
switch { | ||
case initFailed && s.State.Waiting == nil: | ||
return allInit, initFailed, fmt.Errorf("container %s is after a failed container but isn't waiting", s.Name) | ||
case allInit && s.State.Waiting == nil: | ||
return allInit, initFailed, fmt.Errorf("container %s is after an initializing container but isn't waiting", s.Name) | ||
case s.State.Terminated == nil: | ||
allInit = false | ||
case s.State.Terminated.ExitCode != 0: | ||
allInit = false | ||
initFailed = true | ||
case !s.Ready: | ||
return allInit, initFailed, fmt.Errorf("container %s initialized but isn't marked as ready", s.Name) | ||
} | ||
} | ||
return allInit, initFailed, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 anything, I think we should move this to the e2epod package in order to decouple this functionality from the framework.
The method that calls e2epodInitialized is containerInitInvariant().
This method is used a lot in conjunction with
framework.CheckInvariants()
.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.
guess for future reviews: it is ok to move a method back into the framework if it is only used by the framework (?)
/hold cancel
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 I think if only consumed by framework it's fine to bring it in
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.
But we should be careful cause it becomes really easy for someone else to export this function later and call it from somewhere else.