Skip to content

Commit

Permalink
Merge pull request #232 from mmalina/workspace-subdir
Browse files Browse the repository at this point in the history
fix(RHTAPBUGS-560): ensure each pipelinerun uses its own subdir
  • Loading branch information
davidmogar authored Aug 14, 2023
2 parents 1ea93d1 + 25cfcdb commit f916c17
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions controllers/release/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package release
import (
"context"
"fmt"
"github.com/redhat-appstudio/operator-toolkit/controller"
"strings"

"github.com/redhat-appstudio/operator-toolkit/controller"

"github.com/go-logr/logr"
"github.com/redhat-appstudio/release-service/api/v1alpha1"
"github.com/redhat-appstudio/release-service/gitops"
Expand Down Expand Up @@ -306,7 +307,7 @@ func (a *adapter) createReleasePipelineRun(resources *loader.ProcessingResources
resources.ReleasePlanAdmission, resources.ReleaseStrategy, resources.Snapshot).
WithOwner(a.release).
WithReleaseAndApplicationMetadata(a.release, resources.Snapshot.Spec.Application).
WithReleaseStrategy(resources.ReleaseStrategy).
WithReleaseStrategy(resources.ReleaseStrategy, a.release).
WithEnterpriseContractConfigMap(resources.EnterpriseContractConfigMap).
WithEnterpriseContractPolicy(resources.EnterpriseContractPolicy).
AsPipelineRun()
Expand Down
12 changes: 7 additions & 5 deletions tekton/pipeline_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *ReleasePipelineRun) WithReleaseAndApplicationMetadata(release *v1alpha1
}

// WithReleaseStrategy adds Pipeline reference and parameters to the release PipelineRun.
func (r *ReleasePipelineRun) WithReleaseStrategy(strategy *v1alpha1.ReleaseStrategy) *ReleasePipelineRun {
func (r *ReleasePipelineRun) WithReleaseStrategy(strategy *v1alpha1.ReleaseStrategy, release *v1alpha1.Release) *ReleasePipelineRun {
r.Spec.PipelineRef = getPipelineRef(strategy)

valueType := tektonv1beta1.ParamTypeString
Expand All @@ -163,9 +163,9 @@ func (r *ReleasePipelineRun) WithReleaseStrategy(strategy *v1alpha1.ReleaseStrat
}

if strategy.Spec.PersistentVolumeClaim == "" {
r.WithWorkspace(os.Getenv("DEFAULT_RELEASE_WORKSPACE_NAME"), os.Getenv("DEFAULT_RELEASE_PVC"))
r.WithWorkspace(os.Getenv("DEFAULT_RELEASE_WORKSPACE_NAME"), os.Getenv("DEFAULT_RELEASE_PVC"), release.Name)
} else {
r.WithWorkspace(os.Getenv("DEFAULT_RELEASE_WORKSPACE_NAME"), strategy.Spec.PersistentVolumeClaim)
r.WithWorkspace(os.Getenv("DEFAULT_RELEASE_WORKSPACE_NAME"), strategy.Spec.PersistentVolumeClaim, release.Name)
}

r.WithServiceAccount(strategy.Spec.ServiceAccount)
Expand All @@ -182,9 +182,10 @@ func (r *ReleasePipelineRun) WithServiceAccount(serviceAccount string) *ReleaseP
}

// WithWorkspace adds a workspace to the PipelineRun using the given name and PersistentVolumeClaim.
// A subdir consisting of the provided Release name and the PipelineRun uid context variable.
// If any of those values is empty, no workspace will be added.
func (r *ReleasePipelineRun) WithWorkspace(name, persistentVolumeClaim string) *ReleasePipelineRun {
if name == "" || persistentVolumeClaim == "" {
func (r *ReleasePipelineRun) WithWorkspace(name, persistentVolumeClaim string, releaseName string) *ReleasePipelineRun {
if name == "" || persistentVolumeClaim == "" || releaseName == "" {
return r
}

Expand All @@ -193,6 +194,7 @@ func (r *ReleasePipelineRun) WithWorkspace(name, persistentVolumeClaim string) *
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: persistentVolumeClaim,
},
SubPath: releaseName + "-$(context.pipelineRun.uid)",
})

return r
Expand Down
11 changes: 6 additions & 5 deletions tekton/pipeline_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var _ = Describe("PipelineRun", func() {
})

It("can add the ReleaseStrategy information and bundle resolver if present to a PipelineRun object ", func() {
releasePipelineRun.WithReleaseStrategy(strategy)
releasePipelineRun.WithReleaseStrategy(strategy, release)
Expect(releasePipelineRun.Spec.PipelineRef.ResolverRef).NotTo(Equal(tektonv1beta1.ResolverRef{}))
Expect(releasePipelineRun.Spec.PipelineRef.ResolverRef.Resolver).To(Equal(tektonv1beta1.ResolverName("bundles")))
Expect(releasePipelineRun.Spec.PipelineRef.ResolverRef.Params).To(HaveLen(3))
Expand All @@ -208,9 +208,10 @@ var _ = Describe("PipelineRun", func() {
})

It("can add a workspace to the PipelineRun using the given name and PVC", func() {
releasePipelineRun.WithWorkspace(workspace, persistentVolumeClaim)
releasePipelineRun.WithWorkspace(workspace, persistentVolumeClaim, release.Name)
Expect(releasePipelineRun.Spec.Workspaces).Should(ContainElement(HaveField("Name", Equal(workspace))))
Expect(releasePipelineRun.Spec.Workspaces).Should(ContainElement(HaveField("PersistentVolumeClaim.ClaimName", Equal(persistentVolumeClaim))))
Expect(releasePipelineRun.Spec.Workspaces).Should(ContainElement(HaveField("SubPath", Equal(release.Name+"-$(context.pipelineRun.uid)"))))
})

It("can add the EC task bundle parameter to the PipelineRun", func() {
Expand Down Expand Up @@ -248,7 +249,7 @@ var _ = Describe("PipelineRun", func() {
os.Setenv("DEFAULT_RELEASE_WORKSPACE_NAME", "")
os.Setenv("DEFAULT_RELEASE_PVC", "bar")
strategy.Spec.PersistentVolumeClaim = ""
releasePipelineRun.WithReleaseStrategy(strategy)
releasePipelineRun.WithReleaseStrategy(strategy, release)
Expect(releasePipelineRun.Spec.Workspaces).To(BeNil())
})
})
Expand All @@ -257,7 +258,7 @@ var _ = Describe("PipelineRun", func() {
os.Setenv("DEFAULT_RELEASE_WORKSPACE_NAME", "foo")
os.Setenv("DEFAULT_RELEASE_PVC", "")
strategy.Spec.PersistentVolumeClaim = ""
releasePipelineRun.WithReleaseStrategy(strategy)
releasePipelineRun.WithReleaseStrategy(strategy, release)
Expect(releasePipelineRun.Spec.Workspaces).To(BeNil())
})
})
Expand All @@ -266,7 +267,7 @@ var _ = Describe("PipelineRun", func() {
os.Setenv("DEFAULT_RELEASE_WORKSPACE_NAME", "foo")
os.Setenv("DEFAULT_RELEASE_PVC", "bar")
strategy.Spec.PersistentVolumeClaim = ""
releasePipelineRun.WithReleaseStrategy(strategy)
releasePipelineRun.WithReleaseStrategy(strategy, release)
Expect(releasePipelineRun.Spec.Workspaces).Should(ContainElement(HaveField("Name", Equal("foo"))))
Expect(releasePipelineRun.Spec.Workspaces).Should(ContainElement(HaveField("PersistentVolumeClaim.ClaimName", Equal("bar"))))
})
Expand Down

0 comments on commit f916c17

Please sign in to comment.