From c736283e672edeb36c366c9ef7966a6ca5f81300 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 11 May 2021 12:27:21 +0200 Subject: [PATCH] =?UTF-8?q?Skip=20*heavy*=20validation=20on=20deletion=20?= =?UTF-8?q?=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When deleting an object, we don't need to pursue all the validation that we do at creation. It reduces the work to be done as part of the validation *and* allows invalid version of the resource (from previous versions for example) to be deleted safely. Signed-off-by: Vincent Demeester --- pkg/apis/pipeline/v1alpha1/cluster_task_validation.go | 3 +++ pkg/apis/pipeline/v1alpha1/condition_validation.go | 3 +++ pkg/apis/pipeline/v1alpha1/pipeline_validation.go | 3 +++ pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go | 3 +++ pkg/apis/pipeline/v1alpha1/run_validation.go | 3 +++ pkg/apis/pipeline/v1alpha1/task_validation.go | 3 +++ pkg/apis/pipeline/v1alpha1/taskrun_validation.go | 3 +++ pkg/apis/pipeline/v1beta1/cluster_task_validation.go | 3 +++ pkg/apis/pipeline/v1beta1/pipeline_validation.go | 3 +++ pkg/apis/pipeline/v1beta1/pipelinerun_validation.go | 4 ++++ pkg/apis/pipeline/v1beta1/task_validation.go | 3 +++ pkg/apis/pipeline/v1beta1/taskrun_validation.go | 3 +++ pkg/apis/resource/v1alpha1/pipelineresource_validation.go | 4 +++- 13 files changed, 40 insertions(+), 1 deletion(-) diff --git a/pkg/apis/pipeline/v1alpha1/cluster_task_validation.go b/pkg/apis/pipeline/v1alpha1/cluster_task_validation.go index b90a7f3b978..eaf1c04bc16 100644 --- a/pkg/apis/pipeline/v1alpha1/cluster_task_validation.go +++ b/pkg/apis/pipeline/v1alpha1/cluster_task_validation.go @@ -29,5 +29,8 @@ func (t *ClusterTask) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(t.GetObjectMeta()); err != nil { return err.ViaField("metadata") } + if apis.IsInDelete(ctx) { + return nil + } return t.Spec.Validate(ctx) } diff --git a/pkg/apis/pipeline/v1alpha1/condition_validation.go b/pkg/apis/pipeline/v1alpha1/condition_validation.go index dbafbba3a61..1aed47511cb 100644 --- a/pkg/apis/pipeline/v1alpha1/condition_validation.go +++ b/pkg/apis/pipeline/v1alpha1/condition_validation.go @@ -32,6 +32,9 @@ func (c Condition) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(c.GetObjectMeta()); err != nil { return err.ViaField("metadata") } + if apis.IsInDelete(ctx) { + return nil + } return c.Spec.Validate(ctx).ViaField("Spec") } diff --git a/pkg/apis/pipeline/v1alpha1/pipeline_validation.go b/pkg/apis/pipeline/v1alpha1/pipeline_validation.go index 4e56b98e12d..40308bbce06 100644 --- a/pkg/apis/pipeline/v1alpha1/pipeline_validation.go +++ b/pkg/apis/pipeline/v1alpha1/pipeline_validation.go @@ -39,6 +39,9 @@ func (p *Pipeline) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(p.GetObjectMeta()); err != nil { return err.ViaField("metadata") } + if apis.IsInDelete(ctx) { + return nil + } return p.Spec.Validate(ctx) } diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go index 249e0465449..f6396cb4337 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_validation.go @@ -32,6 +32,9 @@ func (pr *PipelineRun) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(pr.GetObjectMeta()).ViaField("metadata"); err != nil { return err } + if apis.IsInDelete(ctx) { + return nil + } return pr.Spec.Validate(ctx) } diff --git a/pkg/apis/pipeline/v1alpha1/run_validation.go b/pkg/apis/pipeline/v1alpha1/run_validation.go index 5a68359f172..09a553dd252 100644 --- a/pkg/apis/pipeline/v1alpha1/run_validation.go +++ b/pkg/apis/pipeline/v1alpha1/run_validation.go @@ -31,6 +31,9 @@ func (r *Run) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(r.GetObjectMeta()).ViaField("metadata"); err != nil { return err } + if apis.IsInDelete(ctx) { + return nil + } return r.Spec.Validate(ctx) } diff --git a/pkg/apis/pipeline/v1alpha1/task_validation.go b/pkg/apis/pipeline/v1alpha1/task_validation.go index 549cc53ee1e..e0a3b3dadfa 100644 --- a/pkg/apis/pipeline/v1alpha1/task_validation.go +++ b/pkg/apis/pipeline/v1alpha1/task_validation.go @@ -37,6 +37,9 @@ func (t *Task) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(t.GetObjectMeta()); err != nil { return err.ViaField("metadata") } + if apis.IsInDelete(ctx) { + return nil + } return t.Spec.Validate(ctx) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_validation.go b/pkg/apis/pipeline/v1alpha1/taskrun_validation.go index b1f2cace2d3..6ef2668c118 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_validation.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_validation.go @@ -34,6 +34,9 @@ func (tr *TaskRun) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(tr.GetObjectMeta()).ViaField("metadata"); err != nil { return err } + if apis.IsInDelete(ctx) { + return nil + } return tr.Spec.Validate(ctx) } diff --git a/pkg/apis/pipeline/v1beta1/cluster_task_validation.go b/pkg/apis/pipeline/v1beta1/cluster_task_validation.go index cd602e91ac2..3cdb3fca90c 100644 --- a/pkg/apis/pipeline/v1beta1/cluster_task_validation.go +++ b/pkg/apis/pipeline/v1beta1/cluster_task_validation.go @@ -27,5 +27,8 @@ var _ apis.Validatable = (*ClusterTask)(nil) func (t *ClusterTask) Validate(ctx context.Context) *apis.FieldError { errs := validate.ObjectMetadata(t.GetObjectMeta()).ViaField("metadata") + if apis.IsInDelete(ctx) { + return nil + } return errs.Also(t.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec")) } diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation.go b/pkg/apis/pipeline/v1beta1/pipeline_validation.go index 6eb248c8afe..da5a37cb08f 100644 --- a/pkg/apis/pipeline/v1beta1/pipeline_validation.go +++ b/pkg/apis/pipeline/v1beta1/pipeline_validation.go @@ -36,6 +36,9 @@ var _ apis.Validatable = (*Pipeline)(nil) // that any references resources exist, that is done at run time. func (p *Pipeline) Validate(ctx context.Context) *apis.FieldError { errs := validate.ObjectMetadata(p.GetObjectMeta()).ViaField("metadata") + if apis.IsInDelete(ctx) { + return nil + } return errs.Also(p.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec")) } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go b/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go index 97061b3e7df..446241c9798 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go @@ -32,6 +32,10 @@ var _ apis.Validatable = (*PipelineRun)(nil) func (pr *PipelineRun) Validate(ctx context.Context) *apis.FieldError { errs := validate.ObjectMetadata(pr.GetObjectMeta()).ViaField("metadata") + if apis.IsInDelete(ctx) { + return nil + } + if pr.IsPending() && pr.HasStarted() { errs = errs.Also(apis.ErrInvalidValue("PipelineRun cannot be Pending after it is started", "spec.status")) } diff --git a/pkg/apis/pipeline/v1beta1/task_validation.go b/pkg/apis/pipeline/v1beta1/task_validation.go index 16846842a92..0ca71ff5883 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation.go +++ b/pkg/apis/pipeline/v1beta1/task_validation.go @@ -36,6 +36,9 @@ var _ apis.Validatable = (*Task)(nil) func (t *Task) Validate(ctx context.Context) *apis.FieldError { errs := validate.ObjectMetadata(t.GetObjectMeta()).ViaField("metadata") + if apis.IsInDelete(ctx) { + return nil + } return errs.Also(t.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec")) } diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation.go b/pkg/apis/pipeline/v1beta1/taskrun_validation.go index 52dbcecb247..b2d6bf50bc4 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation.go @@ -33,6 +33,9 @@ var _ apis.Validatable = (*TaskRun)(nil) // Validate taskrun func (tr *TaskRun) Validate(ctx context.Context) *apis.FieldError { errs := validate.ObjectMetadata(tr.GetObjectMeta()).ViaField("metadata") + if apis.IsInDelete(ctx) { + return nil + } return errs.Also(tr.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec")) } diff --git a/pkg/apis/resource/v1alpha1/pipelineresource_validation.go b/pkg/apis/resource/v1alpha1/pipelineresource_validation.go index c1c217acd0a..a7b21401744 100644 --- a/pkg/apis/resource/v1alpha1/pipelineresource_validation.go +++ b/pkg/apis/resource/v1alpha1/pipelineresource_validation.go @@ -34,7 +34,9 @@ func (r *PipelineResource) Validate(ctx context.Context) *apis.FieldError { if err := validate.ObjectMetadata(r.GetObjectMeta()); err != nil { return err.ViaField("metadata") } - + if apis.IsInDelete(ctx) { + return nil + } return r.Spec.Validate(ctx) }