This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding this to name, since it's an arbitrary number
- Loading branch information
Mario Manno
committed
Oct 7, 2020
1 parent
e6823da
commit b8f6a7e
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
}) | ||
|
||
}) |