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

Commit

Permalink
Returns the spec index number
Browse files Browse the repository at this point in the history
Adding this to name, since it's an arbitrary number
  • Loading branch information
Mario Manno committed Oct 7, 2020
1 parent e6823da commit b8f6a7e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
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))
}
})

})

0 comments on commit b8f6a7e

Please sign in to comment.