Fix incorrect DESIRED on `kubectl get hra (#353)
`kubectl get horizontalrunnerautoscalers.actions.summerwind.dev` shows HRA.status.desiredReplicas as the DESIRED count. However the value had been not taking capacityReservations into account, which resulted in showing incorrect count when you used webhook-based autoscaler, or capacityReservations API directly. This fixes that.
This commit is contained in:
parent
9890a90e69
commit
598dd1d9fe
|
|
@ -132,16 +132,16 @@ func (r *HorizontalRunnerAutoscalerReconciler) Reconcile(req ctrl.Request) (ctrl
|
||||||
|
|
||||||
var updated *v1alpha1.HorizontalRunnerAutoscaler
|
var updated *v1alpha1.HorizontalRunnerAutoscaler
|
||||||
|
|
||||||
if hra.Status.DesiredReplicas == nil || *hra.Status.DesiredReplicas != *replicas {
|
if hra.Status.DesiredReplicas == nil || *hra.Status.DesiredReplicas != newDesiredReplicas {
|
||||||
updated = hra.DeepCopy()
|
updated = hra.DeepCopy()
|
||||||
|
|
||||||
if (hra.Status.DesiredReplicas == nil && *replicas > 1) ||
|
if (hra.Status.DesiredReplicas == nil && newDesiredReplicas > 1) ||
|
||||||
(hra.Status.DesiredReplicas != nil && *replicas > *hra.Status.DesiredReplicas) {
|
(hra.Status.DesiredReplicas != nil && newDesiredReplicas > *hra.Status.DesiredReplicas) {
|
||||||
|
|
||||||
updated.Status.LastSuccessfulScaleOutTime = &metav1.Time{Time: time.Now()}
|
updated.Status.LastSuccessfulScaleOutTime = &metav1.Time{Time: time.Now()}
|
||||||
}
|
}
|
||||||
|
|
||||||
updated.Status.DesiredReplicas = replicas
|
updated.Status.DesiredReplicas = &newDesiredReplicas
|
||||||
}
|
}
|
||||||
|
|
||||||
if replicasFromCache == nil {
|
if replicasFromCache == nil {
|
||||||
|
|
|
||||||
|
|
@ -484,6 +484,7 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
||||||
Expect(err).NotTo(HaveOccurred(), "failed to get test HorizontalRunnerAutoscaler resource")
|
Expect(err).NotTo(HaveOccurred(), "failed to get test HorizontalRunnerAutoscaler resource")
|
||||||
|
|
||||||
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 1, "runners after HRA force update for scale-down")
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 1, "runners after HRA force update for scale-down")
|
||||||
|
ExpectHRADesiredReplicasEquals(ctx, ns.Name, name, 1, "runner deployment desired replicas")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale-up to 2 replicas on first pull_request create webhook event
|
// Scale-up to 2 replicas on first pull_request create webhook event
|
||||||
|
|
@ -491,12 +492,14 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
||||||
env.SendUserPullRequestEvent("test", "valid", "main", "created")
|
env.SendUserPullRequestEvent("test", "valid", "main", "created")
|
||||||
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1, "runner sets after webhook")
|
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1, "runner sets after webhook")
|
||||||
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2, "runners after first webhook event")
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2, "runners after first webhook event")
|
||||||
|
ExpectHRADesiredReplicasEquals(ctx, ns.Name, name, 2, "runner deployment desired replicas")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale-up to 3 replicas on second pull_request create webhook event
|
// Scale-up to 3 replicas on second pull_request create webhook event
|
||||||
{
|
{
|
||||||
env.SendUserPullRequestEvent("test", "valid", "main", "created")
|
env.SendUserPullRequestEvent("test", "valid", "main", "created")
|
||||||
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3, "runners after second webhook event")
|
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3, "runners after second webhook event")
|
||||||
|
ExpectHRADesiredReplicasEquals(ctx, ns.Name, name, 3, "runner deployment desired replicas")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -598,6 +601,18 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
func ExpectHRADesiredReplicasEquals(ctx context.Context, ns, name string, desired int, optionalDescriptions ...interface{}) {
|
||||||
|
var rd actionsv1alpha1.HorizontalRunnerAutoscaler
|
||||||
|
|
||||||
|
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: name}, &rd)
|
||||||
|
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "failed to get test HRA resource")
|
||||||
|
|
||||||
|
replicas := rd.Status.DesiredReplicas
|
||||||
|
|
||||||
|
ExpectWithOffset(1, *replicas).To(Equal(desired), optionalDescriptions...)
|
||||||
|
}
|
||||||
|
|
||||||
func (env *testEnvironment) ExpectRegisteredNumberCountEventuallyEquals(want int, optionalDescriptions ...interface{}) {
|
func (env *testEnvironment) ExpectRegisteredNumberCountEventuallyEquals(want int, optionalDescriptions ...interface{}) {
|
||||||
EventuallyWithOffset(
|
EventuallyWithOffset(
|
||||||
1,
|
1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue