From 8783c19be6d8896b059a014af41e6996abc60c93 Mon Sep 17 00:00:00 2001 From: thxCode Date: Thu, 18 Apr 2024 21:02:31 +0800 Subject: [PATCH] fix: panic on template webhook validation Signed-off-by: thxCode --- pkg/webhooks/walruscore/catalog.go | 1 - pkg/webhooks/walruscore/template.go | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/webhooks/walruscore/catalog.go b/pkg/webhooks/walruscore/catalog.go index 6e5a03638..90b062202 100644 --- a/pkg/webhooks/walruscore/catalog.go +++ b/pkg/webhooks/walruscore/catalog.go @@ -55,7 +55,6 @@ func (r *CatalogWebhook) validateFilter(obj runtime.Object) (ctrladmission.Warni field.NewPath("spec.filters.includeExpression"), filters.IncludeExpression, err.Error()) } } - if filters.ExcludeExpression != "" { if _, err := regexp.Compile(filters.ExcludeExpression); err != nil { return nil, field.Invalid( diff --git a/pkg/webhooks/walruscore/template.go b/pkg/webhooks/walruscore/template.go index a73012070..717bbb086 100644 --- a/pkg/webhooks/walruscore/template.go +++ b/pkg/webhooks/walruscore/template.go @@ -30,8 +30,11 @@ var _ ctrlwebhook.CustomValidator = (*TemplateWebhook)(nil) func (r *TemplateWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (ctrladmission.Warnings, error) { t := obj.(*walruscore.Template) _, err := sourceurl.ParseURLToSourceURL(t.Spec.VCSRepository.URL) - return nil, field.Invalid( - field.NewPath("spec.vcsRepository.url"), t.Spec.VCSRepository.URL, err.Error()) + if err != nil { + return nil, field.Invalid( + field.NewPath("spec.vcsRepository.url"), t.Spec.VCSRepository.URL, err.Error()) + } + return nil, nil } func (r *TemplateWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (ctrladmission.Warnings, error) {