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

feat(analysis): Adds rollout Spec.Selector.MatchLabels to AnalysisRun. Fixes #2888 #2903

Merged
merged 8 commits into from
Aug 10, 2023
5 changes: 5 additions & 0 deletions rollout/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ func (c *rolloutContext) newAnalysisRunFromRollout(rolloutAnalysis *v1alpha1.Rol
for k, v := range rolloutAnalysis.AnalysisRunMetadata.Labels {
run.Labels[k] = v
}

for k, v := range c.rollout.Spec.Selector.MatchLabels {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think taking the labels on the rollout object vs the MatchLabels probably make more sense and follows what we do with ReplicaSets, with RS we take the pod template labels and put them on the RS as labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zachaller, I'll have a look at the RS code and follow the same practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, as requested updated to use template labels.

run.Labels[k] = v
}

run.Annotations = map[string]string{
annotations.RevisionAnnotation: revision,
}
Expand Down
5 changes: 4 additions & 1 deletion rollout/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ func TestAbortRolloutOnErrorPostPromotionAnalysis(t *testing.T) {
assert.Equal(t, calculatePatch(r2, fmt.Sprintf(expectedPatch, now, newConditions, conditions.RolloutAbortedReason, progressingFalseAborted.Message)), patch)
}

func TestCreateAnalysisRunWithCustomAnalysisRunMetadata(t *testing.T) {
func TestCreateAnalysisRunWithCustomAnalysisRunMetadataAndROCopyLabels(t *testing.T) {
f := newFixture(t)
defer f.Close()

Expand All @@ -2346,6 +2346,8 @@ func TestCreateAnalysisRunWithCustomAnalysisRunMetadata(t *testing.T) {
}}
at := analysisTemplate("bar")
r1 := newCanaryRollout("foo", 10, nil, steps, pointer.Int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1))
r1.ObjectMeta.Labels = make(map[string]string)
r1.Spec.Selector.MatchLabels["my-label"] = "1234"
r2 := bumpVersion(r1)
ar := analysisRun(at, v1alpha1.RolloutTypeBackgroundRunLabel, r2)
r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisBackground{
Expand Down Expand Up @@ -2386,4 +2388,5 @@ func TestCreateAnalysisRunWithCustomAnalysisRunMetadata(t *testing.T) {
assert.Equal(t, expectedArName, createdAr.Name)
assert.Equal(t, "testAnnotationValue", createdAr.Annotations["testAnnotationKey"])
assert.Equal(t, "testLabelValue", createdAr.Labels["testLabelKey"])
assert.Equal(t, "1234", createdAr.Labels["my-label"])
}