diff --git a/CHANGELOG.md b/CHANGELOG.md index 8660a1b2123..1dc8c0f7418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Here is an overview of all new **experimental** features: - **General**: Centralize and improve automaxprocs configuration with proper structured logging ([#5970](https://github.com/kedacore/keda/issues/5970)) - **General**: Paused ScaledObject count is reported correctly after operator restart ([#6321](https://github.com/kedacore/keda/issues/6321)) +- **General**: Revise some annotations above function and fix fallback check bug ([#6346](https://github.com/kedacore/keda/pull/6346)) - **General**: ScaledJobs ready status set to true when recoverred problem ([#6329](https://github.com/kedacore/keda/pull/6329)) ### Deprecations diff --git a/apis/keda/v1alpha1/scaledobject_types.go b/apis/keda/v1alpha1/scaledobject_types.go index 37c5e640963..74a0cc030d1 100644 --- a/apis/keda/v1alpha1/scaledobject_types.go +++ b/apis/keda/v1alpha1/scaledobject_types.go @@ -21,10 +21,21 @@ import ( "reflect" "strconv" + eventingv1alpha1 "github.com/kedacore/keda/v2/apis/eventing/v1alpha1" + "github.com/kedacore/keda/v2/pkg/common/message" + "github.com/kedacore/keda/v2/pkg/eventemitter" + "github.com/kedacore/keda/v2/pkg/eventreason" + autoscalingv2 "k8s.io/api/autoscaling/v2" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + logf "sigs.k8s.io/controller-runtime/pkg/log" ) +var scaledobjecttypeslog = logf.Log.WithName("scaledobject-types") + +var EventEmitter eventemitter.EventHandler + // +genclient // +kubebuilder:object:root=true // +kubebuilder:subresource:status @@ -237,7 +248,7 @@ func (so *ScaledObject) IsUsingModifiers() bool { return so.Spec.Advanced != nil && !reflect.DeepEqual(so.Spec.Advanced.ScalingModifiers, ScalingModifiers{}) } -// getHPAMinReplicas returns MinReplicas based on definition in ScaledObject or default value if not defined +// GetHPAMinReplicas returns MinReplicas based on definition in ScaledObject or default value if not defined func (so *ScaledObject) GetHPAMinReplicas() *int32 { if so.Spec.MinReplicaCount != nil && *so.Spec.MinReplicaCount > 0 { return so.Spec.MinReplicaCount @@ -246,7 +257,7 @@ func (so *ScaledObject) GetHPAMinReplicas() *int32 { return &tmp } -// getHPAMaxReplicas returns MaxReplicas based on definition in ScaledObject or default value if not defined +// GetHPAMaxReplicas returns MaxReplicas based on definition in ScaledObject or default value if not defined func (so *ScaledObject) GetHPAMaxReplicas() int32 { if so.Spec.MaxReplicaCount != nil { return *so.Spec.MaxReplicaCount @@ -254,7 +265,7 @@ func (so *ScaledObject) GetHPAMaxReplicas() int32 { return defaultHPAMaxReplicas } -// checkReplicaCountBoundsAreValid checks that Idle/Min/Max ReplicaCount defined in ScaledObject are correctly specified +// CheckReplicaCountBoundsAreValid checks that Idle/Min/Max ReplicaCount defined in ScaledObject are correctly specified // i.e. that Min is not greater than Max or Idle greater or equal to Min func CheckReplicaCountBoundsAreValid(scaledObject *ScaledObject) error { min := int32(0) @@ -288,10 +299,11 @@ 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)) + EventEmitter.Emit(scaledObject, scaledObject.Namespace, corev1.EventTypeWarning, eventingv1alpha1.ScaledObjectFailedType, eventreason.ScaledObjectCheckFailed, message.ScaledObjectMayNotBehaveAsExpectationMsg) } 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) + return fmt.Errorf("MetricType=%s, but fallback can only be enabled for triggers with metric of type AverageValue", trigger.MetricType) } } return nil diff --git a/apis/keda/v1alpha1/scaledobject_webhook.go b/apis/keda/v1alpha1/scaledobject_webhook.go index 41bd0355596..4b7e0cb60e3 100644 --- a/apis/keda/v1alpha1/scaledobject_webhook.go +++ b/apis/keda/v1alpha1/scaledobject_webhook.go @@ -193,7 +193,7 @@ func verifyFallback(incomingSo *ScaledObject, action string, _ bool) error { scaledobjectlog.WithValues("name", incomingSo.Name).Error(err, "validation error") metricscollector.RecordScaledObjectValidatingErrors(incomingSo.Namespace, action, "incorrect-fallback") } - return nil + return err } func verifyTriggers(incomingObject interface{}, action string, _ bool) error { 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() { diff --git a/pkg/common/message/message.go b/pkg/common/message/message.go index 4abcc0402ff..388e032d75e 100644 --- a/pkg/common/message/message.go +++ b/pkg/common/message/message.go @@ -42,4 +42,6 @@ const ( ClusterTriggerAuthenticationCreatedMsg = "New ClusterTriggerAuthentication configured" ClusterTriggerAuthenticationUpdatedMsg = "ClusterTriggerAuthentication %s is updated" + + ScaledObjectMayNotBehaveAsExpectationMsg = "ScaledObject may not behave as expectation" )