From 2de3a4c2e08ad76d8939357456588259f088c752 Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com> Date: Mon, 2 Mar 2020 17:13:02 +0100 Subject: [PATCH] check presence of scaleTargetRef or jobTargetRef (#648) --- .../scaledobject/scaledobject_controller.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/controller/scaledobject/scaledobject_controller.go b/pkg/controller/scaledobject/scaledobject_controller.go index 4d78e78084e..44489c086c3 100644 --- a/pkg/controller/scaledobject/scaledobject_controller.go +++ b/pkg/controller/scaledobject/scaledobject_controller.go @@ -148,13 +148,25 @@ func (r *ReconcileScaledObject) Reconcile(request reconcile.Request) (reconcile. } reqLogger.V(1).Info("Detecting ScaleType from ScaledObject") - if scaledObject.Spec.ScaleTargetRef == nil || scaledObject.Spec.ScaleTargetRef.DeploymentName == "" { + var errMsg string + if scaledObject.Spec.ScaleTargetRef != nil { + if scaledObject.Spec.JobTargetRef == nil { + reqLogger.Info("Detected ScaleType = Deployment") + return r.reconcileDeploymentType(reqLogger, scaledObject) + } + errMsg = "Both ScaledObject.Spec.ScaleTargetRef and ScaledObject.Spec.JobTargetRef cannot be set at the same time" + } else if scaledObject.Spec.JobTargetRef != nil { reqLogger.Info("Detected ScaleType = Job") return r.reconcileJobType(reqLogger, scaledObject) } else { - reqLogger.Info("Detected ScaleType = Deployment") - return r.reconcileDeploymentType(reqLogger, scaledObject) + errMsg = "ScaledObject.Spec.ScaleTargetRef or ScaledObject.Spec.JobTargetRef is not set" + } + if errMsg == "" { + errMsg = "Unknown error while detecting ScaleType" } + err = fmt.Errorf(errMsg) + reqLogger.Error(err, "Failed to detect ScaleType") + return reconcile.Result{}, err } // reconcileJobType implemets reconciler logic for K8s Jobs based ScaleObject