Skip to content

Commit

Permalink
refactor(RHTAPREL-715): rename PipelineRun references
Browse files Browse the repository at this point in the history
Rename references to the release Pipeline{Run} to managed
Pipeline{Run}.

Signed-off-by: David Moreno García <[email protected]>
  • Loading branch information
davidmogar committed Dec 13, 2023
1 parent 8ee0f12 commit 5d4a501
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ TAG_NAME ?= next
CERT_MANAGER_VERSION ?= v1.8.0
ENABLE_WEBHOOKS ?= true

# DEFAULT_PERSISTENT_VOLUME_CLAIM defines the default PVC to be used in the Release pipeline workspace declaration.
# DEFAULT_PERSISTENT_VOLUME_CLAIM defines the default PVC to be used in the managed Release Pipeline workspace declaration.
DEFAULT_RELEASE_PVC ?= release-pvc

# DEFAULT_WORKSPACE_NAME defines the default name for the workspace that will be used in the Release pipeline.
# DEFAULT_WORKSPACE_NAME defines the default name for the workspace that will be used in the managed Release Pipeline.
DEFAULT_RELEASE_WORKSPACE_NAME ?= release-workspace

# CHANNELS define the bundle channels used in the bundle.
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/release_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ReleaseSpec struct {
// +required
ReleasePlan string `json:"releasePlan"`

// Data is an unstructured key used for providing data for the release Pipeline
// Data is an unstructured key used for providing data for the managed Release Pipeline
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Data *runtime.RawExtension `json:"data,omitempty"`
Expand Down Expand Up @@ -138,7 +138,7 @@ type ProcessingInfo struct {
// +optional
CompletionTime *metav1.Time `json:"completionTime,omitempty"`

// PipelineRun contains the namespaced name of the release PipelineRun executed as part of this release
// PipelineRun contains the namespaced name of the managed Release PipelineRun executed as part of this release
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?\/[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// +optional
PipelineRun string `json:"pipelineRun,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/releaseplan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ type ReleasePlanSpec struct {
// +required
Application string `json:"application"`

// Data is an unstructured key used for providing data for the release Pipeline
// Data is an unstructured key used for providing data for the managed Release Pipeline
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Data *runtime.RawExtension `json:"data,omitempty"`

// PipelineRef is an optional reference to a Pipeline that would be executed
// before the release Pipeline
// before the managed Release Pipeline
// +optional
PipelineRef *tektonutils.PipelineRef `json:"pipelineRef,omitempty"`

Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/releaseplanadmission_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ReleasePlanAdmissionSpec struct {
// +required
Applications []string `json:"applications"`

// Data is an unstructured key used for providing data for the release Pipeline
// Data is an unstructured key used for providing data for the managed Release Pipeline
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Data *runtime.RawExtension `json:"data,omitempty"`
Expand All @@ -49,7 +49,7 @@ type ReleasePlanAdmissionSpec struct {
// +required
Origin string `json:"origin"`

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

Expand All @@ -59,7 +59,7 @@ type ReleasePlanAdmissionSpec struct {
Policy string `json:"policy"`

// ServiceAccount is the name of the service account to use in the
// release PipelineRun to gain elevated privileges
// 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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spec:
type: array
data:
description: Data is an unstructured key used for providing data for
the release Pipeline
the managed Release Pipeline
type: object
x-kubernetes-preserve-unknown-fields: true
environment:
Expand All @@ -68,7 +68,7 @@ spec:
type: string
pipelineRef:
description: PipelineRef is a reference to the Pipeline to be executed
by the release PipelineRun
by the managed Release PipelineRun
properties:
params:
description: Params is a slice of parameters for a given resolver
Expand Down Expand Up @@ -106,7 +106,7 @@ spec:
type: string
serviceAccount:
description: ServiceAccount is the name of the service account to
use in the release PipelineRun to gain elevated privileges
use in the managed Release PipelineRun to gain elevated privileges
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/appstudio.redhat.com_releaseplans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ spec:
type: string
data:
description: Data is an unstructured key used for providing data for
the release Pipeline
the managed Release Pipeline
type: object
x-kubernetes-preserve-unknown-fields: true
pipelineRef:
description: PipelineRef is an optional reference to a Pipeline that
would be executed before the release Pipeline
would be executed before the managed Release Pipeline
properties:
params:
description: Params is a slice of parameters for a given resolver
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/appstudio.redhat.com_releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spec:
properties:
data:
description: Data is an unstructured key used for providing data for
the release Pipeline
the managed Release Pipeline
type: object
x-kubernetes-preserve-unknown-fields: true
releasePlan:
Expand Down Expand Up @@ -209,8 +209,8 @@ spec:
format: date-time
type: string
pipelineRun:
description: PipelineRun contains the namespaced name of the release
PipelineRun executed as part of this release
description: PipelineRun contains the namespaced name of the managed
Release PipelineRun executed as part of this release
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?\/[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
startTime:
Expand Down
26 changes: 13 additions & 13 deletions controllers/release/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ func (a *adapter) EnsureReleaseIsRunning() (controller.OperationResult, error) {
return controller.ContinueProcessing()
}

// EnsureReleaseIsProcessed is an operation that will ensure that a release PipelineRun associated to the Release
// being processed exists. Otherwise, it will create a new release PipelineRun.
// EnsureReleaseIsProcessed is an operation that will ensure that a managed Release PipelineRun associated to the Release
// being processed exists. Otherwise, it will create a new managed Release PipelineRun.
func (a *adapter) EnsureReleaseIsProcessed() (controller.OperationResult, error) {
if a.release.HasProcessingFinished() {
return controller.ContinueProcessing()
}

pipelineRun, err := a.loader.GetReleasePipelineRun(a.ctx, a.client, a.release)
pipelineRun, err := a.loader.GetManagedReleasePipelineRun(a.ctx, a.client, a.release)
if err != nil && !errors.IsNotFound(err) {
return controller.RequeueWithError(err)
}
Expand All @@ -263,12 +263,12 @@ func (a *adapter) EnsureReleaseIsProcessed() (controller.OperationResult, error)
}

if pipelineRun == nil {
pipelineRun, err = a.createReleasePipelineRun(resources)
pipelineRun, err = a.createManagedPipelineRun(resources)
if err != nil {
return controller.RequeueWithError(err)
}

a.logger.Info("Created release PipelineRun",
a.logger.Info("Created managed Release PipelineRun",
"PipelineRun.Name", pipelineRun.Name, "PipelineRun.Namespace", pipelineRun.Namespace)
}

Expand Down Expand Up @@ -300,14 +300,14 @@ func (a *adapter) EnsureReleaseIsValid() (controller.OperationResult, error) {
return controller.RequeueOnErrorOrStop(a.client.Status().Patch(a.ctx, a.release, patch))
}

// EnsureReleaseProcessingIsTracked is an operation that will ensure that the release PipelineRun status is tracked
// EnsureReleaseProcessingIsTracked is an operation that will ensure that the managed Release PipelineRun status is tracked
// in the Release being processed.
func (a *adapter) EnsureReleaseProcessingIsTracked() (controller.OperationResult, error) {
if !a.release.IsProcessing() || a.release.HasProcessingFinished() {
return controller.ContinueProcessing()
}

pipelineRun, err := a.loader.GetReleasePipelineRun(a.ctx, a.client, a.release)
pipelineRun, err := a.loader.GetManagedReleasePipelineRun(a.ctx, a.client, a.release)
if err != nil {
return controller.RequeueWithError(err)
}
Expand All @@ -331,12 +331,12 @@ func (a *adapter) EnsureReleaseProcessingIsTracked() (controller.OperationResult
return controller.ContinueProcessing()
}

// createReleasePipelineRun creates and returns a new release PipelineRun. The new PipelineRun will include owner
// createManagedPipelineRun creates and returns a new managed Release PipelineRun. The new PipelineRun will include owner
// annotations, so it triggers Release reconciles whenever it changes. The Pipeline information and the parameters to it
// will be extracted from the given ReleaseStrategy. The Release's Snapshot will also be passed to the release
// PipelineRun.
func (a *adapter) createReleasePipelineRun(resources *loader.ProcessingResources) (*tektonv1.PipelineRun, error) {
pipelineRun := tekton.NewReleasePipelineRun("release-pipelinerun", resources.ReleasePlanAdmission.Namespace).
func (a *adapter) createManagedPipelineRun(resources *loader.ProcessingResources) (*tektonv1.PipelineRun, error) {
pipelineRun := tekton.NewReleasePipelineRun("managed-release", resources.ReleasePlanAdmission.Namespace).
WithObjectReferences(a.release, resources.ReleasePlan,
resources.ReleasePlanAdmission, resources.Snapshot).
WithOwner(a.release).
Expand Down Expand Up @@ -406,7 +406,7 @@ func (a *adapter) createOrUpdateSnapshotEnvironmentBinding(releasePlanAdmission

// finalizeRelease will finalize the Release being processed, removing the associated resources.
func (a *adapter) finalizeRelease() error {
pipelineRun, err := a.loader.GetReleasePipelineRun(a.ctx, a.client, a.release)
pipelineRun, err := a.loader.GetManagedReleasePipelineRun(a.ctx, a.client, a.release)
if err != nil {
return err
}
Expand Down Expand Up @@ -516,7 +516,7 @@ func (a *adapter) registerProcessingData(releasePipelineRun *tektonv1.PipelineRu
}

// registerProcessingStatus updates the status of the Release being processed by monitoring the status of the
// associated release PipelineRun and setting the appropriate state in the Release. If the PipelineRun hasn't
// associated managed Release PipelineRun and setting the appropriate state in the Release. If the PipelineRun hasn't
// started/succeeded, no action will be taken.
func (a *adapter) registerProcessingStatus(pipelineRun *tektonv1.PipelineRun) error {
if pipelineRun != nil && pipelineRun.IsDone() {
Expand Down Expand Up @@ -609,7 +609,7 @@ func (a *adapter) validateProcessingResources() *controller.ValidationResult {
return &controller.ValidationResult{Valid: true}
}

// validatePipelineRef checks that the release PipelineRun ref passes the checks from the ReleaseServiceConfig.
// validatePipelineRef checks that the managed Release PipelineRun ref passes the checks from the ReleaseServiceConfig.
func (a *adapter) validatePipelineRef() *controller.ValidationResult {
releasePlanAdmission, err := a.loader.GetActiveReleasePlanAdmissionFromRelease(a.ctx, a.client, a.release)
if err != nil {
Expand Down
15 changes: 8 additions & 7 deletions controllers/release/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var _ = Describe("Release adapter", Ordered, func() {
Expect(result.RequeueRequest && !result.CancelRequest).To(BeTrue())
Expect(err).NotTo(HaveOccurred())

pipelineRun, err := adapter.loader.GetReleasePipelineRun(adapter.ctx, adapter.client, adapter.release)
pipelineRun, err := adapter.loader.GetManagedReleasePipelineRun(adapter.ctx, adapter.client, adapter.release)
Expect(pipelineRun).To(Or(BeNil(), HaveField("DeletionTimestamp", Not(BeNil()))))
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -646,7 +646,7 @@ var _ = Describe("Release adapter", Ordered, func() {
Expect(err).NotTo(HaveOccurred())
Expect(adapter.release.IsProcessing()).To(BeTrue())

pipelineRun, err := adapter.loader.GetReleasePipelineRun(adapter.ctx, adapter.client, adapter.release)
pipelineRun, err := adapter.loader.GetManagedReleasePipelineRun(adapter.ctx, adapter.client, adapter.release)
Expect(pipelineRun).NotTo(BeNil())
Expect(err).NotTo(HaveOccurred())
Expect(adapter.client.Delete(adapter.ctx, pipelineRun)).To(Succeed())
Expand Down Expand Up @@ -802,7 +802,7 @@ var _ = Describe("Release adapter", Ordered, func() {
})
})

When("createReleasePipelineRun is called", func() {
When("createManagedPipelineRun is called", func() {
var (
adapter *adapter
pipelineRun *tektonv1.PipelineRun
Expand All @@ -825,13 +825,14 @@ var _ = Describe("Release adapter", Ordered, func() {
}

var err error
pipelineRun, err = adapter.createReleasePipelineRun(resources)
pipelineRun, err = adapter.createManagedPipelineRun(resources)
Expect(pipelineRun).NotTo(BeNil())
Expect(err).NotTo(HaveOccurred())
})

It("returns a PipelineRun", func() {
It("returns a PipelineRun with the right prefix", func() {
Expect(reflect.TypeOf(pipelineRun)).To(Equal(reflect.TypeOf(&tektonv1.PipelineRun{})))
Expect(pipelineRun.Name).To(HavePrefix("managed-release"))
})

It("has the release reference", func() {
Expand Down Expand Up @@ -1003,12 +1004,12 @@ var _ = Describe("Release adapter", Ordered, func() {
EnterpriseContractPolicy: enterpriseContractPolicy,
Snapshot: snapshot,
}
pipelineRun, err := adapter.createReleasePipelineRun(resources)
pipelineRun, err := adapter.createManagedPipelineRun(resources)
Expect(pipelineRun).NotTo(BeNil())
Expect(err).NotTo(HaveOccurred())

Expect(adapter.finalizeRelease()).To(Succeed())
pipelineRun, err = adapter.loader.GetReleasePipelineRun(adapter.ctx, adapter.client, adapter.release)
pipelineRun, err = adapter.loader.GetManagedReleasePipelineRun(adapter.ctx, adapter.client, adapter.release)
Expect(err).NotTo(HaveOccurred())
Expect(pipelineRun).To(BeNil())
})
Expand Down
6 changes: 3 additions & 3 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ObjectLoader interface {
GetMatchingReleasePlanAdmission(ctx context.Context, cli client.Client, releasePlan *v1alpha1.ReleasePlan) (*v1alpha1.ReleasePlanAdmission, error)
GetMatchingReleasePlans(ctx context.Context, cli client.Client, releasePlanAdmission *v1alpha1.ReleasePlanAdmission) (*v1alpha1.ReleasePlanList, error)
GetRelease(ctx context.Context, cli client.Client, name, namespace string) (*v1alpha1.Release, error)
GetReleasePipelineRun(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*tektonv1.PipelineRun, error)
GetManagedReleasePipelineRun(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*tektonv1.PipelineRun, error)
GetReleasePlan(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*v1alpha1.ReleasePlan, error)
GetReleaseServiceConfig(ctx context.Context, cli client.Client, name, namespace string) (*v1alpha1.ReleaseServiceConfig, error)
GetSnapshot(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*applicationapiv1alpha1.Snapshot, error)
Expand Down Expand Up @@ -207,9 +207,9 @@ func (l *loader) GetRelease(ctx context.Context, cli client.Client, name, namesp
return release, toolkit.GetObject(name, namespace, cli, ctx, release)
}

// GetReleasePipelineRun returns the PipelineRun referenced by the given Release or nil if it's not found. In the case
// GetManagedReleasePipelineRun returns the managed Release PipelineRun referenced by the given Release or nil if it's not found. In the case
// the List operation fails, an error will be returned.
func (l *loader) GetReleasePipelineRun(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*tektonv1.PipelineRun, error) {
func (l *loader) GetManagedReleasePipelineRun(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*tektonv1.PipelineRun, error) {
pipelineRuns := &tektonv1.PipelineRunList{}
err := cli.List(ctx, pipelineRuns,
client.Limit(1),
Expand Down
6 changes: 3 additions & 3 deletions loader/loader_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func (l *mockLoader) GetRelease(ctx context.Context, cli client.Client, name, na
return toolkit.GetMockedResourceAndErrorFromContext(ctx, ReleaseContextKey, &v1alpha1.Release{})
}

// GetReleasePipelineRun returns the resource and error passed as values of the context.
func (l *mockLoader) GetReleasePipelineRun(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*tektonv1.PipelineRun, error) {
// GetManagedReleasePipelineRun returns the resource and error passed as values of the context.
func (l *mockLoader) GetManagedReleasePipelineRun(ctx context.Context, cli client.Client, release *v1alpha1.Release) (*tektonv1.PipelineRun, error) {
if ctx.Value(ReleasePipelineRunContextKey) == nil {
return l.loader.GetReleasePipelineRun(ctx, cli, release)
return l.loader.GetManagedReleasePipelineRun(ctx, cli, release)
}
return toolkit.GetMockedResourceAndErrorFromContext(ctx, ReleasePipelineRunContextKey, &tektonv1.PipelineRun{})
}
Expand Down
4 changes: 2 additions & 2 deletions loader/loader_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ var _ = Describe("Release Adapter", Ordered, func() {
})
})

When("calling GetReleasePipelineRun", func() {
When("calling GetManagedReleasePipelineRun", func() {
It("returns the resource and error from the context", func() {
pipelineRun := &tektonv1.PipelineRun{}
mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{
Expand All @@ -179,7 +179,7 @@ var _ = Describe("Release Adapter", Ordered, func() {
Resource: pipelineRun,
},
})
resource, err := loader.GetReleasePipelineRun(mockContext, nil, nil)
resource, err := loader.GetManagedReleasePipelineRun(mockContext, nil, nil)
Expect(resource).To(Equal(pipelineRun))
Expect(err).To(BeNil())
})
Expand Down
6 changes: 3 additions & 3 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ var _ = Describe("Release Adapter", Ordered, func() {
})
})

When("calling GetReleasePipelineRun", func() {
When("calling GetManagedReleasePipelineRun", func() {
It("returns a PipelineRun if the labels match with the release data", func() {
returnedObject, err := loader.GetReleasePipelineRun(ctx, k8sClient, release)
returnedObject, err := loader.GetManagedReleasePipelineRun(ctx, k8sClient, release)
Expect(err).NotTo(HaveOccurred())
Expect(returnedObject).NotTo(Equal(&tektonv1.PipelineRun{}))
Expect(returnedObject.Name).To(Equal(pipelineRun.Name))
Expand All @@ -286,7 +286,7 @@ var _ = Describe("Release Adapter", Ordered, func() {
modifiedRelease := release.DeepCopy()
modifiedRelease.Name = "non-existing-release"

returnedObject, err := loader.GetReleasePipelineRun(ctx, k8sClient, modifiedRelease)
returnedObject, err := loader.GetManagedReleasePipelineRun(ctx, k8sClient, modifiedRelease)
Expect(err).NotTo(HaveOccurred())
Expect(returnedObject).To(BeNil())
})
Expand Down
2 changes: 1 addition & 1 deletion metadata/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
ReleasePlanAdmissionLabel = fmt.Sprintf("release.%s/releasePlanAdmission", rhtapDomain)
)

// Prefixes to be used by Release Pipeline Labels
// Prefixes to be used by Release Pipelines labels
var (
// pipelinesLabelPrefix is the prefix of the pipelines label
pipelinesLabelPrefix = fmt.Sprintf("pipelines.%s", rhtapDomain)
Expand Down
Loading

0 comments on commit 5d4a501

Please sign in to comment.