From 77e00f8818a5955221e62c7b9a812926c73ed37d Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Mon, 5 Oct 2020 11:49:14 -0300 Subject: [PATCH] :bug: check if resource exist to allow to create webhooks --- pkg/plugin/v2/webhook.go | 6 ++++++ pkg/plugin/v3/webhook.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/plugin/v2/webhook.go b/pkg/plugin/v2/webhook.go index 7f34cd40e01..aeae540891b 100644 --- a/pkg/plugin/v2/webhook.go +++ b/pkg/plugin/v2/webhook.go @@ -96,6 +96,12 @@ func (p *createWebhookPlugin) Validate() error { " --programmatic-validation and --conversion to be true", p.commandName) } + // check if resource exist to create webhook + if !p.config.HasResource(p.resource.GVK()) { + return fmt.Errorf("%s create webhook requires an api with the group,"+ + " kind and version provided", p.commandName) + } + return nil } diff --git a/pkg/plugin/v3/webhook.go b/pkg/plugin/v3/webhook.go index 2c643f204a6..929023ad096 100644 --- a/pkg/plugin/v3/webhook.go +++ b/pkg/plugin/v3/webhook.go @@ -96,6 +96,12 @@ func (p *createWebhookPlugin) Validate() error { " --programmatic-validation and --conversion to be true", p.commandName) } + // check if resource exist to create webhook + if !p.config.HasResource(p.resource.GVK()) { + return fmt.Errorf("%s create webhook requires an api with the group,"+ + " kind and version provided", p.commandName) + } + return nil }