Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HPA MetricSpec conversion #125

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
voelzmo marked this conversation as resolved.
Show resolved Hide resolved
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