Skip to content

Commit 178b178

Browse files
committed
reset deploy state
1 parent 78b3c71 commit 178b178

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

pkg/skaffold/event/event.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ func emptyState(build latest.BuildConfig) proto.State {
136136
DeployState: &proto.DeployState{
137137
Status: NotStarted,
138138
},
139-
ForwardedPorts: make(map[int32]*proto.PortEvent),
139+
ForwardedPorts: make(map[int32]*proto.PortEvent),
140+
StatusCheckState: &proto.StatusCheckState{Status: NotStarted},
140141
}
141142
}
142143

@@ -282,3 +283,12 @@ func (ev *eventHandler) handle(event *proto.Event) {
282283

283284
ev.logEvent(*logEntry)
284285
}
286+
287+
// ResetStateOnDeploy resets the deploy, sync and status check state
288+
func ResetStateOnDeploy() {
289+
newState := handler.getState()
290+
newState.DeployState.Status = NotStarted
291+
newState.StatusCheckState.Status = NotStarted
292+
newState.ForwardedPorts = map[int32]*proto.PortEvent{}
293+
handler.setState(newState)
294+
}

pkg/skaffold/event/event_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,36 @@ func wait(t *testing.T, condition func() bool) {
182182
}
183183
}
184184
}
185+
186+
func TestResetStateOnBuild(t *testing.T) {
187+
defer func() { handler = &eventHandler{} }()
188+
handler = &eventHandler{
189+
state: proto.State{
190+
BuildState: &proto.BuildState{
191+
Artifacts: map[string]string{
192+
"image1": Complete,
193+
},
194+
},
195+
DeployState: &proto.DeployState{Status: Complete},
196+
ForwardedPorts: map[int32]*proto.PortEvent{
197+
2001: {
198+
LocalPort: 2000,
199+
RemotePort: 2001,
200+
PodName: "test/pod",
201+
},
202+
},
203+
StatusCheckState: &proto.StatusCheckState{Status: Complete},
204+
},
205+
}
206+
ResetStateOnDeploy()
207+
expected := proto.State{
208+
BuildState: &proto.BuildState{
209+
Artifacts: map[string]string{
210+
"image1": Complete,
211+
},
212+
},
213+
DeployState: &proto.DeployState{Status: NotStarted},
214+
StatusCheckState: &proto.StatusCheckState{Status: NotStarted},
215+
}
216+
testutil.CheckDeepEqual(t, expected, handler.getState())
217+
}

pkg/skaffold/runner/dev.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
25+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
2526
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/filemon"
2627
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
2728
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
@@ -80,6 +81,7 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error {
8081
}
8182

8283
if needsDeploy {
84+
event.ResetStateOnDeploy()
8385
defer func() {
8486
r.changeSet.resetDeploy()
8587
r.intents.resetDeploy()

pkg/skaffold/server/endpoints.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (s *server) Execute(ctx context.Context, intent *proto.UserIntentRequest) (
4949
}
5050

5151
if intent.GetIntent().GetDeploy() {
52+
event.ResetStateOnDeploy()
5253
go func() {
5354
s.deployIntentCallback()
5455
}()

0 commit comments

Comments
 (0)