Skip to content

Commit 290280e

Browse files
authored
Send success for pods for a deployment when its rolled out successfully (#6534)
* Send success for pods if deployment is successfule * fix test * fix lint
1 parent 0da149a commit 290280e

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

pkg/skaffold/kubernetes/status/resource/deployment.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
3131
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log"
3232
"github.com/GoogleContainerTools/skaffold/proto/v1"
33+
protoV2 "github.com/GoogleContainerTools/skaffold/proto/v2"
3334
)
3435

3536
const (
@@ -132,12 +133,24 @@ func (d *Deployment) CheckStatus(ctx context.Context, cfg kubectl.Config) {
132133

133134
details := d.cleanupStatus(string(b))
134135

135-
ae := parseKubectlRolloutError(details, err)
136-
if ae.ErrCode == proto.StatusCode_STATUSCHECK_KUBECTL_PID_KILLED {
137-
ae.Message = fmt.Sprintf("received Ctrl-C or deployments could not stabilize within %v: %v", d.deadline, err)
138-
}
139-
136+
ae := parseKubectlRolloutError(details, d.deadline, err)
140137
d.UpdateStatus(ae)
138+
// send event update in check status.
139+
event.ResourceStatusCheckEventCompleted(d.String(), ae)
140+
eventV2.ResourceStatusCheckEventCompleted(d.String(), sErrors.V2fromV1(ae))
141+
// if deployment is successfully rolled out, send pod success event to make sure
142+
// all pod are marked as success in V2
143+
// See https://github.com/GoogleCloudPlatform/cloud-code-vscode-internal/issues/5277
144+
if ae.ErrCode == proto.StatusCode_STATUSCHECK_SUCCESS {
145+
for _, pod := range d.pods {
146+
eventV2.ResourceStatusCheckEventCompletedMessage(
147+
pod.String(),
148+
fmt.Sprintf("%s %s: running.\n", tabHeader, pod.String()),
149+
protoV2.ActionableErr{ErrCode: proto.StatusCode_STATUSCHECK_SUCCESS},
150+
)
151+
}
152+
return
153+
}
141154
if err := d.fetchPods(ctx); err != nil {
142155
log.Entry(ctx).Debugf("pod statuses could not be fetched this time due to %s", err)
143156
}
@@ -233,7 +246,7 @@ func (d *Deployment) cleanupStatus(msg string) string {
233246
// $kubectl logs testPod -f
234247
// 2020/06/18 17:28:31 service is running
235248
// Killed: 9
236-
func parseKubectlRolloutError(details string, err error) proto.ActionableErr {
249+
func parseKubectlRolloutError(details string, deadline time.Duration, err error) proto.ActionableErr {
237250
switch {
238251
case err == nil && strings.Contains(details, rollOutSuccess):
239252
return proto.ActionableErr{
@@ -253,7 +266,7 @@ func parseKubectlRolloutError(details string, err error) proto.ActionableErr {
253266
case strings.Contains(err.Error(), killedErrMsg):
254267
return proto.ActionableErr{
255268
ErrCode: proto.StatusCode_STATUSCHECK_KUBECTL_PID_KILLED,
256-
Message: msgKubectlKilled,
269+
Message: fmt.Sprintf("received Ctrl-C or deployments could not stabilize within %v: %s", deadline, msgKubectlKilled),
257270
}
258271
default:
259272
return proto.ActionableErr{

pkg/skaffold/kubernetes/status/resource/deployment_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ import (
2323
"os"
2424
"path/filepath"
2525
"testing"
26+
"time"
2627

2728
"github.com/GoogleContainerTools/skaffold/pkg/diag/validator"
2829
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
30+
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
2931
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
3032
"github.com/GoogleContainerTools/skaffold/proto/v1"
3133
"github.com/GoogleContainerTools/skaffold/testutil"
34+
testEvent "github.com/GoogleContainerTools/skaffold/testutil/event"
3235
)
3336

3437
func TestDeploymentCheckStatus(t *testing.T) {
@@ -100,6 +103,7 @@ func TestDeploymentCheckStatus(t *testing.T) {
100103
for _, test := range tests {
101104
testutil.Run(t, test.description, func(t *testutil.T) {
102105
t.Override(&util.DefaultExecCommand, test.commands)
106+
testEvent.InitializeState([]latestV1.Pipeline{{}})
103107

104108
r := NewDeployment("graph", "test", 0)
105109
r.CheckStatus(context.Background(), &statusConfig{})
@@ -140,7 +144,7 @@ func TestParseKubectlError(t *testing.T) {
140144
err: errors.New("signal: killed"),
141145
expectedAe: proto.ActionableErr{
142146
ErrCode: proto.StatusCode_STATUSCHECK_KUBECTL_PID_KILLED,
143-
Message: msgKubectlKilled,
147+
Message: "received Ctrl-C or deployments could not stabilize within 10s: kubectl rollout status command interrupted\n",
144148
},
145149
},
146150
{
@@ -162,7 +166,7 @@ func TestParseKubectlError(t *testing.T) {
162166
}
163167
for _, test := range tests {
164168
testutil.Run(t, test.description, func(t *testutil.T) {
165-
ae := parseKubectlRolloutError(test.details, test.err)
169+
ae := parseKubectlRolloutError(test.details, 10*time.Second, test.err)
166170
t.CheckDeepEqual(test.expectedAe, ae)
167171
})
168172
}

pkg/skaffold/kubernetes/status/status_check.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ func (s *Monitor) printStatusCheckSummary(out io.Writer, r *resource.Deployment,
288288
// another deployment failed
289289
return
290290
}
291-
event.ResourceStatusCheckEventCompleted(r.String(), ae)
292-
eventV2.ResourceStatusCheckEventCompleted(r.String(), sErrors.V2fromV1(ae))
293291
out, _ = output.WithEventContext(context.Background(), out, constants.Deploy, r.String())
294292
status := fmt.Sprintf("%s %s", tabHeader, r)
295293
if ae.ErrCode != proto.StatusCode_STATUSCHECK_SUCCESS {

pkg/skaffold/kubernetes/status/status_check_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,6 @@ func TestPollDeployment(t *testing.T) {
596596
"Pending",
597597
proto.ActionableErr{ErrCode: proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE},
598598
[]string{"err"})},
599-
// pod recovered
600-
{validator.NewResource(
601-
"test",
602-
"pod",
603-
"dep-pod",
604-
"Running",
605-
proto.ActionableErr{ErrCode: proto.StatusCode_STATUSCHECK_SUCCESS},
606-
nil)},
607599
},
608600
expected: proto.StatusCode_STATUSCHECK_SUCCESS,
609601
},

0 commit comments

Comments
 (0)