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

add deploymentName label if needed #709

Merged
merged 1 commit into from
Mar 30, 2020
Merged
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
23 changes: 23 additions & 0 deletions pkg/controller/scaledobject/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ func (r *ReconcileScaledObject) reconcileDeploymentType(logger logr.Logger, scal
return reconcile.Result{}, err
}

// add deploymentName label if needed
err = r.checkScaledObjectLabel(logger, scaledObject)
if err != nil {
logger.Error(err, "Failed to update ScaledObject with deploymentName label")
return reconcile.Result{}, err
}

hpaName := getHpaName(deploymentName)
hpaNamespace := scaledObject.Namespace

Expand Down Expand Up @@ -300,6 +307,22 @@ func checkDeploymentTypeScaledObject(scaledObject *kedav1alpha1.ScaledObject) (s
return deploymentName, err
}

func (r *ReconcileScaledObject) checkScaledObjectLabel(logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) error {

if scaledObject.Labels == nil {
scaledObject.Labels = map[string]string{"deploymentName": scaledObject.Spec.ScaleTargetRef.DeploymentName}
} else {
value, found := scaledObject.Labels["deploymentName"]
if found && value == scaledObject.Spec.ScaleTargetRef.DeploymentName {
return nil
}
scaledObject.Labels["deploymentName"] = scaledObject.Spec.ScaleTargetRef.DeploymentName
}

logger.V(1).Info("Adding deploymentName label on ScaledObject")
return r.client.Update(context.TODO(), scaledObject)
}

// startScaleLoop starts ScaleLoop handler for the respective ScaledObject
func (r *ReconcileScaledObject) startScaleLoop(logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) error {

Expand Down