From c5746ccb5069b86dd3d0714abf9b5252022aeddd Mon Sep 17 00:00:00 2001 From: Thomas Anderson <127358482+zc-devs@users.noreply.github.com> Date: Tue, 6 Aug 2024 18:07:07 +0300 Subject: [PATCH] Fail on InvalidImageName (#4007) --- pipeline/backend/kubernetes/kubernetes.go | 6 +++--- pipeline/backend/kubernetes/utils.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pipeline/backend/kubernetes/kubernetes.go b/pipeline/backend/kubernetes/kubernetes.go index 003656896..dadf913c5 100644 --- a/pipeline/backend/kubernetes/kubernetes.go +++ b/pipeline/backend/kubernetes/kubernetes.go @@ -254,7 +254,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) } if pod.Name == podName { - if isImagePullBackOffState(pod) { + if isImagePullBackOffState(pod) || isInvalidImageName(pod) { finished <- true } @@ -286,7 +286,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string) return nil, err } - if isImagePullBackOffState(pod) { + if isImagePullBackOffState(pod) || isInvalidImageName(pod) { return nil, fmt.Errorf("could not pull image for pod %s", podName) } @@ -330,7 +330,7 @@ func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string) } if pod.Name == podName { - if isImagePullBackOffState(pod) { + if isImagePullBackOffState(pod) || isInvalidImageName(pod) { up <- true } switch pod.Status.Phase { diff --git a/pipeline/backend/kubernetes/utils.go b/pipeline/backend/kubernetes/utils.go index 1393c423b..ec601bccc 100644 --- a/pipeline/backend/kubernetes/utils.go +++ b/pipeline/backend/kubernetes/utils.go @@ -65,6 +65,18 @@ func isImagePullBackOffState(pod *v1.Pod) bool { return false } +func isInvalidImageName(pod *v1.Pod) bool { + for _, containerState := range pod.Status.ContainerStatuses { + if containerState.State.Waiting != nil { + if containerState.State.Waiting.Reason == "InvalidImageName" { + return true + } + } + } + + return false +} + // getClientOutOfCluster returns a k8s client set to the request from outside of cluster. func getClientOutOfCluster() (kubernetes.Interface, error) { kubeConfigPath := os.Getenv("KUBECONFIG") // cspell:words KUBECONFIG