Skip to content

Commit

Permalink
Ignore schedules without a replica setting
Browse files Browse the repository at this point in the history
  • Loading branch information
joyrex2001 committed Mar 22, 2022
1 parent 9e147d2 commit ed0de7d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/agent/scale.go
Expand Up @@ -120,6 +120,11 @@ func (a *worker) scale(e *event) {
return
}
// regular scaling
if !e.sched.HasReplicas() {
// ignore scalling if no replicas are present, this is probably a
// schedule just containing triggers.
return
}
repl, err := e.sched.GetReplicas()
if err == nil {
err = e.obj.Scale(e.state, repl)
Expand Down
7 changes: 7 additions & 0 deletions internal/schedule/attribute.go
Expand Up @@ -16,6 +16,13 @@ func (s *Schedule) GetReplicas() (int, error) {
return strconv.Atoi(r)
}

// HasReplicas checks if the given schedule has a replicas settings that
// should be applied.
func (s *Schedule) HasReplicas() bool {
_, ok := s.settings["replicas"]
return ok
}

// GetState will return the state that should be applied according to the
// schedule.
func (s *Schedule) GetState() (State, error) {
Expand Down
28 changes: 28 additions & 0 deletions internal/schedule/attribute_test.go
Expand Up @@ -51,6 +51,34 @@ func TestGetReplicas(t *testing.T) {
}
}

func TestHasReplicas(t *testing.T) {
tests := []struct {
res bool
sched *Schedule
}{
{
res: true,
sched: &Schedule{
settings: map[string]string{
"replicas": "1",
},
},
},
{
res: false,
sched: &Schedule{
settings: map[string]string{},
},
},
}
for i, tst := range tests {
r := tst.sched.HasReplicas()
if r != tst.res {
t.Errorf("failed test %d; expected %t , got %t", i, tst.res, r)
}
}
}

func TestGetState(t *testing.T) {
tests := []struct {
state State
Expand Down

0 comments on commit ed0de7d

Please sign in to comment.