Skip to content

Commit f6f538a

Browse files
authored
feat: add a helper to know automation reached goal state (#120)
1 parent 727adbf commit f6f538a

File tree

7 files changed

+94
-5
lines changed

7 files changed

+94
-5
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ lint: ## Run linter
3636
.PHONY: check
3737
check: test lint ## Run tests and linters
3838

39-
.PHONY: addcopy
40-
addcopy:
39+
.PHONY: addlicense
40+
addlicense:
4141
find . -name '*.go' | while read -r file; do addlicense -c "MongoDB Inc" "$$file"; done
4242

4343
.PHONY: list

atmcfg/atmcfg.go

+9
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,12 @@ func reclaimByShardNameAndProcesses(out *opsmngr.AutomationConfig, processesMap
642642
// compact doesn't run on mongoses
643643
}
644644
}
645+
646+
func IsGoalState(s *opsmngr.AutomationStatus) bool {
647+
for _, p := range s.Processes {
648+
if p.LastGoalVersionAchieved != s.GoalVersion {
649+
return false
650+
}
651+
}
652+
return true
653+
}

atmcfg/atmcfg_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -753,3 +753,52 @@ func isLastCompactEmpty(t *testing.T, process *opsmngr.Process, hostname string,
753753
t.Errorf("ReclaimFreeSpace\n got=%#v", process.LastRestart)
754754
}
755755
}
756+
757+
func TestIsGoalState(t *testing.T) {
758+
tests := []struct {
759+
name string
760+
s *opsmngr.AutomationStatus
761+
want bool
762+
}{
763+
{
764+
name: "reached goal",
765+
s: &opsmngr.AutomationStatus{
766+
Processes: []opsmngr.ProcessStatus{
767+
{
768+
LastGoalVersionAchieved: 0,
769+
Name: "test",
770+
Hostname: "test",
771+
},
772+
},
773+
GoalVersion: 0,
774+
},
775+
want: true,
776+
},
777+
{
778+
name: "pending goal",
779+
s: &opsmngr.AutomationStatus{
780+
Processes: []opsmngr.ProcessStatus{
781+
{
782+
LastGoalVersionAchieved: 0,
783+
Name: "test",
784+
Hostname: "test",
785+
},
786+
},
787+
GoalVersion: 1,
788+
},
789+
want: false,
790+
},
791+
{
792+
name: "empty",
793+
s: &opsmngr.AutomationStatus{},
794+
want: true,
795+
},
796+
}
797+
for _, tt := range tests {
798+
t.Run(tt.name, func(t *testing.T) {
799+
if got := IsGoalState(tt.s); got != tt.want {
800+
t.Errorf("IsGoalState() = %v, want %v", got, tt.want)
801+
}
802+
})
803+
}
804+
}

atmcfg/fixtures.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2021 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package atmcfg
216

317
import "go.mongodb.org/ops-manager/opsmngr"

go.sum

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ go.mongodb.org/atlas v0.11.1-0.20210811161401-47f8a8c02572/go.mod h1:MMWDsc2akjT
2727
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
2828
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
2929
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
30-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
3130
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
3231
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3332
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=

opsmngr/automation_status.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ type AutomationStatus struct {
5757
}
5858

5959
type ProcessStatus struct {
60-
Plan []string `json:"plan"`
60+
ErrorCode *int `json:"errorCode,omitempty"`
61+
ErrorCodeDescription *string `json:"errorCodeDescription,omitempty"`
62+
ErrorCodeHumanReadable *string `json:"errorCodeHumanReadable,omitempty"`
63+
ErrorString *string `json:"errorString,omitempty"`
64+
Hostname string `json:"hostname"`
6165
LastGoalVersionAchieved int `json:"lastGoalVersionAchieved"`
6266
Name string `json:"name"`
63-
Hostname string `json:"hostname"`
67+
Plan []string `json:"plan"`
6468
}

opsmngr/organization_invitations.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2021 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package opsmngr
216

317
import (

0 commit comments

Comments
 (0)