Skip to content

Commit

Permalink
fix(STONEINTG-523): use SetAnnotation function
Browse files Browse the repository at this point in the history
We have a regression because function AddAnnotations is only adding new
annotations to objects, existing annotations are not updated.

We need to update existing annotations, thus using SetAnnotation
function from newer version of operator-toolkit repo.

Signed-off-by: Martin Basti <[email protected]>
  • Loading branch information
MartinBasti committed Sep 13, 2023
1 parent 068cde1 commit 6d6100b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
4 changes: 1 addition & 3 deletions controllers/buildpipeline/buildpipeline_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,8 @@ func (a *Adapter) getSucceededBuildPipelineRunsForComponent(component *applicati

func (a *Adapter) annotateBuildPipelineRunWithSnapshot(pipelineRun *tektonv1beta1.PipelineRun, snapshot *applicationapiv1alpha1.Snapshot) (*tektonv1beta1.PipelineRun, error) {
patch := client.MergeFrom(pipelineRun.DeepCopy())
newAnnotations := map[string]string{}
newAnnotations[tekton.SnapshotNameLabel] = snapshot.Name

_ = metadata.AddAnnotations(&pipelineRun.ObjectMeta, newAnnotations)
_ = metadata.SetAnnotation(&pipelineRun.ObjectMeta, tekton.SnapshotNameLabel, snapshot.Name)

err := a.client.Patch(a.context, pipelineRun, patch)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions gitops/snapshot_integration_tests_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ func WriteIntegrationTestStatusesIntoSnapshot(s *applicationapiv1alpha1.Snapshot
return fmt.Errorf("failed to marshal test results into JSON: %w", err)
}

newAnnotations := map[string]string{
SnapshotTestsStatusAnnotation: string(value),
}
if err := metadata.AddAnnotations(&s.ObjectMeta, newAnnotations); err != nil {
if err := metadata.SetAnnotation(&s.ObjectMeta, SnapshotTestsStatusAnnotation, string(value)); err != nil {
return fmt.Errorf("failed to add annotations: %w", err)
}

Expand Down
21 changes: 5 additions & 16 deletions gitops/snapshot_integration_tests_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,7 @@ var _ = Describe("Snapshot integration test statuses", func() {
When("Snapshot contains empty test status annotation", func() {

BeforeEach(func() {
err := metadata.AddAnnotations(
snapshot,
map[string]string{gitops.SnapshotTestsStatusAnnotation: "[]"},
)
err := metadata.SetAnnotation(snapshot, gitops.SnapshotTestsStatusAnnotation, "[]")
Expect(err).To(BeNil())
})

Expand All @@ -442,10 +439,7 @@ var _ = Describe("Snapshot integration test statuses", func() {
sits.UpdateTestStatusIfChanged(testScenarioName, gitops.IntegrationTestStatusInProgress, testDetails)
testAnnotation, err := json.Marshal(sits)
Expect(err).To(BeNil())
err = metadata.AddAnnotations(
snapshot,
map[string]string{gitops.SnapshotTestsStatusAnnotation: string(testAnnotation)},
)
err = metadata.SetAnnotation(snapshot, gitops.SnapshotTestsStatusAnnotation, string(testAnnotation))
Expect(err).To(BeNil())

})
Expand All @@ -465,10 +459,8 @@ var _ = Describe("Snapshot integration test statuses", func() {

When("Snapshot contains invalid test status annotation", func() {
BeforeEach(func() {
err := metadata.AddAnnotations(
snapshot,
map[string]string{gitops.SnapshotTestsStatusAnnotation: "[{\"invalid\":\"data\"}]"},
)
err := metadata.SetAnnotation(
snapshot, gitops.SnapshotTestsStatusAnnotation, "[{\"invalid\":\"data\"}]")
Expect(err).To(BeNil())
})

Expand All @@ -480,10 +472,7 @@ var _ = Describe("Snapshot integration test statuses", func() {

When("Snapshot contains invalid JSON test status annotation", func() {
BeforeEach(func() {
err := metadata.AddAnnotations(
snapshot,
map[string]string{gitops.SnapshotTestsStatusAnnotation: "{}"},
)
err := metadata.SetAnnotation(snapshot, gitops.SnapshotTestsStatusAnnotation, "{}")
Expect(err).To(BeNil())
})

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/openshift-pipelines/pipelines-as-code v0.17.2
github.com/prometheus/client_golang v1.16.0
github.com/redhat-appstudio/application-api v0.0.0-20230427114540-a91722251e0a
github.com/redhat-appstudio/operator-toolkit v0.0.0-20230829074524-440a6e31b5ae
github.com/redhat-appstudio/operator-toolkit v0.0.0-20230913085326-6c5e9d368a6a
github.com/redhat-appstudio/release-service v0.0.0-20230511145849-bde1cdcbb60b
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/tektoncd/pipeline v0.48.0
Expand Down
Loading

0 comments on commit 6d6100b

Please sign in to comment.