Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Returns the spec index number #96

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/names/spec_index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package names

// SpecIndex return the job sepc index.
// We use a very large value as a maximum number of replicas per instance group, per AZ
// We do this in lieu of using the actual replica count, which would cause pods to always restart
func SpecIndex(azIndex int, podOrdinal int) int {
if azIndex < 1 {
azIndex = 1
}

return (azIndex-1)*10000 + podOrdinal
}
32 changes: 32 additions & 0 deletions pkg/names/spec_index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package names_test

import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"code.cloudfoundry.org/quarks-utils/pkg/names"
)

var _ = Describe("SpecIndex", func() {
tests := []struct {
az int
ord int
r int
}{
{az: 0, ord: 0, r: 0},
{az: 1, ord: 5, r: 5},
{az: 2, ord: 5, r: 10005},
{az: 3, ord: 5, r: 20005},
{az: -1, ord: 0, r: 0},
}

It("produces valid spec indexes", func() {
for _, t := range tests {
r := names.SpecIndex(t.az, t.ord)
Expect(r).To(Equal(t.r), fmt.Sprintf("%#v", t))
}
})

})