From 7d40758d141f5bbc821eefab3568e2f2ee4d9403 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakivskyy Date: Tue, 30 Mar 2021 12:41:09 +0000 Subject: [PATCH] webhook_common: Extract only relevant parts for the validation Since we currently validate only the image name and the tag, ignore registry, vendor and extract only relevant parts. Closes #605 Signed-off-by: Oleg Zhurakivskyy --- pkg/apis/deviceplugin/v1/webhook_common.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/apis/deviceplugin/v1/webhook_common.go b/pkg/apis/deviceplugin/v1/webhook_common.go index e0b15580..261a97ad 100644 --- a/pkg/apis/deviceplugin/v1/webhook_common.go +++ b/pkg/apis/deviceplugin/v1/webhook_common.go @@ -15,6 +15,7 @@ package v1 import ( + "path/filepath" "strings" "github.com/pkg/errors" @@ -23,18 +24,19 @@ import ( // common functions for webhooks -func validatePluginImage(image, expectedName string, expectedMinVersion *version.Version) error { - parts := strings.SplitN(image, ":", 2) +func validatePluginImage(image, expectedImageName string, expectedMinVersion *version.Version) error { + // Ignore registry, vendor and extract the image name with the tag + + parts := strings.SplitN(filepath.Base(image), ":", 2) if len(parts) != 2 { return errors.Errorf("incorrect image field %q", image) } - namespacedName := parts[0] + + imageName := parts[0] versionStr := parts[1] - parts = strings.Split(namespacedName, "/") - name := parts[len(parts)-1] - if name != expectedName { - return errors.Errorf("incorrect image name %q. Make sure you use '/%s:'", name, expectedName) + if imageName != expectedImageName { + return errors.Errorf("incorrect image name %q. Make sure you use '/%s:'", imageName, expectedImageName) } ver, err := version.ParseSemantic(versionStr)