Skip to content

Commit

Permalink
Merge pull request #125 from voelzmo/fix/hpa-metric-spec-conversion
Browse files Browse the repository at this point in the history
Fix HPA MetricSpec conversion
  • Loading branch information
voelzmo authored Aug 8, 2023
2 parents 08b69b9 + 19ca980 commit 2cf9558
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controllers/hpa_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *HvpaReconciler) Convert_v2_HPA_to_v2beta1(in *autoscalingv2.HorizontalP
func (r *HvpaReconciler) Convert_v2beta1_MetricSpec_to_v2(err error, in autoscaling.MetricSpec) (*autoscalingv2.MetricSpec, error) {
out := &autoscalingv2.MetricSpec{}
internalHpaMetricSpec := &kubernetesinternalautoscaling.MetricSpec{}
err = r.Scheme.Convert(in, internalHpaMetricSpec, context.TODO())
err = r.Scheme.Convert(&in, internalHpaMetricSpec, context.TODO())
if err != nil {
return nil, err
}
Expand Down
19 changes: 19 additions & 0 deletions controllers/hvpa_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"k8s.io/utils/pointer"
"time"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -191,6 +192,24 @@ var _ = Describe("#TestReconcile", func() {
return fmt.Errorf("Error: Expected 1 HPA; found %v", len(hpaList.Items))
}, timeout).Should(Succeed())

// Update the HPA spec and expect the change to be reconciled
hvpa := &autoscalingv1alpha1.Hvpa{}
c.Get(context.TODO(), types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, hvpa)
hvpa.Spec.Hpa.Template.Spec.MinReplicas = pointer.Int32(3)
err = c.Update(context.TODO(), hvpa)
Expect(err).NotTo(HaveOccurred())
Eventually(func() error {
var actualMinReplicas int32
c.List(context.TODO(), hpaList)
for _, hpa := range hpaList.Items {
actualMinReplicas = *hpa.Spec.MinReplicas
}
if actualMinReplicas != 3 {
return fmt.Errorf("Expected minReplicas 3, got %v", actualMinReplicas)
}
return nil
}, timeout).Should(Succeed())

// Create a pod for the target deployment, and update status to "OOMKilled".
// The field hvpa.status.overrideScaleUpStabilization should be set to true.
p := v1.Pod{
Expand Down

0 comments on commit 2cf9558

Please sign in to comment.