Skip to content

Commit

Permalink
Merge pull request #258 from sonam1412/cp-labels-itplr
Browse files Browse the repository at this point in the history
fix(STONEINTG-508): copy build labels/annotations to the intg test PLR
  • Loading branch information
sonam1412 authored Aug 3, 2023
2 parents 63e7e81 + ef32e72 commit 8075f54
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions controllers/snapshot/snapshot_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ func (a *Adapter) createIntegrationPipelineRun(application *applicationapiv1alph
// copy PipelineRun PAC annotations/labels from snapshot to integration test PipelineRuns
h.CopyAnnotationsByPrefix(&snapshot.ObjectMeta, &pipelineRun.ObjectMeta, gitops.PipelinesAsCodePrefix, gitops.PipelinesAsCodePrefix)
h.CopyLabelsByPrefix(&snapshot.ObjectMeta, &pipelineRun.ObjectMeta, gitops.PipelinesAsCodePrefix, gitops.PipelinesAsCodePrefix)

// Copy build labels and annotations prefixed with build.appstudio from snapshot to integration test PipelineRuns
h.CopyLabelsByPrefix(&snapshot.ObjectMeta, &pipelineRun.ObjectMeta, gitops.BuildPipelineRunPrefix, gitops.BuildPipelineRunPrefix)
h.CopyAnnotationsByPrefix(&snapshot.ObjectMeta, &pipelineRun.ObjectMeta, gitops.BuildPipelineRunPrefix, gitops.BuildPipelineRunPrefix)

err := ctrl.SetControllerReference(snapshot, pipelineRun, a.client.Scheme())
if err != nil {
return nil, err
Expand Down
42 changes: 39 additions & 3 deletions controllers/snapshot/snapshot_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,14 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
Name: "snapshot-sample",
Namespace: "default",
Labels: map[string]string{
gitops.SnapshotTypeLabel: "component",
gitops.SnapshotComponentLabel: "component-sample",
gitops.SnapshotTypeLabel: "component",
gitops.SnapshotComponentLabel: "component-sample",
"build.appstudio.redhat.com/pipeline": "enterprise-contract",
},
Annotations: map[string]string{
gitops.PipelineAsCodeInstallationIDAnnotation: "123",
gitops.PipelineAsCodeInstallationIDAnnotation: "123",
"build.appstudio.redhat.com/commit_sha": "6c65b2fcaea3e1a0a92476c8b5dc89e92a85f025",
"appstudio.redhat.com/updateComponentOnSuccess": "false",
},
},
Spec: applicationapiv1alpha1.SnapshotSpec{
Expand Down Expand Up @@ -559,6 +562,39 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
err = k8sClient.Delete(ctx, &binding)
Expect(err == nil || errors.IsNotFound(err)).To(BeTrue())
})

It("ensures build labels/annotations prefixed with 'build.appstudio' are propagated from snapshot to Integration test PLR", func() {
pipelineRun, err := adapter.createIntegrationPipelineRun(hasApp, integrationTestScenario, hasSnapshot)
Expect(err).To(BeNil())
Expect(pipelineRun).ToNot(BeNil())

annotation, found := pipelineRun.GetAnnotations()["build.appstudio.redhat.com/commit_sha"]
Expect(found).To(BeTrue())
Expect(annotation).To(Equal("6c65b2fcaea3e1a0a92476c8b5dc89e92a85f025"))

label, found := pipelineRun.GetLabels()["build.appstudio.redhat.com/pipeline"]
Expect(found).To(BeTrue())
Expect(label).To(Equal("enterprise-contract"))
})

It("ensures build labels/annotations non-prefixed with 'build.appstudio' are NOT propagated from snapshot to Integration test PLR", func() {
pipelineRun, err := adapter.createIntegrationPipelineRun(hasApp, integrationTestScenario, hasSnapshot)
Expect(err).To(BeNil())
Expect(pipelineRun).ToNot(BeNil())

// build annotations non-prefixed with 'build.appstudio' are not copied
_, found := hasSnapshot.GetAnnotations()["appstudio.redhat.com/updateComponentOnSuccess"]
Expect(found).To(BeTrue())
_, found = pipelineRun.GetAnnotations()["appstudio.redhat.com/updateComponentOnSuccess"]
Expect(found).To(BeFalse())

// build labels non-prefixed with 'build.appstudio' are not copied
_, found = hasSnapshot.GetLabels()[gitops.SnapshotTypeLabel]
Expect(found).To(BeTrue())
_, found = pipelineRun.GetLabels()[gitops.SnapshotTypeLabel]
Expect(found).To(BeFalse())

})
})

When("multiple components exist", func() {
Expand Down

0 comments on commit 8075f54

Please sign in to comment.