Skip to content

Commit

Permalink
Merge branch 'konflux-ci:main' into STONEINTG-863
Browse files Browse the repository at this point in the history
  • Loading branch information
chipspeak authored Jul 4, 2024
2 parents aa78463 + ab1b8d3 commit 850495f
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ARG ENABLE_WEBHOOKS=true
ENV ENABLE_WEBHOOKS=${ENABLE_WEBHOOKS}
# Use ubi-minimal as minimal base image to package the manager binary
# Refer to https://catalog.redhat.com/software/containers/ubi8/ubi-minimal/5c359a62bed8bd75a2c3fba8 for more details
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10-896.1717584414
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10-1018
COPY --from=builder /opt/app-root/src/manager /
COPY --from=builder /opt/app-root/src/snapshotgc /

Expand Down
8 changes: 1 addition & 7 deletions docs/statusreport-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ flowchart TD
get_required_scenarios(Get all required <br> IntegrationTestScenarios)
parse_snapshot_status(Parse the Snapshot's <br> status annotation)
check_finished_tests{Did Snapshot <br> finish all required <br> integration tests?}
check_supersede{Does Snapshot need <br> to be superseded <br> with a composite Snapshot?}
check_passed_tests{Did Snapshot <br> pass all required <br> integration tests?}
create_snapshot(Create composite Snapshot)
update_status(Update Snapshot status accordingly)
continue_processing_tests(Controller continues processing)
Expand All @@ -26,11 +24,7 @@ flowchart TD
predicate ----> |"EnsureSnapshotFinishedAllTests()"|get_required_scenarios
get_required_scenarios ---> parse_snapshot_status
parse_snapshot_status ---> check_finished_tests
check_finished_tests --Yes--> check_supersede
check_finished_tests --No--> continue_processing_tests
check_supersede --Yes--> create_snapshot
check_supersede --No--> check_passed_tests
create_snapshot ---> update_status
check_finished_tests ---> continue_processing_tests
check_passed_tests --Yes--> update_status
check_passed_tests --No--> update_status
update_status ----> continue_processing_tests
Expand Down
29 changes: 15 additions & 14 deletions gitops/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const (
// PipelinesAsCodePrefix contains the prefix applied to labels and annotations copied from Pipelines as Code resources.
PipelinesAsCodePrefix = "pac.test.appstudio.openshift.io"

// TestLabelPrefix contains the prefix applied to labels and annotations related to testing.
TestLabelPrefix = "test.appstudio.openshift.io"

// CustomLabelPrefix contains the prefix applied to custom user-defined labels and annotations.
CustomLabelPrefix = "custom.appstudio.openshift.io"

// SnapshotTypeLabel contains the type of the Snapshot.
SnapshotTypeLabel = "test.appstudio.openshift.io/type"

Expand Down Expand Up @@ -83,9 +89,6 @@ const (
// SnapshotComponentType is the type of Snapshot which was created for a single component build.
SnapshotComponentType = "component"

// SnapshotCompositeType is the type of Snapshot which was created for multiple components.
SnapshotCompositeType = "composite"

// SnapshotOverrideType is the type of Snapshot which was created for override Global Candidate List.
SnapshotOverrideType = "override"

Expand Down Expand Up @@ -822,9 +825,9 @@ func ResetSnapshotStatusConditions(ctx context.Context, adapterClient client.Cli
return nil
}

// CopySnapshotLabelsAndAnnotation coppies labels and annotations from build pipelineRun or tested snapshot
// into regular or composite snapshot
func CopySnapshotLabelsAndAnnotation(application *applicationapiv1alpha1.Application, snapshot *applicationapiv1alpha1.Snapshot, componentName string, source *metav1.ObjectMeta, prefix string, isComposite bool) {
// CopySnapshotLabelsAndAnnotations coppies labels and annotations from build pipelineRun or tested snapshot
// into regular snapshot
func CopySnapshotLabelsAndAnnotations(application *applicationapiv1alpha1.Application, snapshot *applicationapiv1alpha1.Snapshot, componentName string, source *metav1.ObjectMeta, prefixes []string) {

if snapshot.Labels == nil {
snapshot.Labels = map[string]string{}
Expand All @@ -833,11 +836,7 @@ func CopySnapshotLabelsAndAnnotation(application *applicationapiv1alpha1.Applica
if snapshot.Annotations == nil {
snapshot.Annotations = map[string]string{}
}
if !isComposite {
snapshot.Labels[SnapshotTypeLabel] = SnapshotComponentType
} else {
snapshot.Labels[SnapshotTypeLabel] = SnapshotCompositeType
}
snapshot.Labels[SnapshotTypeLabel] = SnapshotComponentType

snapshot.Labels[SnapshotComponentLabel] = componentName
snapshot.Labels[ApplicationNameLabel] = application.Name
Expand All @@ -846,9 +845,11 @@ func CopySnapshotLabelsAndAnnotation(application *applicationapiv1alpha1.Applica
_ = metadata.CopyLabelsWithPrefixReplacement(source, &snapshot.ObjectMeta, "pipelinesascode.tekton.dev", PipelinesAsCodePrefix)
_ = metadata.CopyAnnotationsWithPrefixReplacement(source, &snapshot.ObjectMeta, "pipelinesascode.tekton.dev", PipelinesAsCodePrefix)

// Copy labels and annotations prefixed with defined prefix
_ = metadata.CopyLabelsByPrefix(source, &snapshot.ObjectMeta, prefix)
_ = metadata.CopyAnnotationsByPrefix(source, &snapshot.ObjectMeta, prefix)
for _, prefix := range prefixes {
// Copy labels and annotations prefixed with defined prefix
_ = metadata.CopyLabelsByPrefix(source, &snapshot.ObjectMeta, prefix)
_ = metadata.CopyAnnotationsByPrefix(source, &snapshot.ObjectMeta, prefix)
}

}

Expand Down
3 changes: 2 additions & 1 deletion internal/controller/buildpipeline/buildpipeline_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func (a *Adapter) prepareSnapshotForPipelineRun(pipelineRun *tektonv1.PipelineRu
return nil, err
}

gitops.CopySnapshotLabelsAndAnnotation(application, snapshot, a.component.Name, &pipelineRun.ObjectMeta, gitops.BuildPipelineRunPrefix, false)
prefixes := []string{gitops.BuildPipelineRunPrefix, gitops.TestLabelPrefix, gitops.CustomLabelPrefix}
gitops.CopySnapshotLabelsAndAnnotations(application, snapshot, a.component.Name, &pipelineRun.ObjectMeta, prefixes)

snapshot.Labels[gitops.BuildPipelineRunNameLabel] = pipelineRun.Name
if pipelineRun.Status.CompletionTime != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
SampleImageWithoutDigest = "quay.io/redhat-appstudio/sample-image"
SampleImage = SampleImageWithoutDigest + "@" + SampleDigest
invalidDigest = "invalidDigest"
customLabel = "custom.appstudio.openshift.io/custom-label"
)

BeforeAll(func() {
Expand Down Expand Up @@ -256,8 +257,9 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
"pipelines.openshift.io/runtime": "nodejs",
"pipelines.openshift.io/strategy": "s2i",
"appstudio.openshift.io/component": "component-sample",
"pipelinesascode.tekton.dev/event-type": "pull_request",
"build.appstudio.redhat.com/target_branch": "main",
"pipelinesascode.tekton.dev/event-type": "pull_request",
customLabel: "custom-label",
},
Annotations: map[string]string{
"appstudio.redhat.com/updateComponentOnSuccess": "false",
Expand Down Expand Up @@ -415,12 +417,15 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
Expect(err).ToNot(HaveOccurred())
Expect(copyToSnapshot).NotTo(BeNil())

gitops.CopySnapshotLabelsAndAnnotation(hasApp, copyToSnapshot, hasComp.Name, &buildPipelineRun.ObjectMeta, gitops.BuildPipelineRunPrefix, false)
prefixes := []string{gitops.BuildPipelineRunPrefix, gitops.CustomLabelPrefix, gitops.TestLabelPrefix}
gitops.CopySnapshotLabelsAndAnnotations(hasApp, copyToSnapshot, hasComp.Name, &buildPipelineRun.ObjectMeta, prefixes)
Expect(copyToSnapshot.Labels[gitops.SnapshotTypeLabel]).To(Equal(gitops.SnapshotComponentType))
Expect(copyToSnapshot.Labels[gitops.SnapshotComponentLabel]).To(Equal(hasComp.Name))
Expect(copyToSnapshot.Labels[gitops.ApplicationNameLabel]).To(Equal(hasApp.Name))
Expect(copyToSnapshot.Labels["build.appstudio.redhat.com/target_branch"]).To(Equal("main"))
Expect(copyToSnapshot.Annotations["build.appstudio.openshift.io/repo"]).To(Equal("https://github.com/devfile-samples/devfile-sample-go-basic?rev=c713067b0e65fb3de50d1f7c457eb51c2ab0dbb0"))
Expect(copyToSnapshot.Labels[gitops.PipelineAsCodeEventTypeLabel]).To(Equal(buildPipelineRun.Labels["pipelinesascode.tekton.dev/event-type"]))
Expect(copyToSnapshot.Labels[customLabel]).To(Equal(buildPipelineRun.Labels[customLabel]))

})

Expand Down
5 changes: 0 additions & 5 deletions internal/controller/component/component_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ func (a *Adapter) createUpdatedSnapshot(snapshotComponents *[]applicationapiv1al
if snapshot.Labels == nil {
snapshot.Labels = map[string]string{}
}
snapshotType := gitops.SnapshotCompositeType
if len(*snapshotComponents) == 1 {
snapshotType = gitops.SnapshotComponentType
}
snapshot.Labels[gitops.SnapshotTypeLabel] = snapshotType

err := ctrl.SetControllerReference(a.application, snapshot, a.client.Scheme())
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions internal/controller/snapshot/snapshot_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,6 @@ func (a *Adapter) createIntegrationPipelineRun(application *applicationapiv1alph
}

pipelineRun := pipelineRunBuilder.AsPipelineRun()
// copy PipelineRun PAC annotations/labels from snapshot to integration test PipelineRuns
_ = metadata.CopyAnnotationsByPrefix(&snapshot.ObjectMeta, &pipelineRun.ObjectMeta, gitops.PipelinesAsCodePrefix)
_ = metadata.CopyLabelsByPrefix(&snapshot.ObjectMeta, &pipelineRun.ObjectMeta, gitops.PipelinesAsCodePrefix)

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

err := ctrl.SetControllerReference(snapshot, pipelineRun, a.client.Scheme())
if err != nil {
Expand Down
36 changes: 27 additions & 9 deletions internal/controller/snapshot/snapshot_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
sample_image = "quay.io/redhat-appstudio/sample-image"
sample_revision = "random-value"
sampleDigest = "sha256:841328df1b9f8c4087adbdcfec6cc99ac8308805dea83f6d415d6fb8d40227c1"
customLabel = "custom.appstudio.openshift.io/custom-label"
)

BeforeAll(func() {
Expand Down Expand Up @@ -184,6 +185,7 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
gitops.SnapshotComponentLabel: "component-sample",
"build.appstudio.redhat.com/pipeline": "enterprise-contract",
gitops.PipelineAsCodeEventTypeLabel: "push",
customLabel: "custom-label",
},
Annotations: map[string]string{
gitops.PipelineAsCodeInstallationIDAnnotation: "123",
Expand Down Expand Up @@ -601,21 +603,44 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
Expect(buf.String()).Should(ContainSubstring(expectedLogEntry))
})

It("ensures build labels/annotations prefixed with 'build.appstudio' are propagated from snapshot to Integration test PLR", func() {
It("ensures build, PaC, test, and custom labels/annotations are 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 and labels prefixed with `build.appstudio` are copied
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"))

// Pac labels prefixed with 'pac.test.appstudio.openshift.io' are copied
_, found = hasSnapshot.GetLabels()[gitops.PipelineAsCodeEventTypeLabel]
Expect(found).To(BeTrue())
label, found = pipelineRun.GetLabels()[gitops.PipelineAsCodeEventTypeLabel]
Expect(found).To(BeTrue())
Expect(label).To(Equal(hasSnapshot.GetLabels()[gitops.PipelineAsCodeEventTypeLabel]))

// test labels prefixed with 'test.appstudio.openshift.io' are copied
_, found = hasSnapshot.GetLabels()[gitops.SnapshotTypeLabel]
Expect(found).To(BeTrue())
label, found = pipelineRun.GetLabels()[gitops.SnapshotTypeLabel]
Expect(found).To(BeTrue())
Expect(label).To(Equal(hasSnapshot.GetLabels()[gitops.SnapshotTypeLabel]))

// custom labels prefixed with 'custom.appstudio.openshift.io' are copied
_, found = hasSnapshot.GetLabels()[customLabel]
Expect(found).To(BeTrue())
label, found = pipelineRun.GetLabels()[customLabel]
Expect(found).To(BeTrue())
Expect(label).To(Equal(hasSnapshot.GetLabels()[customLabel]))

})

It("ensures build labels/annotations non-prefixed with 'build.appstudio' are NOT propagated from snapshot to Integration test PLR", func() {
It("ensures other labels/annotations 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())
Expand All @@ -625,13 +650,6 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
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("pull request updates repo with integration test", func() {
Expand Down
19 changes: 18 additions & 1 deletion tekton/integration_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ const (
// PipelinesLabelPrefix is the prefix of the pipelines label
PipelinesLabelPrefix = "pipelines.appstudio.openshift.io"

// TestLabelPrefix is the prefix of the test labels
// TestLabelPrefix contains the prefix applied to labels and annotations related to testing.
TestLabelPrefix = "test.appstudio.openshift.io"

// PipelinesAsCodePrefix contains the prefix applied to labels and annotations copied from Pipelines as Code resources.
PipelinesAsCodePrefix = "pac.test.appstudio.openshift.io"

// BuildPipelineRunPrefix contains the build pipeline run related labels and annotations
BuildPipelineRunPrefix = "build.appstudio"

// CustomLabelPrefix contains the prefix applied to custom user-defined labels and annotations.
CustomLabelPrefix = "custom.appstudio.openshift.io"

// resource labels for snapshot, application and component
ResourceLabelSuffix = "appstudio.openshift.io"

Expand Down Expand Up @@ -204,6 +213,14 @@ func (r *IntegrationPipelineRun) WithSnapshot(snapshot *applicationapiv1alpha1.S
r.ObjectMeta.Labels[ComponentNameLabel] = componentLabel
}

// copy PipelineRun PAC, build, test and custom annotations/labels from Snapshot to integration test PipelineRun
prefixes := []string{PipelinesAsCodePrefix, BuildPipelineRunPrefix, TestLabelPrefix, CustomLabelPrefix}
for _, prefix := range prefixes {
// Copy labels and annotations prefixed with defined prefix
_ = metadata.CopyAnnotationsByPrefix(&snapshot.ObjectMeta, &r.ObjectMeta, prefix)
_ = metadata.CopyLabelsByPrefix(&snapshot.ObjectMeta, &r.ObjectMeta, prefix)
}

return r
}

Expand Down
9 changes: 7 additions & 2 deletions tekton/integration_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ var _ = Describe("Integration pipeline", func() {
Name: "snapshot-sample",
Namespace: "default",
Labels: map[string]string{
gitops.SnapshotTypeLabel: "component",
gitops.SnapshotComponentLabel: "component-sample",
gitops.SnapshotTypeLabel: "component",
gitops.SnapshotComponentLabel: "component-sample",
gitops.CustomLabelPrefix + "/custom-label": "custom-label",
},
},
Spec: applicationapiv1alpha1.SnapshotSpec{
Expand Down Expand Up @@ -357,6 +358,10 @@ var _ = Describe("Integration pipeline", func() {
To(Equal(hasSnapshot.Name))
Expect(newIntegrationPipelineRun.Labels["appstudio.openshift.io/component"]).
To(Equal(hasComp.Name))
Expect(newIntegrationPipelineRun.Labels[gitops.CustomLabelPrefix+"/custom_label"]).
To(Equal(hasSnapshot.Labels[gitops.CustomLabelPrefix+"/custom_label"]))
Expect(newIntegrationPipelineRun.Labels[gitops.SnapshotTypeLabel]).
To(Equal(hasSnapshot.Labels[gitops.SnapshotTypeLabel]))
})

It("can append labels coming from Application to IntegrationPipelineRun and making sure that label values matches application", func() {
Expand Down

0 comments on commit 850495f

Please sign in to comment.