From 27d65935c9f256461b86de86797295addd0984f4 Mon Sep 17 00:00:00 2001 From: zerospiel Date: Fri, 1 Nov 2024 13:08:29 +0100 Subject: [PATCH] Fix incorrect comp sets check in admission * provider tpl capi contract should not support all of the declared capi contracts Fixes #586 --- internal/webhook/management_webhook.go | 6 +++--- internal/webhook/management_webhook_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/webhook/management_webhook.go b/internal/webhook/management_webhook.go index 78f349c8..e857eba5 100644 --- a/internal/webhook/management_webhook.go +++ b/internal/webhook/management_webhook.go @@ -114,9 +114,9 @@ func (v *ManagementValidator) ValidateUpdate(ctx context.Context, _, newObj runt return nil, fmt.Errorf("%s: not valid ProviderTemplate %s", invalidMgmtMsg, tplName) } - for capi := range capiTpl.Status.CAPIContracts { - if _, ok := pTpl.Status.CAPIContracts[capi]; !ok { - wrongVersions = errors.Join(wrongVersions, fmt.Errorf("core CAPI contract version %s does not support ProviderTemplate %s", capi, pTpl.Name)) + for capiVersion := range pTpl.Status.CAPIContracts { + if _, ok := capiTpl.Status.CAPIContracts[capiVersion]; !ok { + wrongVersions = errors.Join(wrongVersions, fmt.Errorf("core CAPI contract versions does not support %s version in the ProviderTemplate %s", capiVersion, pTpl.Name)) } } } diff --git a/internal/webhook/management_webhook_test.go b/internal/webhook/management_webhook_test.go index 98142ed9..37a4c55c 100644 --- a/internal/webhook/management_webhook_test.go +++ b/internal/webhook/management_webhook_test.go @@ -160,7 +160,7 @@ func TestManagementValidateUpdate(t *testing.T) { ), }, warnings: admission.Warnings{"The Management object has incompatible CAPI contract versions in ProviderTemplates"}, - err: fmt.Sprintf("the Management is invalid: core CAPI contract version %s does not support ProviderTemplate %s", capiVersion, template.DefaultName), + err: fmt.Sprintf("the Management is invalid: core CAPI contract versions does not support %s version in the ProviderTemplate %s", capiVersionOther, template.DefaultName), }, { name: "providertemplates match capi contracts, should succeed",