Skip to content

Commit

Permalink
update build pods test to reflect startingordinals usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vimystic committed Nov 12, 2024
1 parent 212e049 commit 6c4f498
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/fullnode/build_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func BuildPods(crd *cosmosv1.CosmosFullNode, cksums ConfigChecksums, startingOrd
pods []diff.Resource[*corev1.Pod]
)
candidates := podCandidates(crd)
for i := startingOrdinal; i < crd.Spec.Replicas; i++ {
for i := startingOrdinal; i < crd.Spec.Replicas+startingOrdinal; i++ {
pod, err := builder.WithOrdinal(i).Build()
if err != nil {
return nil, err
Expand Down
40 changes: 22 additions & 18 deletions internal/fullnode/build_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func TestBuildPods(t *testing.T) {
t.Parallel()

t.Run("happy path", func(t *testing.T) {
t.Run("happy path with starting ordinal", func(t *testing.T) {
crd := &cosmosv1.CosmosFullNode{
ObjectMeta: metav1.ObjectMeta{
Name: "agoric",
Expand All @@ -34,36 +34,38 @@ func TestBuildPods(t *testing.T) {
}

cksums := make(ConfigChecksums)
startingOrdinal := int32(2)
for i := 0; i < int(crd.Spec.Replicas); i++ {
cksums[client.ObjectKey{Namespace: crd.Namespace, Name: fmt.Sprintf("agoric-%d", i)}] = strconv.Itoa(i)
cksums[client.ObjectKey{Namespace: crd.Namespace, Name: fmt.Sprintf("agoric-%d", i+int(startingOrdinal))}] = strconv.Itoa(i + int(startingOrdinal))
}

pods, err := BuildPods(crd, cksums, 0)
pods, err := BuildPods(crd, cksums, startingOrdinal)
require.NoError(t, err)
require.Equal(t, 5, len(pods))

for i, r := range pods {
require.Equal(t, int64(i), r.Ordinal(), i)
expectedOrdinal := startingOrdinal + int32(i)
require.Equal(t, int64(expectedOrdinal), r.Ordinal(), i)
require.NotEmpty(t, r.Revision(), i)
require.Equal(t, strconv.Itoa(i), r.Object().Annotations["cosmos.strange.love/config-checksum"])
require.Equal(t, strconv.Itoa(int(expectedOrdinal)), r.Object().Annotations["cosmos.strange.love/config-checksum"])
}

want := lo.Map([]int{0, 1, 2, 3, 4}, func(_ int, i int) string {
want := lo.Map([]int{2, 3, 4, 5, 6}, func(i int, _ int) string {
return fmt.Sprintf("agoric-%d", i)
})
got := lo.Map(pods, func(pod diff.Resource[*corev1.Pod], _ int) string { return pod.Object().Name })
require.Equal(t, want, got)

pod, err := NewPodBuilder(crd).WithOrdinal(0).Build()
pod, err := NewPodBuilder(crd).WithOrdinal(startingOrdinal).Build()
require.NoError(t, err)
require.Equal(t, pod.Spec, pods[0].Object().Spec)
})

t.Run("instance overrides", func(t *testing.T) {
t.Run("instance overrides with starting ordinal", func(t *testing.T) {
const (
image = "agoric:latest"
overrideImage = "some_image:custom"
overridePod = "agoric-5"
overridePod = "agoric-7"
)
crd := &cosmosv1.CosmosFullNode{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -75,18 +77,19 @@ func TestBuildPods(t *testing.T) {
Image: image,
},
InstanceOverrides: map[string]cosmosv1.InstanceOverridesSpec{
"agoric-2": {DisableStrategy: ptr(cosmosv1.DisablePod)},
"agoric-4": {DisableStrategy: ptr(cosmosv1.DisableAll)},
"agoric-4": {DisableStrategy: ptr(cosmosv1.DisablePod)},
"agoric-6": {DisableStrategy: ptr(cosmosv1.DisableAll)},
overridePod: {Image: overrideImage},
},
},
}

pods, err := BuildPods(crd, nil, 0)
startingOrdinal := int32(2)
pods, err := BuildPods(crd, nil, startingOrdinal)
require.NoError(t, err)
require.Equal(t, 4, len(pods))

want := lo.Map([]int{0, 1, 3, 5}, func(i int, _ int) string {
want := lo.Map([]int{2, 3, 5, 7}, func(i int, _ int) string {
return fmt.Sprintf("agoric-%d", i)
})
got := lo.Map(pods, func(pod diff.Resource[*corev1.Pod], _ int) string { return pod.Object().Name })
Expand All @@ -101,7 +104,7 @@ func TestBuildPods(t *testing.T) {
}
})

t.Run("scheduled volume snapshot pod candidate", func(t *testing.T) {
t.Run("scheduled volume snapshot pod candidate with starting ordinal", func(t *testing.T) {
crd := &cosmosv1.CosmosFullNode{
ObjectMeta: metav1.ObjectMeta{
Name: "agoric",
Expand All @@ -111,18 +114,19 @@ func TestBuildPods(t *testing.T) {
},
Status: cosmosv1.FullNodeStatus{
ScheduledSnapshotStatus: map[string]cosmosv1.FullNodeSnapshotStatus{
"some.scheduled.snapshot.1": {PodCandidate: "agoric-1"},
"some.scheduled.snapshot.2": {PodCandidate: "agoric-2"},
"some.scheduled.snapshot.1": {PodCandidate: "agoric-3"},
"some.scheduled.snapshot.2": {PodCandidate: "agoric-4"},
"some.scheduled.snapshot.ignored": {PodCandidate: "agoric-99"},
},
},
}

pods, err := BuildPods(crd, nil, 0)
startingOrdinal := int32(2)
pods, err := BuildPods(crd, nil, startingOrdinal)
require.NoError(t, err)
require.Equal(t, 4, len(pods))

want := lo.Map([]int{0, 3, 4, 5}, func(i int, _ int) string {
want := lo.Map([]int{2, 5, 6, 7}, func(i int, _ int) string {
return fmt.Sprintf("agoric-%d", i)
})
got := lo.Map(pods, func(pod diff.Resource[*corev1.Pod], _ int) string { return pod.Object().Name })
Expand Down

0 comments on commit 6c4f498

Please sign in to comment.