Skip to content

Commit

Permalink
Make restart tracker's restart policy field public
Browse files Browse the repository at this point in the history
  • Loading branch information
danehlim committed Jun 7, 2024
1 parent 404c217 commit af767d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions ecs-agent/api/container/restart/restart_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
)

type RestartTracker struct {
RestartCount int `json:"restartCount,omitempty"`
LastRestartAt time.Time `json:"lastRestartAt,omitempty"`
restartPolicy RestartPolicy
RestartCount int `json:"restartCount,omitempty"`
LastRestartAt time.Time `json:"lastRestartAt,omitempty"`
RestartPolicy RestartPolicy `json:"restartPolicy,omitempty"`
lock sync.RWMutex
}

Expand All @@ -38,7 +38,7 @@ type RestartPolicy struct {

func NewRestartTracker(restartPolicy RestartPolicy) *RestartTracker {
return &RestartTracker{
restartPolicy: restartPolicy,
RestartPolicy: restartPolicy,
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func (rt *RestartTracker) ShouldRestart(exitCode *int, startedAt time.Time,
rt.lock.RLock()
defer rt.lock.RUnlock()

if !rt.restartPolicy.Enabled {
if !rt.RestartPolicy.Enabled {
return false, "restart policy is not enabled"
}
if desiredStatus == apicontainerstatus.ContainerStopped {
Expand All @@ -82,7 +82,7 @@ func (rt *RestartTracker) ShouldRestart(exitCode *int, startedAt time.Time,
if exitCode == nil {
return false, "exit code is nil"
}
for _, ignoredCode := range rt.restartPolicy.IgnoredExitCodes {
for _, ignoredCode := range rt.RestartPolicy.IgnoredExitCodes {
if ignoredCode == *exitCode {
return false, fmt.Sprintf("exit code %d should be ignored", *exitCode)
}
Expand All @@ -92,7 +92,7 @@ func (rt *RestartTracker) ShouldRestart(exitCode *int, startedAt time.Time,
if !rt.LastRestartAt.IsZero() {
startTime = rt.LastRestartAt
}
if time.Since(startTime) < rt.restartPolicy.RestartAttemptPeriod {
if time.Since(startTime) < rt.RestartPolicy.RestartAttemptPeriod {
return false, "attempt reset period has not elapsed"
}
return true, ""
Expand Down
6 changes: 3 additions & 3 deletions ecs-agent/api/container/restart/restart_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestShouldRestart(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
rt.restartPolicy = tc.rp
rt.RestartPolicy = tc.rp

// Because we cannot instantiate int pointers directly,
// check for the exit code and leave this int pointer as nil
Expand Down Expand Up @@ -171,6 +171,6 @@ func TestRecordRestartPolicy(t *testing.T) {
RestartAttemptPeriod: 60 * time.Second,
})
assert.Equal(t, 0, rt.RestartCount)
assert.Equal(t, 0, len(rt.restartPolicy.IgnoredExitCodes))
assert.NotNil(t, rt.restartPolicy)
assert.Equal(t, 0, len(rt.RestartPolicy.IgnoredExitCodes))
assert.NotNil(t, rt.RestartPolicy)
}

0 comments on commit af767d7

Please sign in to comment.