Skip to content

Commit

Permalink
update unit test for capi scale from zero
Browse files Browse the repository at this point in the history
adding a few more cases and details to the scale from zero unit tests,
including ensuring that the int based annotations do not accept other
unit types.
  • Loading branch information
elmiko committed Jul 18, 2022
1 parent b2578c7 commit d3edc45
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
},
nodegroupLabels: map[string]string{
"nodeGroupLabel": "value",
"anotherLabel": "anotherValue",
"anotherLabel": "nodeGroupValue",
},
expectedCapacity: map[corev1.ResourceName]int64{
corev1.ResourceCPU: 2,
Expand All @@ -1380,7 +1380,7 @@ func TestNodeGroupTemplateNodeInfo(t *testing.T) {
"kubernetes.io/arch": "arm64",
"beta.kubernetes.io/arch": "amd64",
"nodeGroupLabel": "value",
"anotherLabel": "anotherValue",
"anotherLabel": "nodeGroupValue",
"node.kubernetes.io/instance-type": "instance1",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,10 @@ func TestAnnotations(t *testing.T) {
maxPodsKey: maxPodsQuantity.String(),
}

test := func(t *testing.T, testConfig *testConfig) {
test := func(t *testing.T, testConfig *testConfig, testResource *unstructured.Unstructured) {
controller, stop := mustCreateTestController(t, testConfig)
defer stop()

testResource := testConfig.machineSet

sr, err := newUnstructuredScalableResource(controller, testResource)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -330,7 +328,13 @@ func TestAnnotations(t *testing.T) {
}

t.Run("MachineSet", func(t *testing.T) {
test(t, createMachineSetTestConfig(RandomString(6), RandomString(6), RandomString(6), 1, annotations, nil))
testConfig := createMachineSetTestConfig(RandomString(6), RandomString(6), RandomString(6), 1, annotations, nil)
test(t, testConfig, testConfig.machineSet)
})

t.Run("MachineDeployment", func(t *testing.T) {
testConfig := createMachineDeploymentTestConfig(RandomString(6), RandomString(6), RandomString(6), 1, annotations, nil)
test(t, testConfig, testConfig.machineDeployment)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func parseMemoryCapacity(annotations map[string]string) (resource.Quantity, erro
}

func parseGPUCount(annotations map[string]string) (resource.Quantity, error) {
return parseKey(annotations, gpuCountKey)
return parseIntKey(annotations, gpuCountKey)
}

// The GPU type is not currently considered by the autoscaler when planning
Expand All @@ -223,7 +223,7 @@ func parseGPUType(annotations map[string]string) string {
}

func parseMaxPodsCapacity(annotations map[string]string) (resource.Quantity, error) {
return parseKey(annotations, maxPodsKey)
return parseIntKey(annotations, maxPodsKey)
}

func clusterNameFromResource(r *unstructured.Unstructured) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ func TestParseGPUCapacity(t *testing.T) {
annotations: map[string]string{gpuCountKey: "13"},
expectedError: false,
expectedQuantity: resource.MustParse("13"),
}, {
description: "valid quantity, bad unit type",
annotations: map[string]string{gpuCountKey: "13Mi"},
expectedQuantity: zeroQuantity.DeepCopy(),
expectedError: true,
}} {
t.Run(tc.description, func(t *testing.T) {
got, err := parseGPUCount(tc.annotations)
Expand Down Expand Up @@ -631,6 +636,11 @@ func TestParseMaxPodsCapacity(t *testing.T) {
annotations: map[string]string{maxPodsKey: "13"},
expectedError: false,
expectedQuantity: resource.MustParse("13"),
}, {
description: "valid quantity, bad unit type",
annotations: map[string]string{maxPodsKey: "13Mi"},
expectedQuantity: zeroQuantity.DeepCopy(),
expectedError: true,
}} {
t.Run(tc.description, func(t *testing.T) {
got, err := parseMaxPodsCapacity(tc.annotations)
Expand Down

0 comments on commit d3edc45

Please sign in to comment.