From 01e982ab0068c4dd06ab79cfb0af17712d6b5d8e Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Sat, 9 Oct 2021 15:42:17 -0700 Subject: [PATCH] Have `[Cluster]Task` and `Pipeline` implement `kmeta.OwnerRefable`. This is somewhat related to https://github.com/tektoncd/pipeline/pull/4293, in that a common thing to do one reconciling a certain primary resource is to hang child resources off of it. A simple example of this might be if you wanted to create Knative `Image` resources for the images in a `TaskRun` to direct a caching system to warm those images on builder nodes. --- pkg/apis/pipeline/controller.go | 10 ++++++++++ pkg/apis/pipeline/v1beta1/cluster_task_types.go | 10 ++++++++++ pkg/apis/pipeline/v1beta1/pipeline_types.go | 10 ++++++++++ pkg/apis/pipeline/v1beta1/task_types.go | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/pkg/apis/pipeline/controller.go b/pkg/apis/pipeline/controller.go index cc4cfdfc932..a21dbb05a41 100644 --- a/pkg/apis/pipeline/controller.go +++ b/pkg/apis/pipeline/controller.go @@ -21,9 +21,19 @@ const ( // nolint: revive PipelineRunControllerName = "PipelineRun" + // PipelineControllerName holds the name of the Pipeline controller + // nolint: revive + PipelineControllerName = "Pipeline" + // TaskRunControllerName holds the name of the TaskRun controller TaskRunControllerName = "TaskRun" + // TaskControllerName holds the name of the Task controller + TaskControllerName = "Task" + + // ClusterTaskControllerName holds the name of the Task controller + ClusterTaskControllerName = "ClusterTask" + // RuncControllerName holds the name of the Custom Task controller RunControllerName = "Run" ) diff --git a/pkg/apis/pipeline/v1beta1/cluster_task_types.go b/pkg/apis/pipeline/v1beta1/cluster_task_types.go index de5b61aaa6b..ff7763a5f9f 100644 --- a/pkg/apis/pipeline/v1beta1/cluster_task_types.go +++ b/pkg/apis/pipeline/v1beta1/cluster_task_types.go @@ -17,7 +17,10 @@ limitations under the License. package v1beta1 import ( + "github.com/tektoncd/pipeline/pkg/apis/pipeline" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/pkg/kmeta" ) // +genclient @@ -38,6 +41,8 @@ type ClusterTask struct { Spec TaskSpec `json:"spec,omitempty"` } +var _ kmeta.OwnerRefable = (*ClusterTask)(nil) + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // ClusterTaskList contains a list of ClusterTask @@ -59,3 +64,8 @@ func (t *ClusterTask) TaskMetadata() metav1.ObjectMeta { func (t *ClusterTask) Copy() TaskObject { return t.DeepCopy() } + +// GetGroupVersionKind implements kmeta.OwnerRefable. +func (*ClusterTask) GetGroupVersionKind() schema.GroupVersionKind { + return SchemeGroupVersion.WithKind(pipeline.ClusterTaskControllerName) +} diff --git a/pkg/apis/pipeline/v1beta1/pipeline_types.go b/pkg/apis/pipeline/v1beta1/pipeline_types.go index d7e26abc0ce..7ff72897bc8 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_types.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_types.go @@ -23,13 +23,16 @@ import ( "github.com/google/go-containerregistry/pkg/name" "github.com/tektoncd/pipeline/pkg/apis/config" + "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation" "knative.dev/pkg/apis" + "knative.dev/pkg/kmeta" ) const ( @@ -58,6 +61,8 @@ type Pipeline struct { Spec PipelineSpec `json:"spec"` } +var _ kmeta.OwnerRefable = (*Pipeline)(nil) + func (p *Pipeline) PipelineMetadata() metav1.ObjectMeta { return p.ObjectMeta } @@ -70,6 +75,11 @@ func (p *Pipeline) Copy() PipelineObject { return p.DeepCopy() } +// GetGroupVersionKind implements kmeta.OwnerRefable. +func (*Pipeline) GetGroupVersionKind() schema.GroupVersionKind { + return SchemeGroupVersion.WithKind(pipeline.PipelineControllerName) +} + // PipelineSpec defines the desired state of Pipeline. type PipelineSpec struct { // Description is a user-facing description of the pipeline that may be diff --git a/pkg/apis/pipeline/v1beta1/task_types.go b/pkg/apis/pipeline/v1beta1/task_types.go index 89d2224d957..095c87787ce 100644 --- a/pkg/apis/pipeline/v1beta1/task_types.go +++ b/pkg/apis/pipeline/v1beta1/task_types.go @@ -17,8 +17,11 @@ limitations under the License. package v1beta1 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/kmeta" ) const ( @@ -52,6 +55,8 @@ type Task struct { Spec TaskSpec `json:"spec"` } +var _ kmeta.OwnerRefable = (*Task)(nil) + func (t *Task) TaskSpec() TaskSpec { return t.Spec } @@ -64,6 +69,11 @@ func (t *Task) Copy() TaskObject { return t.DeepCopy() } +// GetGroupVersionKind implements kmeta.OwnerRefable. +func (*Task) GetGroupVersionKind() schema.GroupVersionKind { + return SchemeGroupVersion.WithKind(pipeline.TaskControllerName) +} + // TaskSpec defines the desired state of Task. type TaskSpec struct { // Resources is a list input and output resource to run the task