Skip to content

Commit

Permalink
Add Condition type to webhook and SchemeBuilder
Browse files Browse the repository at this point in the history
To enable webhook validation, Condition has to implement the
`Defaultable` interface even though at the moment there are no
default values.
Also, found that we need to register new types to the SchemeBuilder else
if we cannot create Conditions using the generated client (e.g. for e2e
 tests) since the Kind is not properly set.

Both of these changes should have been a part of the APIs PR for
Conditions. I will have an upcoming PR that will update docs for creating new
types with this information.

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom committed Jul 26, 2019
1 parent dc91bdc commit 6786e0c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func main() {
v1alpha1.SchemeGroupVersion.WithKind("ClusterTask"): &v1alpha1.ClusterTask{},
v1alpha1.SchemeGroupVersion.WithKind("TaskRun"): &v1alpha1.TaskRun{},
v1alpha1.SchemeGroupVersion.WithKind("PipelineRun"): &v1alpha1.PipelineRun{},
v1alpha1.SchemeGroupVersion.WithKind("Condition"): &v1alpha1.Condition{},
},
Logger: logger,
DisallowUnknownFields: true,
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/pipeline/v1alpha1/condition_defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
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"

func (c *Condition) SetDefaults(ctx context.Context) {
c.Spec.SetDefaults(ctx)
}

func (cs *ConditionSpec) SetDefaults(ctx context.Context) {
}
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

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

// +genclient
// +genclient:noStatus
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{},
&Condition{},
&ConditionList{},
&ClusterTask{},
&ClusterTaskList{},
&TaskRun{},
Expand Down
4 changes: 2 additions & 2 deletions test/builder/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
)

// ConditionOp is an operation which modifies a StatusCondition struct.
// ConditionOp is an operation which modifies a Condition struct.
type ConditionOp func(*v1alpha1.Condition)

// ConditionSpecOp is an operation which modifies a ConditionSpec struct.
type ConditionSpecOp func(spec *v1alpha1.ConditionSpec)

// TaskParamOp is an operation which modify a ParamSpec struct.
// ConditionParamOp is an operation which modify a ParamSpec struct.
type ConditionParamOp func(*v1alpha1.ParamSpec)

// Condition creates a Condition with default values.
Expand Down

0 comments on commit 6786e0c

Please sign in to comment.