From f79d66981bcb9eecb369765c064015678376a930 Mon Sep 17 00:00:00 2001 From: Dibyo Mukherjee Date: Tue, 2 Jul 2019 17:23:33 -0400 Subject: [PATCH] Add APIs for Conditionals This commit adds the basic APIs for conditionals in Tekton: 1. Condition CRD defines a condition how a condition is evaluated i.e. the container spec and any input parameters. 2. The `Conditions` field in `PipelineTask` references `Condition` resources that have to pass before the task is executed. 3. The `ConditionChecks` field in `PipelineRun.Status.TaskRuns` surfaces the status of conditions that were evaluated for that particular task. --- config/200-clusterrole.yaml | 2 +- config/500-condition.yaml | 31 +++ pkg/apis/pipeline/v1alpha1/condition_types.go | 86 +++++++ .../pipeline/v1alpha1/condition_validation.go | 37 +++ .../v1alpha1/condition_validation_test.go | 48 ++++ pkg/apis/pipeline/v1alpha1/pipeline_types.go | 4 + .../pipeline/v1alpha1/pipelinerun_types.go | 11 + .../v1alpha1/zz_generated.deepcopy.go | 230 ++++++++++++++++++ .../typed/pipeline/v1alpha1/condition.go | 154 ++++++++++++ .../pipeline/v1alpha1/fake/fake_condition.go | 125 ++++++++++ .../v1alpha1/fake/fake_pipeline_client.go | 4 + .../pipeline/v1alpha1/generated_expansion.go | 2 + .../pipeline/v1alpha1/pipeline_client.go | 5 + .../informers/externalversions/generic.go | 2 + .../pipeline/v1alpha1/condition.go | 86 +++++++ .../pipeline/v1alpha1/interface.go | 7 + .../listers/pipeline/v1alpha1/condition.go | 91 +++++++ .../pipeline/v1alpha1/expansion_generated.go | 8 + 18 files changed, 932 insertions(+), 1 deletion(-) create mode 100644 config/500-condition.yaml create mode 100644 pkg/apis/pipeline/v1alpha1/condition_types.go create mode 100644 pkg/apis/pipeline/v1alpha1/condition_validation.go create mode 100644 pkg/apis/pipeline/v1alpha1/condition_validation_test.go create mode 100644 pkg/client/clientset/versioned/typed/pipeline/v1alpha1/condition.go create mode 100644 pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_condition.go create mode 100644 pkg/client/informers/externalversions/pipeline/v1alpha1/condition.go create mode 100644 pkg/client/listers/pipeline/v1alpha1/condition.go diff --git a/config/200-clusterrole.yaml b/config/200-clusterrole.yaml index ad18bf4be76..1ca30572693 100644 --- a/config/200-clusterrole.yaml +++ b/config/200-clusterrole.yaml @@ -16,7 +16,7 @@ rules: resources: ["mutatingwebhookconfigurations"] verbs: ["get", "list", "create", "update", "delete", "patch", "watch"] - apiGroups: ["tekton.dev"] - resources: ["tasks", "clustertasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources"] + resources: ["tasks", "clustertasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources", "conditions"] verbs: ["get", "list", "create", "update", "delete", "patch", "watch"] - apiGroups: ["tekton.dev"] resources: ["taskruns/finalizers", "pipelineruns/finalizers"] diff --git a/config/500-condition.yaml b/config/500-condition.yaml new file mode 100644 index 00000000000..cc41d128907 --- /dev/null +++ b/config/500-condition.yaml @@ -0,0 +1,31 @@ +# 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: conditions.tekton.dev +spec: + group: tekton.dev + names: + kind: Condition + plural: conditions + categories: + - all + - tekton-pipelines + scope: Namespaced + # Opt into the status subresource so metadata.generation + # starts to increment + subresources: + status: {} + version: v1alpha1 \ No newline at end of file diff --git a/pkg/apis/pipeline/v1alpha1/condition_types.go b/pkg/apis/pipeline/v1alpha1/condition_types.go new file mode 100644 index 00000000000..76f94ec11c6 --- /dev/null +++ b/pkg/apis/pipeline/v1alpha1/condition_types.go @@ -0,0 +1,86 @@ +/* + * + * Copyright 2019 The Tekton 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" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Add validation for TaskConditions? +type TaskCondition struct { + ConditionRef string `json:"conditionRef"` + // TODO: Support a ConditionSpec? + // +optional + Params []Param `json:"params,omitempty"` +} + +// Check that Task may be validated and defaulted. +var _ apis.Validatable = (*Condition)(nil) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Task represents a collection of sequential steps that are run as part of a +// Pipeline using a set of inputs and producing a set of outputs. Tasks execute +// when TaskRuns are created that provide the input parameters and resources and +// output resources the Task requires. +// +// +k8s:openapi-gen=true +type Condition struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata"` + + // Spec holds the desired state of the Condition from the client + // +optional + Spec ConditionSpec `json:"spec"` +} + +type ConditionSpec struct { + // +optional + Params []ParamSpec `json:"params,omitempty"` + // Check is a container whose exit code determines where a condition is true or false + Check corev1.Container `json:"check,omitempty"` +} + +type ConditionCheck TaskRun + +type ConditionCheckStatus TaskRunStatus + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ConditionList contains a list of Conditions +type ConditionList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + Items []Condition `json:"items"` +} + +func NewConditionCheck(tr *TaskRun) *ConditionCheck { + if tr == nil { + return nil + } + + cc := ConditionCheck(*tr) + return &cc +} \ No newline at end of file diff --git a/pkg/apis/pipeline/v1alpha1/condition_validation.go b/pkg/apis/pipeline/v1alpha1/condition_validation.go new file mode 100644 index 00000000000..b6513165376 --- /dev/null +++ b/pkg/apis/pipeline/v1alpha1/condition_validation.go @@ -0,0 +1,37 @@ +/* +Copyright 2019 The Tekton 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 ( + "context" + "github.com/knative/pkg/apis" + "k8s.io/apimachinery/pkg/api/equality" +) + +func (c *Condition) Validate(ctx context.Context) *apis.FieldError { + if err := validateObjectMetadata(c.GetObjectMeta()); err != nil { + return err.ViaField("metadata") + } + return c.Spec.Validate(ctx) +} + +func (cs *ConditionSpec) Validate(ctx context.Context) *apis.FieldError { + if equality.Semantic.DeepEqual(cs, &ConditionSpec{}) { + return apis.ErrMissingField(apis.CurrentField) + } + return nil +} diff --git a/pkg/apis/pipeline/v1alpha1/condition_validation_test.go b/pkg/apis/pipeline/v1alpha1/condition_validation_test.go new file mode 100644 index 00000000000..e790f3642a5 --- /dev/null +++ b/pkg/apis/pipeline/v1alpha1/condition_validation_test.go @@ -0,0 +1,48 @@ +/* + * + * Copyright 2019 The Tekton 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 ( + "context" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +func TestCondition_Validate(t *testing.T) { + c := Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskname", + }, + Spec: ConditionSpec{ + Check: corev1.Container{ + Name: "foo", + Image: "bar", + }, + Params: []ParamSpec{ + { + Name: "expected", + }, + }, + }, + } + if err := c.Validate(context.Background()); err != nil { + t.Errorf("TaskRun.Validate() error = %v", err) + } +} diff --git a/pkg/apis/pipeline/v1alpha1/pipeline_types.go b/pkg/apis/pipeline/v1alpha1/pipeline_types.go index 59d1f83cd3a..7cc80782d3d 100644 --- a/pkg/apis/pipeline/v1alpha1/pipeline_types.go +++ b/pkg/apis/pipeline/v1alpha1/pipeline_types.go @@ -83,6 +83,10 @@ type PipelineTask struct { // TaskRef is a reference to a task definition. TaskRef TaskRef `json:"taskRef"` + // Conditions is a list of conditions that need to be true for the task to run + // +optional + Conditions []TaskCondition `json:"conditions,omitempty"` + // Retries represents how many times this task should be retried in case of task failure: ConditionSucceeded set to False // +optional Retries int `json:"retries,omitempty"` diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go index 32a593fd8cb..34ea8887264 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_types.go @@ -128,6 +128,17 @@ type PipelineRunTaskRunStatus struct { // Status is the TaskRunStatus for the corresponding TaskRun // +optional Status *TaskRunStatus `json:"status,omitempty"` + // ConditionChecks is the Status for the corresponding ConditionCheck + // +optional + ConditionChecks map[string]*PipelineRunConditionCheckStatus `json:"conditionChecks,omitempty"` +} + +type PipelineRunConditionCheckStatus struct { + // ConditionName is the name of the Condition + ConditionName string `json:"conditionName,omitempty"` + // Status is the ConditionCheckStatus for the corresponding ConditionCheck + // +optional + Status *ConditionCheckStatus `json:"status,omitempty"` } var pipelineRunCondSet = apis.NewBatchConditionSet() diff --git a/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go index d95226a4571..0666585ffae 100644 --- a/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go @@ -174,6 +174,171 @@ func (in *ClusterTaskList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Condition) DeepCopyInto(out *Condition) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition. +func (in *Condition) DeepCopy() *Condition { + if in == nil { + return nil + } + out := new(Condition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Condition) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConditionCheck) DeepCopyInto(out *ConditionCheck) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConditionCheck. +func (in *ConditionCheck) DeepCopy() *ConditionCheck { + if in == nil { + return nil + } + out := new(ConditionCheck) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConditionCheckStatus) DeepCopyInto(out *ConditionCheckStatus) { + *out = *in + in.Status.DeepCopyInto(&out.Status) + if in.Results != nil { + in, out := &in.Results, &out.Results + if *in == nil { + *out = nil + } else { + *out = new(Results) + **out = **in + } + } + if in.StartTime != nil { + in, out := &in.StartTime, &out.StartTime + if *in == nil { + *out = nil + } else { + *out = new(meta_v1.Time) + (*in).DeepCopyInto(*out) + } + } + if in.CompletionTime != nil { + in, out := &in.CompletionTime, &out.CompletionTime + if *in == nil { + *out = nil + } else { + *out = new(meta_v1.Time) + (*in).DeepCopyInto(*out) + } + } + if in.Steps != nil { + in, out := &in.Steps, &out.Steps + *out = make([]StepState, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.RetriesStatus != nil { + in, out := &in.RetriesStatus, &out.RetriesStatus + *out = make([]TaskRunStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.ResourcesResult != nil { + in, out := &in.ResourcesResult, &out.ResourcesResult + *out = make([]PipelineResourceResult, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConditionCheckStatus. +func (in *ConditionCheckStatus) DeepCopy() *ConditionCheckStatus { + if in == nil { + return nil + } + out := new(ConditionCheckStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConditionList) DeepCopyInto(out *ConditionList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConditionList. +func (in *ConditionList) DeepCopy() *ConditionList { + if in == nil { + return nil + } + out := new(ConditionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ConditionList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConditionSpec) DeepCopyInto(out *ConditionSpec) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = make([]ParamSpec, len(*in)) + copy(*out, *in) + } + in.Check.DeepCopyInto(&out.Check) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConditionSpec. +func (in *ConditionSpec) DeepCopy() *ConditionSpec { + if in == nil { + return nil + } + out := new(ConditionSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DAG) DeepCopyInto(out *DAG) { *out = *in @@ -653,6 +818,31 @@ func (in *PipelineRun) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PipelineRunConditionCheckStatus) DeepCopyInto(out *PipelineRunConditionCheckStatus) { + *out = *in + if in.Status != nil { + in, out := &in.Status, &out.Status + if *in == nil { + *out = nil + } else { + *out = new(ConditionCheckStatus) + (*in).DeepCopyInto(*out) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineRunConditionCheckStatus. +func (in *PipelineRunConditionCheckStatus) DeepCopy() *PipelineRunConditionCheckStatus { + if in == nil { + return nil + } + out := new(PipelineRunConditionCheckStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineRunList) DeepCopyInto(out *PipelineRunList) { *out = *in @@ -843,6 +1033,18 @@ func (in *PipelineRunTaskRunStatus) DeepCopyInto(out *PipelineRunTaskRunStatus) (*in).DeepCopyInto(*out) } } + if in.ConditionChecks != nil { + in, out := &in.ConditionChecks, &out.ConditionChecks + *out = make(map[string]*PipelineRunConditionCheckStatus, len(*in)) + for key, val := range *in { + if val == nil { + (*out)[key] = nil + } else { + (*out)[key] = new(PipelineRunConditionCheckStatus) + val.DeepCopyInto((*out)[key]) + } + } + } return } @@ -909,6 +1111,13 @@ func (in *PipelineStatus) DeepCopy() *PipelineStatus { func (in *PipelineTask) DeepCopyInto(out *PipelineTask) { *out = *in out.TaskRef = in.TaskRef + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]TaskCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.RunAfter != nil { in, out := &in.RunAfter, &out.RunAfter *out = make([]string, len(*in)) @@ -1135,6 +1344,27 @@ func (in *Task) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TaskCondition) DeepCopyInto(out *TaskCondition) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = make([]Param, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskCondition. +func (in *TaskCondition) DeepCopy() *TaskCondition { + if in == nil { + return nil + } + out := new(TaskCondition) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TaskList) DeepCopyInto(out *TaskList) { *out = *in diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/condition.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/condition.go new file mode 100644 index 00000000000..7b66ee8a90e --- /dev/null +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/condition.go @@ -0,0 +1,154 @@ +/* +Copyright 2019 The Tekton 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 ( + v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// ConditionsGetter has a method to return a ConditionInterface. +// A group's client should implement this interface. +type ConditionsGetter interface { + Conditions(namespace string) ConditionInterface +} + +// ConditionInterface has methods to work with Condition resources. +type ConditionInterface interface { + Create(*v1alpha1.Condition) (*v1alpha1.Condition, error) + Update(*v1alpha1.Condition) (*v1alpha1.Condition, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Condition, error) + List(opts v1.ListOptions) (*v1alpha1.ConditionList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Condition, err error) + ConditionExpansion +} + +// conditions implements ConditionInterface +type conditions struct { + client rest.Interface + ns string +} + +// newConditions returns a Conditions +func newConditions(c *TektonV1alpha1Client, namespace string) *conditions { + return &conditions{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the condition, and returns the corresponding condition object, and an error if there is any. +func (c *conditions) Get(name string, options v1.GetOptions) (result *v1alpha1.Condition, err error) { + result = &v1alpha1.Condition{} + err = c.client.Get(). + Namespace(c.ns). + Resource("conditions"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Conditions that match those selectors. +func (c *conditions) List(opts v1.ListOptions) (result *v1alpha1.ConditionList, err error) { + result = &v1alpha1.ConditionList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("conditions"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested conditions. +func (c *conditions) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("conditions"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a condition and creates it. Returns the server's representation of the condition, and an error, if there is any. +func (c *conditions) Create(condition *v1alpha1.Condition) (result *v1alpha1.Condition, err error) { + result = &v1alpha1.Condition{} + err = c.client.Post(). + Namespace(c.ns). + Resource("conditions"). + Body(condition). + Do(). + Into(result) + return +} + +// Update takes the representation of a condition and updates it. Returns the server's representation of the condition, and an error, if there is any. +func (c *conditions) Update(condition *v1alpha1.Condition) (result *v1alpha1.Condition, err error) { + result = &v1alpha1.Condition{} + err = c.client.Put(). + Namespace(c.ns). + Resource("conditions"). + Name(condition.Name). + Body(condition). + Do(). + Into(result) + return +} + +// Delete takes name of the condition and deletes it. Returns an error if one occurs. +func (c *conditions) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("conditions"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *conditions) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("conditions"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched condition. +func (c *conditions) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Condition, err error) { + result = &v1alpha1.Condition{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("conditions"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_condition.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_condition.go new file mode 100644 index 00000000000..1cd7f748f2d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_condition.go @@ -0,0 +1,125 @@ +/* +Copyright 2019 The Tekton 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 fake + +import ( + v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeConditions implements ConditionInterface +type FakeConditions struct { + Fake *FakeTektonV1alpha1 + ns string +} + +var conditionsResource = schema.GroupVersionResource{Group: "tekton.dev", Version: "v1alpha1", Resource: "conditions"} + +var conditionsKind = schema.GroupVersionKind{Group: "tekton.dev", Version: "v1alpha1", Kind: "Condition"} + +// Get takes name of the condition, and returns the corresponding condition object, and an error if there is any. +func (c *FakeConditions) Get(name string, options v1.GetOptions) (result *v1alpha1.Condition, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(conditionsResource, c.ns, name), &v1alpha1.Condition{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Condition), err +} + +// List takes label and field selectors, and returns the list of Conditions that match those selectors. +func (c *FakeConditions) List(opts v1.ListOptions) (result *v1alpha1.ConditionList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(conditionsResource, conditionsKind, c.ns, opts), &v1alpha1.ConditionList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.ConditionList{ListMeta: obj.(*v1alpha1.ConditionList).ListMeta} + for _, item := range obj.(*v1alpha1.ConditionList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested conditions. +func (c *FakeConditions) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(conditionsResource, c.ns, opts)) + +} + +// Create takes the representation of a condition and creates it. Returns the server's representation of the condition, and an error, if there is any. +func (c *FakeConditions) Create(condition *v1alpha1.Condition) (result *v1alpha1.Condition, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(conditionsResource, c.ns, condition), &v1alpha1.Condition{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Condition), err +} + +// Update takes the representation of a condition and updates it. Returns the server's representation of the condition, and an error, if there is any. +func (c *FakeConditions) Update(condition *v1alpha1.Condition) (result *v1alpha1.Condition, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(conditionsResource, c.ns, condition), &v1alpha1.Condition{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Condition), err +} + +// Delete takes name of the condition and deletes it. Returns an error if one occurs. +func (c *FakeConditions) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(conditionsResource, c.ns, name), &v1alpha1.Condition{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeConditions) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(conditionsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.ConditionList{}) + return err +} + +// Patch applies the patch and returns the patched condition. +func (c *FakeConditions) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Condition, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(conditionsResource, c.ns, name, data, subresources...), &v1alpha1.Condition{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Condition), err +} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_pipeline_client.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_pipeline_client.go index 5514728213a..86e0147c802 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_pipeline_client.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_pipeline_client.go @@ -29,6 +29,10 @@ func (c *FakeTektonV1alpha1) ClusterTasks() v1alpha1.ClusterTaskInterface { return &FakeClusterTasks{c} } +func (c *FakeTektonV1alpha1) Conditions(namespace string) v1alpha1.ConditionInterface { + return &FakeConditions{c, namespace} +} + func (c *FakeTektonV1alpha1) Pipelines(namespace string) v1alpha1.PipelineInterface { return &FakePipelines{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/generated_expansion.go index 135b91b84f7..eaf69b60dad 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/generated_expansion.go @@ -17,6 +17,8 @@ package v1alpha1 type ClusterTaskExpansion interface{} +type ConditionExpansion interface{} + type PipelineExpansion interface{} type PipelineResourceExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/pipeline_client.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/pipeline_client.go index 1ea047aedba..d193d549f30 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/pipeline_client.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/pipeline_client.go @@ -25,6 +25,7 @@ import ( type TektonV1alpha1Interface interface { RESTClient() rest.Interface ClusterTasksGetter + ConditionsGetter PipelinesGetter PipelineResourcesGetter PipelineRunsGetter @@ -41,6 +42,10 @@ func (c *TektonV1alpha1Client) ClusterTasks() ClusterTaskInterface { return newClusterTasks(c) } +func (c *TektonV1alpha1Client) Conditions(namespace string) ConditionInterface { + return newConditions(c, namespace) +} + func (c *TektonV1alpha1Client) Pipelines(namespace string) PipelineInterface { return newPipelines(c, namespace) } diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 7216523ffb3..30c72d94de9 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -52,6 +52,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=tekton.dev, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithResource("clustertasks"): return &genericInformer{resource: resource.GroupResource(), informer: f.Tekton().V1alpha1().ClusterTasks().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("conditions"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Tekton().V1alpha1().Conditions().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("pipelines"): return &genericInformer{resource: resource.GroupResource(), informer: f.Tekton().V1alpha1().Pipelines().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("pipelineresources"): diff --git a/pkg/client/informers/externalversions/pipeline/v1alpha1/condition.go b/pkg/client/informers/externalversions/pipeline/v1alpha1/condition.go new file mode 100644 index 00000000000..f91ac07173f --- /dev/null +++ b/pkg/client/informers/externalversions/pipeline/v1alpha1/condition.go @@ -0,0 +1,86 @@ +/* +Copyright 2019 The Tekton 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 ( + time "time" + + pipeline_v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + versioned "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" + internalinterfaces "github.com/tektoncd/pipeline/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// ConditionInformer provides access to a shared informer and lister for +// Conditions. +type ConditionInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.ConditionLister +} + +type conditionInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewConditionInformer constructs a new informer for Condition type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewConditionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredConditionInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredConditionInformer constructs a new informer for Condition type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredConditionInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.TektonV1alpha1().Conditions(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.TektonV1alpha1().Conditions(namespace).Watch(options) + }, + }, + &pipeline_v1alpha1.Condition{}, + resyncPeriod, + indexers, + ) +} + +func (f *conditionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredConditionInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *conditionInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&pipeline_v1alpha1.Condition{}, f.defaultInformer) +} + +func (f *conditionInformer) Lister() v1alpha1.ConditionLister { + return v1alpha1.NewConditionLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/pipeline/v1alpha1/interface.go b/pkg/client/informers/externalversions/pipeline/v1alpha1/interface.go index e622462c703..73736011c03 100644 --- a/pkg/client/informers/externalversions/pipeline/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/pipeline/v1alpha1/interface.go @@ -23,6 +23,8 @@ import ( type Interface interface { // ClusterTasks returns a ClusterTaskInformer. ClusterTasks() ClusterTaskInformer + // Conditions returns a ConditionInformer. + Conditions() ConditionInformer // Pipelines returns a PipelineInformer. Pipelines() PipelineInformer // PipelineResources returns a PipelineResourceInformer. @@ -51,6 +53,11 @@ func (v *version) ClusterTasks() ClusterTaskInformer { return &clusterTaskInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// Conditions returns a ConditionInformer. +func (v *version) Conditions() ConditionInformer { + return &conditionInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // Pipelines returns a PipelineInformer. func (v *version) Pipelines() PipelineInformer { return &pipelineInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/listers/pipeline/v1alpha1/condition.go b/pkg/client/listers/pipeline/v1alpha1/condition.go new file mode 100644 index 00000000000..ec11c015d77 --- /dev/null +++ b/pkg/client/listers/pipeline/v1alpha1/condition.go @@ -0,0 +1,91 @@ +/* +Copyright 2019 The Tekton 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 ( + v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ConditionLister helps list Conditions. +type ConditionLister interface { + // List lists all Conditions in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Condition, err error) + // Conditions returns an object that can list and get Conditions. + Conditions(namespace string) ConditionNamespaceLister + ConditionListerExpansion +} + +// conditionLister implements the ConditionLister interface. +type conditionLister struct { + indexer cache.Indexer +} + +// NewConditionLister returns a new ConditionLister. +func NewConditionLister(indexer cache.Indexer) ConditionLister { + return &conditionLister{indexer: indexer} +} + +// List lists all Conditions in the indexer. +func (s *conditionLister) List(selector labels.Selector) (ret []*v1alpha1.Condition, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Condition)) + }) + return ret, err +} + +// Conditions returns an object that can list and get Conditions. +func (s *conditionLister) Conditions(namespace string) ConditionNamespaceLister { + return conditionNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ConditionNamespaceLister helps list and get Conditions. +type ConditionNamespaceLister interface { + // List lists all Conditions in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Condition, err error) + // Get retrieves the Condition from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Condition, error) + ConditionNamespaceListerExpansion +} + +// conditionNamespaceLister implements the ConditionNamespaceLister +// interface. +type conditionNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Conditions in the indexer for a given namespace. +func (s conditionNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Condition, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Condition)) + }) + return ret, err +} + +// Get retrieves the Condition from the indexer for a given namespace and name. +func (s conditionNamespaceLister) Get(name string) (*v1alpha1.Condition, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("condition"), name) + } + return obj.(*v1alpha1.Condition), nil +} diff --git a/pkg/client/listers/pipeline/v1alpha1/expansion_generated.go b/pkg/client/listers/pipeline/v1alpha1/expansion_generated.go index 6a6baadb92e..20753bfa4cc 100644 --- a/pkg/client/listers/pipeline/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/pipeline/v1alpha1/expansion_generated.go @@ -19,6 +19,14 @@ package v1alpha1 // ClusterTaskLister. type ClusterTaskListerExpansion interface{} +// ConditionListerExpansion allows custom methods to be added to +// ConditionLister. +type ConditionListerExpansion interface{} + +// ConditionNamespaceListerExpansion allows custom methods to be added to +// ConditionNamespaceLister. +type ConditionNamespaceListerExpansion interface{} + // PipelineListerExpansion allows custom methods to be added to // PipelineLister. type PipelineListerExpansion interface{}