Skip to content

Commit

Permalink
rename a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekgogia committed Nov 23, 2020
1 parent b277a7e commit 7cc4cb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/horizontalautoscaler/v1alpha1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Examples", func() {
It("should scale to average utilization target, metric=85, target=60, replicas=5, want=8", func() {
Expect(ns.ParseResources("docs/examples/reserved-capacity-utilization.yaml", ha, sng)).To(Succeed())
sng.Spec.Replicas = ptr.Int32(5)
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = ptr.Int32(*sng.Spec.Replicas)
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = ptr.Int32(*sng.Spec.Replicas) // create a new pointer to avoid races with the controller
MockMetricValue(fakeServer, .85)

ExpectCreated(ns.Client, sng, ha)
Expand All @@ -105,7 +105,7 @@ var _ = Describe("Examples", func() {
It("should scale to average value target, metric=41, target=4, want=11", func() {
Expect(ns.ParseResources("docs/examples/queue-length-average-value.yaml", ha, sng)).To(Succeed())
sng.Spec.Replicas = ptr.Int32(1)
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = ptr.Int32(*sng.Spec.Replicas)
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = ptr.Int32(*sng.Spec.Replicas) // create a new pointer to avoid races with the controller
MockMetricValue(fakeServer, 41)

ExpectCreated(ns.Client, sng, ha)
Expand Down
20 changes: 11 additions & 9 deletions pkg/controllers/scalablenodegroup/v1alpha1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ var _ = AfterSuite(func() {

var _ = Describe("Examples", func() {
var ns *environment.Namespace
var desiredReplicas = ptr.Int32(5)
var dummyMessage = "test message"
var defaultReplicaCount = ptr.Int32(3)

var sng *v1alpha1.ScalableNodeGroup

BeforeEach(func() {
Expand All @@ -66,7 +66,7 @@ var _ = Describe("Examples", func() {
fakeCloudProvider.NodeGroupStable = true
fakeCloudProvider.NodeGroupMessage = ""
fakeCloudProvider.WantErr = nil
sng.Spec.Replicas = desiredReplicas
sng.Spec.Replicas = defaultReplicaCount
sng.Spec.ID = "dummyID"
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = ptr.Int32(0)
})
Expand All @@ -84,38 +84,40 @@ var _ = Describe("Examples", func() {
Context("ScalableNodeGroup Reconcile tests", func() {
It("Test reconciler to scale up nodes", func() {
Expect(fakeController.Reconcile(sng)).To(Succeed())
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(desiredReplicas))
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(defaultReplicaCount))
})

It("Test reconciler to scale down nodes", func() {
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = ptr.Int32(10) // set existing replicas higher than desired
Expect(fakeController.Reconcile(sng)).To(Succeed())
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(desiredReplicas))
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(defaultReplicaCount))
})

It("Test reconciler to make no change to node count", func() {
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = desiredReplicas // set existing replicas equal to desired
fakeCloudProvider.NodeReplicas[sng.Spec.ID] = defaultReplicaCount // set existing replicas equal to desired
Expect(fakeController.Reconcile(sng)).To(Succeed())
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(desiredReplicas))
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(defaultReplicaCount))
})

It("Scale up nodes when not node group is stabilized and check status condition", func() {
Expect(fakeController.Reconcile(sng)).To(Succeed())
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(desiredReplicas))
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(defaultReplicaCount))
Expect(sng.StatusConditions().GetCondition(v1alpha1.Stabilized).IsTrue()).To(Equal(true))
Expect(sng.StatusConditions().GetCondition(v1alpha1.Stabilized).Message).To(Equal(""))
})

It("Scale up nodes when not node group is NOT stabilized and check status condition", func() {
var dummyMessage = "test message"
fakeCloudProvider.NodeGroupStable = false
fakeCloudProvider.NodeGroupMessage = dummyMessage
Expect(fakeController.Reconcile(sng)).To(Succeed())
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(desiredReplicas))
Expect(fakeCloudProvider.NodeReplicas[sng.Spec.ID]).To(Equal(defaultReplicaCount))
Expect(sng.StatusConditions().GetCondition(v1alpha1.Stabilized).IsFalse()).To(Equal(true))
Expect(sng.StatusConditions().GetCondition(v1alpha1.Stabilized).Message).To(Equal(dummyMessage))
})

It("Retryable error while reconciling", func() {
var dummyMessage = "test message"
fakeCloudProvider.WantErr = fake.RetryableError(fmt.Errorf(dummyMessage)) // retryable error
existingReplicas := fakeCloudProvider.NodeReplicas[sng.Spec.ID]
Expect(fakeController.Reconcile(sng)).To(Succeed())
Expand Down

0 comments on commit 7cc4cb8

Please sign in to comment.