From 5256fb16bd3eedcd20a7d044bef49cb073a757e7 Mon Sep 17 00:00:00 2001 From: Shane Date: Sat, 7 Dec 2024 23:29:48 +0800 Subject: [PATCH] revise fallback with cpu/memory validation Signed-off-by: Shane --- apis/keda/v1alpha1/scaledobject_types.go | 5 ++++- apis/keda/v1alpha1/scaledobject_webhook_test.go | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apis/keda/v1alpha1/scaledobject_types.go b/apis/keda/v1alpha1/scaledobject_types.go index 216a93b6f9a..63fa48ea42c 100644 --- a/apis/keda/v1alpha1/scaledobject_types.go +++ b/apis/keda/v1alpha1/scaledobject_types.go @@ -23,8 +23,11 @@ import ( autoscalingv2 "k8s.io/api/autoscaling/v2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + logf "sigs.k8s.io/controller-runtime/pkg/log" ) +var scaledobjecttypeslog = logf.Log.WithName("scaledobject-types") + // +genclient // +kubebuilder:object:root=true // +kubebuilder:subresource:status @@ -288,7 +291,7 @@ func CheckFallbackValid(scaledObject *ScaledObject) error { for _, trigger := range scaledObject.Spec.Triggers { if trigger.Type == cpuString || trigger.Type == memoryString { - return fmt.Errorf("type is %s , but fallback it is not supported by the CPU & memory scalers", trigger.Type) + scaledobjecttypeslog.Error(nil, fmt.Sprintf("type is %s , but fallback it is not supported by the CPU & memory scalers", trigger.Type)) } if trigger.MetricType != autoscalingv2.AverageValueMetricType { return fmt.Errorf("MetricType=%s, but fallback can only be enabled for triggers with metric of type AverageValue", trigger.MetricType) diff --git a/apis/keda/v1alpha1/scaledobject_webhook_test.go b/apis/keda/v1alpha1/scaledobject_webhook_test.go index e30404d16c4..08970b121ac 100644 --- a/apis/keda/v1alpha1/scaledobject_webhook_test.go +++ b/apis/keda/v1alpha1/scaledobject_webhook_test.go @@ -176,7 +176,7 @@ var _ = It("shouldn't validate the so creation when the fallback is wrong", func }).Should(HaveOccurred()) }) -var _ = It("shouldn't validate the so creation When the fallback are configured and the scaler is either CPU or memory.", func() { +var _ = It("should validate the so creation When the fallback are configured and the scaler is either CPU or memory.", func() { namespaceName := "wrong-fallback-cpu-memory" namespace := createNamespace(namespaceName) workload := createDeployment(namespaceName, true, true) @@ -193,7 +193,7 @@ var _ = It("shouldn't validate the so creation When the fallback are configured Eventually(func() error { return k8sClient.Create(context.Background(), so) - }).Should(HaveOccurred()) + }).ShouldNot(HaveOccurred()) }) var _ = It("shouldn't validate the so creation when there is another unmanaged hpa and so has transfer-hpa-ownership activated", func() {