Skip to content

Commit

Permalink
Move Validatable/Defaultable interface checks out
Browse files Browse the repository at this point in the history
These type checks are a signal that the types are
validatable/defaultable, which is nice, but having them in the _types.go
files makes it more difficult to consume those files by themselves.
  • Loading branch information
imjasonh authored and tekton-robot committed Nov 14, 2019
1 parent 11dc1be commit 6bb6361
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 48 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cluster_task_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ package v1alpha1

import (
"context"

"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*ClusterTask)(nil)

func (t *ClusterTask) SetDefaults(ctx context.Context) {
t.Spec.SetDefaults(ctx)
}
7 changes: 0 additions & 7 deletions pkg/apis/pipeline/v1alpha1/cluster_task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

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

// +genclient
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cluster_task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*ClusterTask)(nil)

func (t *ClusterTask) Validate(ctx context.Context) *apis.FieldError {
if err := validateObjectMetadata(t.GetObjectMeta()); err != nil {
return err.ViaField("metadata")
Expand Down
8 changes: 7 additions & 1 deletion pkg/apis/pipeline/v1alpha1/condition_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ limitations under the License.

package v1alpha1

import "context"
import (
"context"

"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*Condition)(nil)

func (c *Condition) SetDefaults(ctx context.Context) {
c.Spec.SetDefaults(ctx)
Expand Down
6 changes: 0 additions & 6 deletions pkg/apis/pipeline/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ import (
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

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

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/condition_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*Condition)(nil)

func (c Condition) Validate(ctx context.Context) *apis.FieldError {
if err := validateObjectMetadata(c.GetObjectMeta()); err != nil {
return err.ViaField("metadata")
Expand Down
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 @@ -16,7 +16,13 @@ limitations under the License.

package v1alpha1

import "context"
import (
"context"

"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*Pipeline)(nil)

func (p *Pipeline) SetDefaults(ctx context.Context) {
p.Spec.SetDefaults(ctx)
Expand Down
6 changes: 0 additions & 6 deletions pkg/apis/pipeline/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

// PipelineSpec defines the desired state of Pipeline.
Expand Down Expand Up @@ -50,11 +49,6 @@ const (
ClusterTaskKind TaskKind = "ClusterTask"
)

var (
_ apis.Validatable = (*Pipeline)(nil)
_ apis.Defaultable = (*Pipeline)(nil)
)

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

Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*Pipeline)(nil)

// Validate checks that the Pipeline structure is valid but does not validate
// that any references resources exist, that is done at run time.
func (p *Pipeline) Validate(ctx context.Context) *apis.FieldError {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelineresource_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*PipelineResource)(nil)

func (r *PipelineResource) Validate(ctx context.Context) *apis.FieldError {
if err := validateObjectMetadata(r.GetObjectMeta()); err != nil {
return err.ViaField("metadata")
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import (

"github.com/tektoncd/pipeline/pkg/apis/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*PipelineRun)(nil)

func (pr *PipelineRun) SetDefaults(ctx context.Context) {
pr.Spec.SetDefaults(ctx)
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ var (
Version: SchemeGroupVersion.Version,
Kind: pipelineRunControllerName,
}

// Check that TaskRun may be validated and defaulted.
_ apis.Validatable = (*PipelineRun)(nil)
_ apis.Defaultable = (*PipelineRun)(nil)
)

// PipelineRunSpec defines the desired state of PipelineRun
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*PipelineRun)(nil)

// Validate pipelinerun
func (pr *PipelineRun) Validate(ctx context.Context) *apis.FieldError {
if err := validateObjectMetadata(pr.GetObjectMeta()).ViaField("metadata"); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/apis/pipeline/v1alpha1/resource_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ limitations under the License.

package v1alpha1

import "context"
import (
"context"

"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*PipelineResource)(nil)

func (t *PipelineResource) SetDefaults(ctx context.Context) {
t.Spec.SetDefaults(ctx)
Expand Down
11 changes: 2 additions & 9 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"golang.org/x/xerrors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

// PipelineResourceType represents the type of endpoint the pipelineResource is, so that the
Expand Down Expand Up @@ -57,14 +56,8 @@ const (
PipelineResourceTypeCloudEvent PipelineResourceType = "cloudEvent"
)

var (
// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypeImage, PipelineResourceTypeCluster, PipelineResourceTypePullRequest, PipelineResourceTypeCloudEvent}

// Check that PipelineResource may be validated and defaulted.
_ apis.Validatable = (*PipelineResource)(nil)
_ apis.Defaultable = (*PipelineResource)(nil)
)
// AllResourceTypes can be used for validation to check if a provided Resource type is one of the known types.
var AllResourceTypes = []PipelineResourceType{PipelineResourceTypeGit, PipelineResourceTypeStorage, PipelineResourceTypeImage, PipelineResourceTypeCluster, PipelineResourceTypePullRequest, PipelineResourceTypeCloudEvent}

// PipelineResourceInterface interface to be implemented by different PipelineResource types
type PipelineResourceInterface interface {
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha1/task_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ package v1alpha1

import (
"context"

"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*Task)(nil)

func (t *Task) SetDefaults(ctx context.Context) {
t.Spec.SetDefaults(ctx)
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/apis/pipeline/v1alpha1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

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

func (t *Task) TaskSpec() TaskSpec {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*Task)(nil)

func (t *Task) Validate(ctx context.Context) *apis.FieldError {
if err := validateObjectMetadata(t.GetObjectMeta()); err != nil {
return err.ViaField("metadata")
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import (

"github.com/tektoncd/pipeline/pkg/apis/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)

var _ apis.Defaultable = (*TaskRun)(nil)

func (tr *TaskRun) SetDefaults(ctx context.Context) {
tr.Spec.SetDefaults(ctx)
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ import (
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

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

// TaskRunSpec defines the desired state of TaskRun
type TaskRunSpec struct {
// +optional
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"knative.dev/pkg/apis"
)

var _ apis.Validatable = (*TaskRun)(nil)

// Validate taskrun
func (tr *TaskRun) Validate(ctx context.Context) *apis.FieldError {
if err := validateObjectMetadata(tr.GetObjectMeta()).ViaField("metadata"); err != nil {
Expand Down

0 comments on commit 6bb6361

Please sign in to comment.