Skip to content

Commit

Permalink
move filed reported to changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed May 19, 2020
1 parent e9f74c6 commit eb5cbcb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
16 changes: 9 additions & 7 deletions pkg/skaffold/deploy/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ func (d *Deployment) Deadline() time.Duration {

func (d *Deployment) UpdateStatus(details string, err error) {
updated := newStatus(details, err)
if !d.status.Equal(updated) {
d.status = updated
if strings.Contains(details, rollOutSuccess) || isErrAndNotRetryAble(err) {
d.done = true
}
if d.status.Equal(updated) {
d.status.changed = false
return
}
d.status = updated
d.status.changed = true
if strings.Contains(details, rollOutSuccess) || isErrAndNotRetryAble(err) {
d.done = true
}
}

Expand Down Expand Up @@ -111,10 +114,9 @@ func (d *Deployment) IsStatusCheckComplete() bool {
}

func (d *Deployment) ReportSinceLastUpdated() string {
if d.status.reported {
if !d.status.changed {
return ""
}
d.status.reported = true
return fmt.Sprintf("%s: %s", d, d.status)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/deploy/resource/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestReportSinceLastUpdated(t *testing.T) {
dep.UpdateStatus(test.message, test.err)

t.CheckDeepEqual(test.expected, dep.ReportSinceLastUpdated())
t.CheckTrue(dep.status.reported)
t.CheckTrue(dep.status.changed)
})
}
}
Expand All @@ -231,9 +231,10 @@ func TestReportSinceLastUpdatedMultipleTimes(t *testing.T) {
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
dep := NewDeployment("test", "test-ns", 1)
dep.UpdateStatus("cannot pull image", nil)
var actual string
for i := 0; i < test.times; i++ {
// update to same status
dep.UpdateStatus("cannot pull image", nil)
actual = dep.ReportSinceLastUpdated()
}
t.CheckDeepEqual(test.expected, actual)
Expand Down
7 changes: 4 additions & 3 deletions pkg/skaffold/deploy/resource/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package resource

type Status struct {
err error
details string
reported bool
err error
details string
changed bool
}

func (rs Status) Error() error {
Expand Down Expand Up @@ -47,5 +47,6 @@ func newStatus(msg string, err error) Status {
return Status{
details: msg,
err: err,
changed: true,
}
}

0 comments on commit eb5cbcb

Please sign in to comment.