Skip to content

Commit

Permalink
Add functions to v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpettersson committed Apr 9, 2020
1 parent 04b877c commit e7cdea6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Expand Up @@ -130,6 +130,17 @@ func (pr *PipelineRun) GetServiceAccountName(pipelineTaskName string) string {
return serviceAccountName
}

// HasVolumeClaimTemplate returns true if PipelineRun contains volumeClaimTemplates that is
// used for creating PersistentVolumeClaims with an OwnerReference for each run
func (pr *PipelineRun) HasVolumeClaimTemplate() bool {
for _, ws := range pr.Spec.Workspaces {
if ws.VolumeClaimTemplate != nil {
return true
}
}
return false
}

// PipelineRunSpec defines the desired state of PipelineRun
type PipelineRunSpec struct {
// +optional
Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go
Expand Up @@ -130,6 +130,25 @@ func TestPipelineRunIsCancelled(t *testing.T) {
}
}

func TestPipelineRunHasVolumeClaimTemplate(t *testing.T) {
pr := &v1beta1.PipelineRun{
Spec: v1beta1.PipelineRunSpec{
Workspaces: []v1beta1.WorkspaceBinding{{
Name: "my-workspace",
VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "pvc",
},
Spec: corev1.PersistentVolumeClaimSpec{},
},
}},
},
}
if !pr.HasVolumeClaimTemplate() {
t.Fatal("Expected pipelinerun to have a volumeClaimTemplate workspace")
}
}

func TestPipelineRunKey(t *testing.T) {
pr := tb.PipelineRun("prunname", "testns")
expectedKey := fmt.Sprintf("PipelineRun/%p", pr)
Expand Down
25 changes: 25 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Expand Up @@ -23,10 +23,19 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

var (
taskRunGroupVersionKind = schema.GroupVersionKind{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Kind: pipeline.TaskRunControllerName,
}
)

// TaskRunSpec defines the desired state of TaskRun
type TaskRunSpec struct {
// +optional
Expand Down Expand Up @@ -163,6 +172,11 @@ type TaskRunResult struct {
Value string `json:"value"`
}

// GetOwnerReference gets the task run as owner reference for any related objects
func (tr *TaskRun) GetOwnerReference() metav1.OwnerReference {
return *metav1.NewControllerRef(tr, taskRunGroupVersionKind)
}

// GetCondition returns the Condition matching the given type.
func (trs *TaskRunStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return taskRunCondSet.Manage(trs).GetCondition(t)
Expand Down Expand Up @@ -338,3 +352,14 @@ func (tr *TaskRun) IsPartOfPipeline() (bool, string, string) {

return false, "", ""
}

// HasVolumeClaimTemplate returns true if TaskRun contains volumeClaimTemplates that is
// used for creating PersistentVolumeClaims with an OwnerReference for each run
func (tr *TaskRun) HasVolumeClaimTemplate() bool {
for _, ws := range tr.Spec.Workspaces {
if ws.VolumeClaimTemplate != nil {
return true
}
}
return false
}
19 changes: 19 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_types_test.go
Expand Up @@ -151,6 +151,25 @@ func TestTaskRunIsCancelled(t *testing.T) {
}
}

func TestTaskRunHasVolumeClaimTemplate(t *testing.T) {
tr := &v1beta1.TaskRun{
Spec: v1beta1.TaskRunSpec{
Workspaces: []v1beta1.WorkspaceBinding{{
Name: "my-workspace",
VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "pvc",
},
Spec: corev1.PersistentVolumeClaimSpec{},
},
}},
},
}
if !tr.HasVolumeClaimTemplate() {
t.Fatal("Expected taskrun to have a volumeClaimTemplate workspace")
}
}

func TestTaskRunKey(t *testing.T) {
tr := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit e7cdea6

Please sign in to comment.