Skip to content

Commit

Permalink
Change signature on GetOwnerReference
Browse files Browse the repository at this point in the history
A small refactoring of PipelineRun function. Change signature so it corresponds with the name.
From:

    func (pr *PipelineRun) GetOwnerReference() []metav1.OwnerReference

To:

    func (pr *PipelineRun) GetOwnerReference() metav1.OwnerReference

 This signature change leads to more _idiomatic code_ and avoids code like:

     pr.GetOwnerReference()[0]

 to be replaced with:

     pr.GetOwnerReference()

 This is a small Go function API change, but it does not change the type structure API (e.g. Yaml). Code that before this change used

     pr.GetOwnerReference()

 need to change the function call to

     []metav1.OwnerReference{pr.GetOwnerReference()}
  • Loading branch information
jlpettersson authored and tekton-robot committed Apr 15, 2020
1 parent 5d9c881 commit dc0a8b9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
6 changes: 2 additions & 4 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ func (pr *PipelineRun) GetTaskRunRef() corev1.ObjectReference {
}

// GetOwnerReference gets the pipeline run as owner reference for any related objects
func (pr *PipelineRun) GetOwnerReference() []metav1.OwnerReference {
return []metav1.OwnerReference{
*metav1.NewControllerRef(pr, groupVersionKind),
}
func (pr *PipelineRun) GetOwnerReference() metav1.OwnerReference {
return *metav1.NewControllerRef(pr, groupVersionKind)
}

// IsDone returns true if the PipelineRun's status indicates that it is done.
Expand Down
6 changes: 2 additions & 4 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ func (pr *PipelineRun) GetTaskRunRef() corev1.ObjectReference {
}

// GetOwnerReference gets the pipeline run as owner reference for any related objects
func (pr *PipelineRun) GetOwnerReference() []metav1.OwnerReference {
return []metav1.OwnerReference{
*metav1.NewControllerRef(pr, groupVersionKind),
}
func (pr *PipelineRun) GetOwnerReference() metav1.OwnerReference {
return *metav1.NewControllerRef(pr, groupVersionKind)
}

// IsDone returns true if the PipelineRun's status indicates that it is done.
Expand Down
2 changes: 1 addition & 1 deletion pkg/artifacts/artifact_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var (

func GetPersistentVolumeClaim(size string, storageClassName *string) *corev1.PersistentVolumeClaim {
pvc := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{Name: "pipelineruntest-pvc", Namespace: pipelinerun.Namespace, OwnerReferences: pipelinerun.GetOwnerReference()},
ObjectMeta: metav1.ObjectMeta{Name: "pipelineruntest-pvc", Namespace: pipelinerun.Namespace, OwnerReferences: []metav1.OwnerReference{pipelinerun.GetOwnerReference()}},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse(size)}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/artifacts/artifacts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func GetPVCSpec(pr *v1alpha1.PipelineRun, pvcSize resource.Quantity, storageClas
ObjectMeta: metav1.ObjectMeta{
Namespace: pr.Namespace,
Name: GetPVCName(pr),
OwnerReferences: pr.GetOwnerReference(),
OwnerReferences: []metav1.OwnerReference{pr.GetOwnerReference()},
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Expand Down
8 changes: 4 additions & 4 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er

if pipelineState.IsBeforeFirstTaskRun() && pr.HasVolumeClaimTemplate() {
// create workspace PVC from template
if err = c.pvcHandler.CreatePersistentVolumeClaimsForWorkspaces(pr.Spec.Workspaces, pr.GetOwnerReference()[0], pr.Namespace); err != nil {
if err = c.pvcHandler.CreatePersistentVolumeClaimsForWorkspaces(pr.Spec.Workspaces, pr.GetOwnerReference(), pr.Namespace); err != nil {
c.Logger.Errorf("Failed to create PVC for PipelineRun %s: %v", pr.Name, err)
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Expand Down Expand Up @@ -708,7 +708,7 @@ func (c *Reconciler) createTaskRun(rprt *resources.ResolvedPipelineRunTask, pr *
ObjectMeta: metav1.ObjectMeta{
Name: rprt.TaskRunName,
Namespace: pr.Namespace,
OwnerReferences: pr.GetOwnerReference(),
OwnerReferences: []metav1.OwnerReference{pr.GetOwnerReference()},
Labels: getTaskrunLabels(pr, rprt.PipelineTask.Name),
Annotations: getTaskrunAnnotations(pr),
},
Expand All @@ -735,7 +735,7 @@ func (c *Reconciler) createTaskRun(rprt *resources.ResolvedPipelineRunTask, pr *
for _, ws := range rprt.PipelineTask.Workspaces {
taskWorkspaceName, pipelineWorkspaceName := ws.Name, ws.Workspace
if b, hasBinding := pipelineRunWorkspaces[pipelineWorkspaceName]; hasBinding {
tr.Spec.Workspaces = append(tr.Spec.Workspaces, taskWorkspaceByWorkspaceVolumeSource(b, taskWorkspaceName, pr.GetOwnerReference()[0]))
tr.Spec.Workspaces = append(tr.Spec.Workspaces, taskWorkspaceByWorkspaceVolumeSource(b, taskWorkspaceName, pr.GetOwnerReference()))
} else {
return nil, fmt.Errorf("expected workspace %q to be provided by pipelinerun for pipeline task %q", pipelineWorkspaceName, rprt.PipelineTask.Name)
}
Expand Down Expand Up @@ -887,7 +887,7 @@ func (c *Reconciler) makeConditionCheckContainer(rprt *resources.ResolvedPipelin
ObjectMeta: metav1.ObjectMeta{
Name: rcc.ConditionCheckName,
Namespace: pr.Namespace,
OwnerReferences: pr.GetOwnerReference(),
OwnerReferences: []metav1.OwnerReference{pr.GetOwnerReference()},
Labels: labels,
Annotations: getTaskrunAnnotations(pr), // Propagate annotations from PipelineRun to TaskRun.
},
Expand Down

0 comments on commit dc0a8b9

Please sign in to comment.