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

[Labels] Argo-rollout's experiments and replicaSet cannot be enriched with custom labels #4113

Closed
ayureidini opened this issue Feb 5, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@ayureidini
Copy link
Contributor

Summary

I have noticed that there is no mechanism to add custom labels to Experiments and their associated ReplicaSets.

What change needs making?
I have tested this change for canary strategy and the idea would be to propagate labels from spec.template.labels into Experiments and ReplicaSets upon creation.

diff --git a/experiments/replicaset.go b/experiments/replicaset.go
index d91843a0..56424ac9 100644
--- a/experiments/replicaset.go
+++ b/experiments/replicaset.go
@@ -166,17 +166,21 @@ func newReplicaSetFromTemplate(experiment *v1alpha1.Experiment, template v1alpha
        newRSTemplate.Labels = labelsutil.CloneAndAddLabel(newRSTemplate.Labels, v1alpha1.DefaultRolloutUniqueLabelKey, podHash)
        // Add podTemplateHash label to selector.
        newRSSelector := labelsutil.CloneSelectorAndAddLabel(template.Selector, v1alpha1.DefaultRolloutUniqueLabelKey, podHash)
+       newRSLabels := map[string]string{}
+       // enrich with template labels
+       for k, v := range newRSTemplate.Labels {
+               newRSLabels[k] = v
+       }
+       newRSLabels[v1alpha1.DefaultRolloutUniqueLabelKey] = podHash
 
        // The annotations must be different for each template because annotations are used to match
        // replicasets to templates. We inject the experiment and template name in the replicaset
        // annotations to ensure uniqueness.
        rs := appsv1.ReplicaSet{
                ObjectMeta: metav1.ObjectMeta{
-                       Name:      fmt.Sprintf("%s-%s", experiment.Name, template.Name),
-                       Namespace: experiment.Namespace,
-                       Labels: map[string]string{
-                               v1alpha1.DefaultRolloutUniqueLabelKey: podHash,
-                       },
+                       Name:            fmt.Sprintf("%s-%s", experiment.Name, template.Name),
+                       Namespace:       experiment.Namespace,
+                       Labels:          newRSLabels,
                        OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(experiment, controllerKind)},
                        Annotations:     replicaSetAnnotations,
                },
diff --git a/rollout/experiment.go b/rollout/experiment.go
index 7b28cc28..c65e7322 100644
--- a/rollout/experiment.go
+++ b/rollout/experiment.go
@@ -35,14 +35,19 @@ func GetExperimentFromTemplate(r *v1alpha1.Rollout, stableRS, newRS *appsv1.Repl
        if r.Annotations != nil {
                revision = r.Annotations[annotations.RevisionAnnotation]
        }
+       newExperimentabels := map[string]string{}
+       // enrich with template labels
+       for k, v := range r.Labels {
+               newExperimentabels[k] = v
+       }
+       newExperimentabels[v1alpha1.DefaultRolloutUniqueLabelKey] = podHash
+
        experiment := &v1alpha1.Experiment{
                ObjectMeta: metav1.ObjectMeta{
                        Name:            fmt.Sprintf("%s-%s-%s-%d", r.Name, podHash, revision, currentStep),
                        Namespace:       r.Namespace,
                        OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(r, controllerKind)},
-                       Labels: map[string]string{
-                               v1alpha1.DefaultRolloutUniqueLabelKey: podHash,
-                       },
+                       Labels:          newExperimentabels,
                        Annotations: map[string]string{
                                annotations.RevisionAnnotation: revision,
                        },

Use Cases

This can be useful for complying to Tagging Policy imposed at cluster level. Indeed, this can be useful for enabling automatic reporting but also give required information for investigation. This can be levered by using Open Policy Agent (OPA) Gatekeeper.


Message from the maintainers:

Impacted by this bug? Give it a 👍. We prioritize the issues with the most 👍.

@ayureidini ayureidini added the enhancement New feature or request label Feb 5, 2025
@OpenGuidou
Copy link
Contributor

It looks indeed like a miss. Would you mind raising a PR to add it ?

ayureidini pushed a commit to ayureidini/argo-rollouts that referenced this issue Feb 6, 2025
… sets

Enhancement ticket: argoproj#4113
This can be useful for complying to Tagging Policy imposed at cluster level
since there is no mechanism to add custom labels to Experiments and their
associated ReplicaSets.
Indeed, this could enable automatic reporting but also give required information
for investigation.
ayureidini pushed a commit to ayureidini/argo-rollouts that referenced this issue Feb 6, 2025
… sets

Enhancement ticket: argoproj#4113
This can be useful for complying to Tagging Policy imposed at cluster level
since there is no mechanism to add custom labels to Experiments and their
associated ReplicaSets.
Indeed, this could enable automatic reporting but also give required information
for investigation.
Signed-off-by: Ahmed YUREIDINI [email protected]
ayureidini pushed a commit to ayureidini/argo-rollouts that referenced this issue Feb 6, 2025
… sets

Enhancement ticket: argoproj#4113
This can be useful for complying to Tagging Policy imposed at cluster level
since there is no mechanism to add custom labels to Experiments and their
associated ReplicaSets.
Indeed, this could enable automatic reporting but also give required information
for investigation.
Signed-off-by: Ahmed YUREIDINI <[email protected]>
ayureidini pushed a commit to ayureidini/argo-rollouts that referenced this issue Feb 6, 2025
… sets

Enhancement ticket: argoproj#4113
This can be useful for complying to Tagging Policy imposed at cluster level
since there is no mechanism to add custom labels to Experiments and their
associated ReplicaSets.
Indeed, this could enable automatic reporting but also give required information
for investigation.

Signed-off-by: Ahmed YUREIDINI NOGALES <[email protected]>
ayureidini pushed a commit to ayureidini/argo-rollouts that referenced this issue Feb 6, 2025
… sets

Enhancement ticket: argoproj#4113
This can be useful for complying to Tagging Policy imposed at cluster level
since there is no mechanism to add custom labels to Experiments and their
associated ReplicaSets.
Indeed, this could enable automatic reporting but also give required information
for investigation.

Signed-off-by: Ahmed YUREIDINI NOGALES <[email protected]>
@ayureidini
Copy link
Contributor Author

ayureidini commented Feb 6, 2025

@OpenGuidou : Pull-request submitted: #4118

zachaller pushed a commit that referenced this issue Feb 7, 2025
…sets (#4118)

fix(experiments): propagate rolouts labels to experiments and replica sets

Enhancement ticket: #4113
This can be useful for complying to Tagging Policy imposed at cluster level
since there is no mechanism to add custom labels to Experiments and their
associated ReplicaSets.
Indeed, this could enable automatic reporting but also give required information
for investigation.

Signed-off-by: Ahmed YUREIDINI NOGALES <[email protected]>
Co-authored-by: Ahmed YUREIDINI NOGALES <[email protected]>
@ayureidini
Copy link
Contributor Author

Pull-request was merged, so I am closing this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants