Skip to content

Commit c779d4d

Browse files
committed
Adjust test suite to check MachineDeploymentName
Previously we were comparing instanceType.Name to machineDeployment.Name, but with the change to machineDeploymentToInstanceType where we are setting the instanceType name to the instanceTyple label, those fields no longer line up, so we need to adjust the test suite to check against the field where we actually stuff that value (instanceType.MachineDeploymentName). We probably need an additional test to test the label behavior. Signed-off-by: John Kyros <[email protected]>
1 parent c5b5b78 commit c779d4d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pkg/cloudprovider/cloudprovider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ func machineDeploymentToInstanceType(machineDeployment *capiv1beta1.MachineDeplo
606606
// For now, we check the labels we know about from the MachineDeployment, if the instance type label
607607
// is not there, leave it blank.
608608
// to the v1.LabelInstanceTypeStable. if karpenter expects this to match the node, then we need to get this value through capi.
609+
// TODO (jkyros) Add a test case to test this behavior
609610
instanceType.Name = labels[corev1.LabelInstanceTypeStable]
610611

611612
// TODO (elmiko) add the proper overhead information, not sure where we will harvest this information.

pkg/cloudprovider/cloudprovider_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
349349
Expect(instanceType.Capacity).Should(HaveKeyWithValue(corev1.ResourceCPU, resource.MustParse("1")))
350350
Expect(instanceType.Capacity).Should(HaveKeyWithValue(corev1.ResourceMemory, resource.MustParse("16Gi")))
351351
Expect(instanceType.Capacity).Should(HaveKeyWithValue(corev1.ResourceName("nvidia.com/gpu"), resource.MustParse("1")))
352-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
352+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
353353
})
354354

355355
It("adds nothing to requirements when no managed labels or scale from zero annotations are present", func() {
@@ -358,7 +358,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
358358
instanceType := machineDeploymentToInstanceType(machineDeployment)
359359

360360
Expect(instanceType.Requirements).To(HaveLen(0))
361-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
361+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
362362
})
363363

364364
It("adds labels to the requirements from the Cluster API propagation rules", func() {
@@ -381,7 +381,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
381381
Expect(instanceType.Requirements).Should(HaveKey("prefixed.node-restriction.kubernetes.io/some-other-thing"))
382382
Expect(instanceType.Requirements).Should(HaveKey("node.cluster.x-k8s.io/another-thing"))
383383
Expect(instanceType.Requirements).Should(HaveKey("prefixed.node.cluster.x-k8s.io/another-thing"))
384-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
384+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
385385
})
386386

387387
It("adds labels to the requirements from the scale from zero annotations", func() {
@@ -395,7 +395,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
395395
Expect(instanceType.Requirements).To(HaveLen(2))
396396
Expect(instanceType.Requirements).Should(HaveKey(corev1.LabelTopologyZone))
397397
Expect(instanceType.Requirements).Should(HaveKey(InstanceSizeLabelKey))
398-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
398+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
399399
})
400400

401401
It("adds labels to the requirements from the propagation rules and the scale from zero annotations", func() {
@@ -424,7 +424,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
424424
Expect(instanceType.Requirements).Should(HaveKey("prefixed.node-restriction.kubernetes.io/some-other-thing"))
425425
Expect(instanceType.Requirements).Should(HaveKey("node.cluster.x-k8s.io/another-thing"))
426426
Expect(instanceType.Requirements).Should(HaveKey("prefixed.node.cluster.x-k8s.io/another-thing"))
427-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
427+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
428428
})
429429

430430
It("adds a single available on-demand offering with price 0 and empty zone", func() {
@@ -438,7 +438,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
438438
Expect(offering.Requirements[karpv1.CapacityTypeLabelKey].Values()).Should(ContainElement(karpv1.CapacityTypeOnDemand))
439439
Expect(offering.Requirements).Should(HaveKey(corev1.LabelTopologyZone))
440440
Expect(offering.Requirements[corev1.LabelTopologyZone].Values()).Should(ContainElement(""))
441-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
441+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
442442
})
443443

444444
It("adds the correct zone to offering when the well known zone label is present", func() {
@@ -453,7 +453,7 @@ var _ = Describe("machineDeploymentToInstanceType function", func() {
453453
offering := instanceType.Offerings[0]
454454
Expect(offering.Requirements).Should(HaveKey(corev1.LabelTopologyZone))
455455
Expect(offering.Requirements[corev1.LabelTopologyZone].Values()).Should(ContainElement(zone))
456-
Expect(instanceType.Name).To(Equal(machineDeployment.Name))
456+
Expect(instanceType.MachineDeploymentName).To(Equal(machineDeployment.Name))
457457
})
458458
})
459459

0 commit comments

Comments
 (0)