Skip to content

Commit

Permalink
Use scaled[object/job].keda.sh/ prefix for KEDA related labels (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
zroubalik authored Aug 6, 2021
1 parent a3b7c3b commit 31e980e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

### Other

- TODO ([#XXX](https://github.com/kedacore/keda/pull/XXX))
- Use `scaled[object/job].keda.sh/` prefix for KEDA related labels ([#2008](https://github.com/kedacore/keda/pull/2008))

## v2.3.0

Expand Down
4 changes: 2 additions & 2 deletions controllers/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(logger logr.Logger,
return nil, fmt.Errorf("metricName %s defined multiple times in ScaledObject %s, please refer the documentation how to define metricName manually", externalMetricName, scaledObject.Name)
}

// add the scaledObjectName label. This is how the MetricsAdapter will know which scaledobject a metric is for when the HPA queries it.
// add the scaledobject.keda.sh/name label. This is how the MetricsAdapter will know which scaledobject a metric is for when the HPA queries it.
metricSpec.External.Metric.Selector = &metav1.LabelSelector{MatchLabels: make(map[string]string)}
metricSpec.External.Metric.Selector.MatchLabels["scaledObjectName"] = scaledObject.Name
metricSpec.External.Metric.Selector.MatchLabels["scaledobject.keda.sh/name"] = scaledObject.Name
externalMetricNames = append(externalMetricNames, externalMetricName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/scaledjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob *
func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) {
opts := []client.ListOption{
client.InNamespace(scaledJob.GetNamespace()),
client.MatchingLabels(map[string]string{"scaledJob": scaledJob.GetName()}),
client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}),
}
jobs := &batchv1.JobList{}
err := r.Client.List(context.TODO(), jobs, opts...)
Expand Down
6 changes: 3 additions & 3 deletions controllers/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(logger logr.Logger, scale
return "ScaledObject is defined correctly and is ready for scaling", nil
}

// ensureScaledObjectLabel ensures that scaledObjectName=<scaledObject.Name> label exist in the ScaledObject
// ensureScaledObjectLabel ensures that scaledobject.keda.sh/name=<scaledObject.Name> label exist in the ScaledObject
// This is how the MetricsAdapter will know which ScaledObject a metric is for when the HPA queries it.
func (r *ScaledObjectReconciler) ensureScaledObjectLabel(logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) error {
const labelScaledObjectName = "scaledObjectName"
const labelScaledObjectName = "scaledobject.keda.sh/name"

if scaledObject.Labels == nil {
scaledObject.Labels = map[string]string{labelScaledObjectName: scaledObject.Name}
Expand All @@ -246,7 +246,7 @@ func (r *ScaledObjectReconciler) ensureScaledObjectLabel(logger logr.Logger, sca
scaledObject.Labels[labelScaledObjectName] = scaledObject.Name
}

logger.V(1).Info("Adding scaledObjectName label on ScaledObject", "value", scaledObject.Name)
logger.V(1).Info("Adding \"scaledobject.keda.sh/name\" label on ScaledObject", "value", scaledObject.Name)
return r.Client.Update(context.TODO(), scaledObject)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/scaling/executor/scale_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (e *scaleExecutor) createJobs(logger logr.Logger, scaledJob *kedav1alpha1.S
if scaledJob.Spec.JobTargetRef.Template.Labels == nil {
scaledJob.Spec.JobTargetRef.Template.Labels = map[string]string{}
}
scaledJob.Spec.JobTargetRef.Template.Labels["scaledjob"] = scaledJob.GetName()
scaledJob.Spec.JobTargetRef.Template.Labels["scaledjob.keda.sh/name"] = scaledJob.GetName()

logger.Info("Creating jobs", "Effective number of max jobs", maxScale)

Expand All @@ -90,7 +90,7 @@ func (e *scaleExecutor) createJobs(logger logr.Logger, scaledJob *kedav1alpha1.S
"app.kubernetes.io/version": version.Version,
"app.kubernetes.io/part-of": scaledJob.GetName(),
"app.kubernetes.io/managed-by": "keda-operator",
"scaledjob": scaledJob.GetName(),
"scaledjob.keda.sh/name": scaledJob.GetName(),
}
for key, value := range scaledJob.ObjectMeta.Labels {
labels[key] = value
Expand Down Expand Up @@ -142,7 +142,7 @@ func (e *scaleExecutor) getRunningJobCount(scaledJob *kedav1alpha1.ScaledJob) in

opts := []client.ListOption{
client.InNamespace(scaledJob.GetNamespace()),
client.MatchingLabels(map[string]string{"scaledjob": scaledJob.GetName()}),
client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}),
}

jobs := &batchv1.JobList{}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (e *scaleExecutor) getPendingJobCount(scaledJob *kedav1alpha1.ScaledJob) in

opts := []client.ListOption{
client.InNamespace(scaledJob.GetNamespace()),
client.MatchingLabels(map[string]string{"scaledjob": scaledJob.GetName()}),
client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}),
}

jobs := &batchv1.JobList{}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (e *scaleExecutor) cleanUp(scaledJob *kedav1alpha1.ScaledJob) error {

opts := []client.ListOption{
client.InNamespace(scaledJob.GetNamespace()),
client.MatchingLabels(map[string]string{"scaledjob": scaledJob.GetName()}),
client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}),
}

jobs := &batchv1.JobList{}
Expand Down

0 comments on commit 31e980e

Please sign in to comment.