Skip to content

Commit

Permalink
Merge pull request #334 from johnbieren/rhtaprel_790
Browse files Browse the repository at this point in the history
feat(RHTAPREL-790): pass taskGitRevision param to plr
  • Loading branch information
johnbieren authored Jan 9, 2024
2 parents b1ca7bb + 4193998 commit 405596b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
1 change: 1 addition & 0 deletions controllers/release/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func (a *adapter) createManagedPipelineRun(resources *loader.ProcessingResources
WithServiceAccount(resources.ReleasePlanAdmission.Spec.ServiceAccount).
WithTimeout(resources.ReleasePlanAdmission.Spec.PipelineRef.Timeout).
WithPipelineRef(resources.ReleasePlanAdmission.Spec.PipelineRef.ToTektonPipelineRef()).
WithTaskGitRevisionParameter(resources.ReleasePlanAdmission.Spec.PipelineRef).
WithEnterpriseContractConfigMap(resources.EnterpriseContractConfigMap).
WithEnterpriseContractPolicy(resources.EnterpriseContractPolicy).
AsPipelineRun()
Expand Down
28 changes: 20 additions & 8 deletions controllers/release/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,14 +872,26 @@ var _ = Describe("Release adapter", Ordered, func() {
})

It("references the pipeline specified in the ReleasePlanAdmission", func() {
var pipelineName string
var pipelineUrl string
resolverParams := pipelineRun.Spec.PipelineRef.ResolverRef.Params
for i := range resolverParams {
if resolverParams[i].Name == "name" {
pipelineName = resolverParams[i].Value.StringVal
if resolverParams[i].Name == "url" {
pipelineUrl = resolverParams[i].Value.StringVal
}
}
Expect(pipelineName).To(Equal(releasePlanAdmission.Spec.PipelineRef.Params[1].Value))
Expect(pipelineUrl).To(Equal(releasePlanAdmission.Spec.PipelineRef.Params[0].Value))
})

It("contains a parameter with the taskGitRevision", func() {
Expect(pipelineRun.Spec.Params).Should(ContainElement(HaveField("Name", "taskGitRevision")))
var revision string
resolverParams := pipelineRun.Spec.PipelineRef.ResolverRef.Params
for i := range resolverParams {
if resolverParams[i].Name == "revision" {
revision = resolverParams[i].Value.StringVal
}
}
Expect(pipelineRun.Spec.Params).Should(ContainElement(HaveField("Value.StringVal", revision)))
})

It("contains the proper timeout value", func() {
Expand Down Expand Up @@ -1689,11 +1701,11 @@ var _ = Describe("Release adapter", Ordered, func() {
Origin: "default",
Environment: environment.Name,
PipelineRef: &tektonutils.PipelineRef{
Resolver: "bundles",
Resolver: "git",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
{Name: "url", Value: "my-url"},
{Name: "revision", Value: "my-revision"},
{Name: "pathInRepo", Value: "my-path"},
},
Timeout: "2h0m0s",
},
Expand Down
18 changes: 18 additions & 0 deletions tekton/pipeline_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

ecapiv1alpha1 "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
"github.com/redhat-appstudio/release-service/metadata"
"github.com/redhat-appstudio/release-service/tekton/utils"

libhandler "github.com/operator-framework/operator-lib/handler"
integrationServiceGitopsPkg "github.com/redhat-appstudio/integration-service/gitops"
Expand Down Expand Up @@ -163,6 +164,23 @@ func (r *ReleasePipelineRun) WithServiceAccount(serviceAccount string) *ReleaseP
return r
}

// WithTaskGitRevisionParameter adds the taskGitRevision parameter to the managed Release PipelineRun with the value of the revision
// from the pipelineRef if the pipelineRef is for a git resolver.
func (r *ReleasePipelineRun) WithTaskGitRevisionParameter(pipelineRef *utils.PipelineRef) *ReleasePipelineRun {
if pipelineRef.Resolver == "git" {
for _, p := range pipelineRef.Params {
if p.Name == "revision" {
r.WithExtraParam("taskGitRevision", tektonv1.ParamValue{
Type: tektonv1.ParamTypeString,
StringVal: p.Value,
})
}
}
}

return r
}

// WithTimeout overwrites the PipelineRun's default timeout value.
func (r *ReleasePipelineRun) WithTimeout(timeout string) *ReleasePipelineRun {
duration, err := time.ParseDuration(timeout)
Expand Down
29 changes: 29 additions & 0 deletions tekton/pipeline_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,35 @@ var _ = Describe("PipelineRun", func() {
Expect(releasePipelineRun.Spec.TaskRunTemplate.ServiceAccountName).To(Equal(serviceAccountName))
})

It("can add the taskGitRevision parameter to the PipelineRun object when using a git resolver", func() {
pipelineRef := &tektonutils.PipelineRef{
Resolver: "git",
Params: []tektonutils.Param{
{
Name: "revision",
Value: "my-revision",
},
},
}
releasePipelineRun.WithTaskGitRevisionParameter(pipelineRef)
Expect(releasePipelineRun.Spec.Params[0].Name).To(Equal("taskGitRevision"))
Expect(releasePipelineRun.Spec.Params[0].Value.StringVal).To(Equal("my-revision"))
})

It("does not add the taskGitRevision parameter to the PipelineRun object when using a bundles resolver", func() {
pipelineRef := &tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{
Name: "revision",
Value: "my-revision",
},
},
}
releasePipelineRun.WithTaskGitRevisionParameter(pipelineRef)
Expect(len(releasePipelineRun.Spec.Params)).To(Equal(0))
})

It("can add the timeout that should be used", func() {
releasePipelineRun.WithTimeout(timeout)
Expect(releasePipelineRun.Spec.Timeouts.Pipeline.Duration.String()).To(Equal(timeout))
Expand Down

0 comments on commit 405596b

Please sign in to comment.