Skip to content

Commit

Permalink
feat(RHTAPREL-714): add Tekton utilities
Browse files Browse the repository at this point in the history
The utilities added in this commit come from the shared-utils
repository. In addition, the RPA already references the new
Pipeline struct.

Signed-off-by: David Moreno García <damoreno@redhat.com>
  • Loading branch information
davidmogar committed Jan 22, 2024
1 parent 22f4a01 commit 6368064
Show file tree
Hide file tree
Showing 19 changed files with 833 additions and 151 deletions.
10 changes: 2 additions & 8 deletions api/v1alpha1/releaseplanadmission_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,14 @@ type ReleasePlanAdmissionSpec struct {
// +required
Origin string `json:"origin"`

// PipelineRef is a reference to the Pipeline to be executed by the managed Release PipelineRun
// Pipeline contains all the information about the managed Pipeline
// +required
PipelineRef *tektonutils.PipelineRef `json:"pipelineRef"`
Pipeline *tektonutils.Pipeline `json:"pipeline"`

// Policy to validate before releasing an artifact
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// +required
Policy string `json:"policy"`

// ServiceAccount is the name of the service account to use in the
// managed Release PipelineRun to gain elevated privileges
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// MatchedReleasePlan defines the relevant information for a matched ReleasePlan.
Expand Down
14 changes: 8 additions & 6 deletions api/v1alpha1/webhooks/releaseplanadmission/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ var _ = Describe("ReleasePlanAdmission webhook", func() {
Applications: []string{"application"},
Origin: "default",
Environment: "environment",
PipelineRef: &tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
Pipeline: &tektonutils.Pipeline{
PipelineRef: tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
},
},
},
Policy: "policy",
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 37 additions & 31 deletions config/crd/bases/appstudio.redhat.com_releaseplanadmissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,53 +66,59 @@ spec:
from
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
pipelineRef:
description: PipelineRef is a reference to the Pipeline to be executed
by the managed Release PipelineRun
pipeline:
description: Pipeline contains all the information about the managed
Pipeline
properties:
params:
description: Params is a slice of parameters for a given resolver
items:
description: Param defines the parameters for a given resolver
in PipelineRef
properties:
name:
description: Name is the name of the parameter
type: string
value:
description: Value is the value of the parameter
type: string
required:
- name
- value
type: object
type: array
resolver:
description: Resolver is the name of a Tekton resolver to be used
(e.g. git)
pipelineRef:
description: PipelineRef is the reference to the Pipeline
properties:
params:
description: Params is a slice of parameters for a given resolver
items:
description: Param defines the parameters for a given resolver
in PipelineRef
properties:
name:
description: Name is the name of the parameter
type: string
value:
description: Value is the value of the parameter
type: string
required:
- name
- value
type: object
type: array
resolver:
description: Resolver is the name of a Tekton resolver to
be used (e.g. git)
type: string
required:
- params
- resolver
type: object
serviceAccountName:
description: ServiceAccount is the ServiceAccount to use during
the execution of the Pipeline
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
timeout:
default: "0"
description: Timeout is value to use to override the tekton default
Pipelinerun timeout
type: string
required:
- params
- resolver
- pipelineRef
type: object
policy:
description: Policy to validate before releasing an artifact
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
serviceAccount:
description: ServiceAccount is the name of the service account to
use in the managed Release PipelineRun to gain elevated privileges
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
- applications
- origin
- pipelineRef
- pipeline
- policy
type: object
status:
Expand Down
5 changes: 0 additions & 5 deletions config/crd/bases/appstudio.redhat.com_releaseplans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ spec:
description: Resolver is the name of a Tekton resolver to be used
(e.g. git)
type: string
timeout:
default: "0"
description: Timeout is value to use to override the tekton default
Pipelinerun timeout
type: string
required:
- params
- resolver
Expand Down
10 changes: 5 additions & 5 deletions controllers/release/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ func (a *adapter) createManagedPipelineRun(resources *loader.ProcessingResources
WithOwner(a.release).
WithReleaseAndApplicationMetadata(a.release, resources.Snapshot.Spec.Application).
WithWorkspace(os.Getenv("DEFAULT_RELEASE_WORKSPACE_NAME"), os.Getenv("DEFAULT_RELEASE_PVC")).
WithServiceAccount(resources.ReleasePlanAdmission.Spec.ServiceAccount).
WithTimeout(resources.ReleasePlanAdmission.Spec.PipelineRef.Timeout).
WithPipelineRef(resources.ReleasePlanAdmission.Spec.PipelineRef.ToTektonPipelineRef()).
WithTaskGitPipelineParameters(resources.ReleasePlanAdmission.Spec.PipelineRef).
WithServiceAccount(resources.ReleasePlanAdmission.Spec.Pipeline.ServiceAccount).
WithTimeout(resources.ReleasePlanAdmission.Spec.Pipeline.Timeout).
WithPipelineRef(resources.ReleasePlanAdmission.Spec.Pipeline.PipelineRef.ToTektonPipelineRef()).
WithTaskGitPipelineParameters(&resources.ReleasePlanAdmission.Spec.Pipeline.PipelineRef).
WithEnterpriseContractConfigMap(resources.EnterpriseContractConfigMap).
WithEnterpriseContractPolicy(resources.EnterpriseContractPolicy).
AsPipelineRun()
Expand Down Expand Up @@ -621,7 +621,7 @@ func (a *adapter) validatePipelineRef() *controller.ValidationResult {
return &controller.ValidationResult{Err: err}
}

if !a.releaseServiceConfig.Spec.Debug && releasePlanAdmission.Spec.PipelineRef.IsClusterScoped() {
if !a.releaseServiceConfig.Spec.Debug && releasePlanAdmission.Spec.Pipeline.PipelineRef.IsClusterScoped() {
a.release.MarkValidationFailed("tried using debug only options while debug mode is disabled in the ReleaseServiceConfig")
return &controller.ValidationResult{Valid: false}
}
Expand Down
46 changes: 26 additions & 20 deletions controllers/release/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,14 @@ var _ = Describe("Release adapter", Ordered, func() {
Spec: v1alpha1.ReleasePlanAdmissionSpec{
Applications: []string{"app"},
Origin: "default",
PipelineRef: &tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
Pipeline: &tektonutils.Pipeline{
PipelineRef: tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
},
},
},
Policy: enterpriseContractPolicy.Name,
Expand Down Expand Up @@ -879,7 +881,7 @@ var _ = Describe("Release adapter", Ordered, func() {
pipelineUrl = resolverParams[i].Value.StringVal
}
}
Expect(pipelineUrl).To(Equal(releasePlanAdmission.Spec.PipelineRef.Params[0].Value))
Expect(pipelineUrl).To(Equal(releasePlanAdmission.Spec.Pipeline.PipelineRef.Params[0].Value))
})

It("contains a parameter with the taskGitUrl", func() {
Expand Down Expand Up @@ -907,7 +909,7 @@ var _ = Describe("Release adapter", Ordered, func() {
})

It("contains the proper timeout value", func() {
timeout := releasePlanAdmission.Spec.PipelineRef.Timeout
timeout := releasePlanAdmission.Spec.Pipeline.Timeout
Expect(pipelineRun.Spec.Timeouts.Pipeline.Duration.String()).To(Equal(string(timeout)))
})

Expand Down Expand Up @@ -1548,12 +1550,14 @@ var _ = Describe("Release adapter", Ordered, func() {
Applications: []string{application.Name},
Origin: "default",
Environment: environment.Name,
PipelineRef: &tektonutils.PipelineRef{
Resolver: "cluster",
Params: []tektonutils.Param{
{Name: "name", Value: "release-pipeline"},
{Name: "namespace", Value: "default"},
{Name: "kind", Value: "pipeline"},
Pipeline: &tektonutils.Pipeline{
PipelineRef: tektonutils.PipelineRef{
Resolver: "cluster",
Params: []tektonutils.Param{
{Name: "name", Value: "release-pipeline"},
{Name: "namespace", Value: "default"},
{Name: "kind", Value: "pipeline"},
},
},
},
Policy: enterpriseContractPolicy.Name,
Expand Down Expand Up @@ -1712,12 +1716,14 @@ var _ = Describe("Release adapter", Ordered, func() {
Applications: []string{application.Name},
Origin: "default",
Environment: environment.Name,
PipelineRef: &tektonutils.PipelineRef{
Resolver: "git",
Params: []tektonutils.Param{
{Name: "url", Value: "my-url"},
{Name: "revision", Value: "my-revision"},
{Name: "pathInRepo", Value: "my-path"},
Pipeline: &tektonutils.Pipeline{
PipelineRef: tektonutils.PipelineRef{
Resolver: "git",
Params: []tektonutils.Param{
{Name: "url", Value: "my-url"},
{Name: "revision", Value: "my-revision"},
{Name: "pathInRepo", Value: "my-path"},
},
},
Timeout: "2h0m0s",
},
Expand Down
16 changes: 9 additions & 7 deletions controllers/releaseplan/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,17 @@ var _ = Describe("ReleasePlan adapter", Ordered, func() {
Spec: v1alpha1.ReleasePlanAdmissionSpec{
Applications: []string{application.Name},
Origin: "default",
Policy: "policy",
PipelineRef: &tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
Pipeline: &tektonutils.Pipeline{
PipelineRef: tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
},
},
},
Policy: "policy",
},
}
Expect(k8sClient.Create(ctx, releasePlanAdmission)).To(Succeed())
Expand Down
16 changes: 9 additions & 7 deletions controllers/releaseplanadmission/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,17 @@ var _ = Describe("ReleasePlanAdmission adapter", Ordered, func() {
Spec: v1alpha1.ReleasePlanAdmissionSpec{
Applications: []string{"application"},
Origin: "default",
Policy: "policy",
PipelineRef: &tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
Pipeline: &tektonutils.Pipeline{
PipelineRef: tektonutils.PipelineRef{
Resolver: "bundles",
Params: []tektonutils.Param{
{Name: "bundle", Value: "quay.io/some/bundle"},
{Name: "name", Value: "release-pipeline"},
{Name: "kind", Value: "pipeline"},
},
},
},
Policy: "policy",
},
}
Expect(k8sClient.Create(ctx, releasePlanAdmission)).To(Succeed())
Expand Down
Loading

0 comments on commit 6368064

Please sign in to comment.