Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClusterTask new CRD #312

Merged
merged 2 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
buildInformerFactory := buildinformers.NewSharedInformerFactory(buildClient, opt.ResyncPeriod)

taskInformer := pipelineInformerFactory.Pipeline().V1alpha1().Tasks()
clusterTaskInformer := pipelineInformerFactory.Pipeline().V1alpha1().ClusterTasks()
taskRunInformer := pipelineInformerFactory.Pipeline().V1alpha1().TaskRuns()
resourceInformer := pipelineInformerFactory.Pipeline().V1alpha1().PipelineResources()
buildInformer := buildInformerFactory.Build().V1alpha1().Builds()
Expand All @@ -124,13 +125,15 @@ func main() {
taskrun.NewController(opt,
taskRunInformer,
taskInformer,
clusterTaskInformer,
buildInformer,
resourceInformer,
),
pipelinerun.NewController(opt,
pipelineRunInformer,
pipelineInformer,
taskInformer,
clusterTaskInformer,
taskRunInformer,
resourceInformer,
),
Expand All @@ -150,6 +153,7 @@ func main() {
logger.Info("Waiting for informer caches to sync")
for i, synced := range []cache.InformerSynced{
taskInformer.Informer().HasSynced,
clusterTaskInformer.Informer().HasSynced,
taskRunInformer.Informer().HasSynced,
buildInformer.Informer().HasSynced,
resourceInformer.Informer().HasSynced,
Expand Down
2 changes: 1 addition & 1 deletion config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rules:
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["pipeline.knative.dev"]
resources: ["tasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources"]
resources: ["tasks", "clustertasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["build.knative.dev"]
resources: ["builds", "buildtemplates", "clusterbuildtemplates"]
Expand Down
28 changes: 28 additions & 0 deletions config/300-clustertask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: clustertasks.pipeline.knative.dev
spec:
group: pipeline.knative.dev
names:
kind: ClusterTask
plural: clustertasks
categories:
- all
- knative
- build-pipeline
scope: Cluster
version: v1alpha1
16 changes: 13 additions & 3 deletions config/300-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: pipelines.pipeline.knative.dev
spec:
group: pipeline.knative.dev
Expand Down
16 changes: 13 additions & 3 deletions config/300-pipelinerun.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: pipelineruns.pipeline.knative.dev
spec:
group: pipeline.knative.dev
Expand Down
16 changes: 13 additions & 3 deletions config/300-resource.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: pipelineresources.pipeline.knative.dev
spec:
group: pipeline.knative.dev
Expand Down
16 changes: 13 additions & 3 deletions config/300-task.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: tasks.pipeline.knative.dev
spec:
group: pipeline.knative.dev
Expand Down
16 changes: 13 additions & 3 deletions config/300-taskrun.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Copyright 2018 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: taskruns.pipeline.knative.dev
spec:
group: pipeline.knative.dev
Expand Down
5 changes: 5 additions & 0 deletions docs/Concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ pull in your environment, so we provide a way for you to configure that by edit
the `image`'s value in a configmap named
[`config-entrypoint`](./../config/config-entrypoint.yaml).

### Cluster Task

Similar to `Task` but with a cluster-wide scope. Cluster Tasks are available in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide some examples of Cluster tasks to users? Like what kind of tasks could be cluster task Vs a normal Task.
Why shdn't all tasks be cluster tasks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejal29 any task can be a ClusterTask, it depends on how operators set up their clusters, if they want their users to just use standard tasks available for everybody in all namespaces, or want users to setup their own. It is similar to ClusterBuildTemplates and BuildTemplates in Build

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing that i noticed in the most recent user study is that i think we've started mixing some of our using docs into the concepts docs - I'd like to move some of the stuff we've got in concepts.md out and keep this doc pretty short and sweet, just about the high level concepts

something we can iterate on tho! and i think it might make sense to write up some guidelines on which docs go where 🤔

all namespaces, typically used to conveniently provide commonly used tasks to users.

### Pipeline

`Pipelines` describes a graph of [Tasks](#Task) to execute.
Expand Down
23 changes: 23 additions & 0 deletions docs/using.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ To access a `Param`, replace `resources` with `params` as below:
${inputs.params.NAME}
```

## Cluster Task

Similar to Task, but with a cluster scope.

In case of using a ClusterTask, the `TaskRef` kind should be added. The default kind is Task
which represents a namespaced Task

```yaml
apiVersion: pipeline.knative.dev/v1alpha1
kind: Pipeline
metadata:
name: demo-pipeline
namespace: default
spec:
tasks:
- name: build-skaffold-web
taskRef:
name: build-push
kind: ClusterTask
params:
....
```

## Running a Pipeline

In order to run a Pipeline, you will need to provide:
Expand Down
72 changes: 72 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cluster_task_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2018 The Knative Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/knative/pkg/apis"
"github.com/knative/pkg/webhook"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (t *ClusterTask) TaskSpec() TaskSpec {
return t.Spec
}

func (t *ClusterTask) TaskMetadata() metav1.ObjectMeta {
return t.ObjectMeta
}

func (t *ClusterTask) Copy() TaskInterface {
return t.DeepCopy()
}

func (t *ClusterTask) SetDefaults() {
t.Spec.SetDefaults()
}

// Check that Task may be validated and defaulted.
var _ apis.Validatable = (*ClusterTask)(nil)
var _ apis.Defaultable = (*ClusterTask)(nil)

// Assert that Task implements the GenericCRD interface.
var _ webhook.GenericCRD = (*ClusterTask)(nil)

// +genclient
// +genclient:noStatus
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterTask is a Task with a cluster scope
type ClusterTask struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec holds the desired state of the Task from the client
// +optional
Spec TaskSpec `json:"spec,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterTaskList contains a list of ClusterTask
type ClusterTaskList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterTask `json:"items"`
}
28 changes: 28 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cluster_task_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2018 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/knative/pkg/apis"
)

func (t *ClusterTask) Validate() *apis.FieldError {
if err := validateObjectMetadata(t.GetObjectMeta()); err != nil {
return err.ViaField("metadata")
}
return t.Spec.Validate()
}
8 changes: 7 additions & 1 deletion pkg/apis/pipeline/v1alpha1/pipeline_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ func (p *Pipeline) SetDefaults() {
p.Spec.SetDefaults()
}

func (ps *PipelineSpec) SetDefaults() {}
func (ps *PipelineSpec) SetDefaults() {
for _, pt := range ps.Tasks {
if pt.TaskRef.Kind == "" {
pt.TaskRef.Kind = NamespacedTaskKind
}
}
}
12 changes: 12 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ type PipelineStatus struct {
var _ apis.Validatable = (*Pipeline)(nil)
var _ apis.Defaultable = (*Pipeline)(nil)

// TaskKind defines the type of Task used by the pipeline.
type TaskKind string

const (
// NamespacedTaskKind indicates that the task type has a namepace scope.
NamespacedTaskKind TaskKind = "Task"
// ClusterTaskKind indicates that task type has a cluster scope.
ClusterTaskKind TaskKind = "ClusterTask"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down Expand Up @@ -90,6 +100,8 @@ type ResourceDependency struct {
type TaskRef struct {
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name"`
// TaskKind inficates the kind of the task, namespaced or cluster scoped.
Kind TaskKind `json:"kind,omitempty"`
// API version of the referent
// +optional
APIVersion string `json:"apiVersion,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Task{},
&TaskList{},
&ClusterTask{},
&ClusterTaskList{},
&TaskRun{},
&TaskRunList{},
&Pipeline{},
Expand Down
Loading