Skip to content

Commit

Permalink
fix: Handle StandalonePods Succeeded case when checking status (#…
Browse files Browse the repository at this point in the history
…9580)

* fix: Handle `Succeeded` case

* test: add tests for standalone pods
  • Loading branch information
Y-- authored Nov 25, 2024
1 parent 62c0a70 commit bd02eac
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/skaffold/kubernetes/status/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (r *Resource) checkStandalonePodsStatus(ctx context.Context, cfg kubectl.Co
if podReady, _ := strconv.ParseBool(string(b)); !podReady {
pendingPods = append(pendingPods, pod.Name())
}
case "Succeeded":
log.Entry(ctx).Debugf("pod '%s' succeeded - ignoring", pod.Name())
default:
pendingPods = append(pendingPods, pod.Name())
}
Expand Down Expand Up @@ -237,6 +239,10 @@ func (r *Resource) CheckStatus(ctx context.Context, cfg kubectl.Config) {
// See https://github.com/GoogleCloudPlatform/cloud-code-vscode-internal/issues/5277
if ae.ErrCode == proto.StatusCode_STATUSCHECK_SUCCESS {
for _, pod := range r.resources {
if pod.Status() == "Succeeded" {
continue // Skip terminated pods
}

eventV2.ResourceStatusCheckEventCompletedMessage(
pod.String(),
fmt.Sprintf("%s %s: running.\n", tabHeader, pod.String()),
Expand Down
52 changes: 52 additions & 0 deletions pkg/skaffold/kubernetes/status/resource/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,58 @@ func TestDeploymentCheckStatus(t *testing.T) {
}
}

func TestStandalonePodsCheckStatus(t *testing.T) {
ns := "test-ns"
tests := []struct {
description string
podStatus string
expectedMessage string
expectedErrCode proto.StatusCode
}{
{
description: "running pod not ready",
podStatus: "Running",
expectedErrCode: proto.StatusCode_STATUSCHECK_STANDALONE_PODS_PENDING,
expectedMessage: "pods not ready: [test-pod]",
},
{
description: "failed pod",
podStatus: "Failed",
expectedErrCode: proto.StatusCode_STATUSCHECK_UNKNOWN,
expectedMessage: "pod test-pod failed",
},
{
description: "pending pod",
podStatus: "Pending",
expectedErrCode: proto.StatusCode_STATUSCHECK_STANDALONE_PODS_PENDING,
expectedMessage: "pods not ready: [test-pod]",
},
{
description: "succeeded pod",
podStatus: "Succeeded",
expectedErrCode: proto.StatusCode_STATUSCHECK_SUCCESS,
expectedMessage: "",
},
{
description: "unknown status pod",
podStatus: "Unknown",
expectedErrCode: proto.StatusCode_STATUSCHECK_STANDALONE_PODS_PENDING,
expectedMessage: "pods not ready: [test-pod]",
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
r := NewResource("test-standalone-pods", ResourceTypes.StandalonePods, ns, 42, false)
r.resources = map[string]validator.Resource{}
r.resources["test-pod"] = validator.NewResource(ns, "pod", "test-pod", validator.Status(test.podStatus), nil, nil)
r.CheckStatus(context.Background(), &statusConfig{})
t.CheckDeepEqual(r.status.ae.GetMessage(), test.expectedMessage)
t.CheckDeepEqual(r.status.ae.GetErrCode(), test.expectedErrCode)
})
}
}

func TestParseKubectlError(t *testing.T) {
tests := []struct {
description string
Expand Down

0 comments on commit bd02eac

Please sign in to comment.