-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20550 from juanvallejo/jvallejo/fix-debug-panic
Fix debug panic
- Loading branch information
Showing
6 changed files
with
123 additions
and
16 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package conditions | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/kubernetes/pkg/kubectl" | ||
) | ||
|
||
// PodContainerRunning returns false until the named container has ContainerStatus running (at least once), | ||
// and will return an error if the pod is deleted, runs to completion, or the container pod is not available. | ||
func PodContainerRunning(containerName string) watch.ConditionFunc { | ||
return func(event watch.Event) (bool, error) { | ||
switch event.Type { | ||
case watch.Deleted: | ||
return false, errors.NewNotFound(schema.GroupResource{Resource: "pods"}, "") | ||
} | ||
switch t := event.Object.(type) { | ||
case *corev1.Pod: | ||
switch t.Status.Phase { | ||
case corev1.PodRunning, corev1.PodPending: | ||
case corev1.PodFailed, corev1.PodSucceeded: | ||
return false, kubectl.ErrPodCompleted | ||
default: | ||
return false, nil | ||
} | ||
for _, s := range t.Status.ContainerStatuses { | ||
if s.Name != containerName { | ||
continue | ||
} | ||
if s.State.Terminated != nil { | ||
return false, kubectl.ErrContainerTerminated | ||
} | ||
return s.State.Running != nil, nil | ||
} | ||
for _, s := range t.Status.InitContainerStatuses { | ||
if s.Name != containerName { | ||
continue | ||
} | ||
if s.State.Terminated != nil { | ||
return false, kubectl.ErrContainerTerminated | ||
} | ||
return s.State.Running != nil, nil | ||
} | ||
return false, nil | ||
} | ||
return false, nil | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.