mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
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 <oleg.zhurakivskyy@intel.com>
This commit is contained in:
parent
60f23f40f0
commit
7d40758d14
@ -15,6 +15,7 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -23,18 +24,19 @@ import (
|
|||||||
|
|
||||||
// common functions for webhooks
|
// common functions for webhooks
|
||||||
|
|
||||||
func validatePluginImage(image, expectedName string, expectedMinVersion *version.Version) error {
|
func validatePluginImage(image, expectedImageName string, expectedMinVersion *version.Version) error {
|
||||||
parts := strings.SplitN(image, ":", 2)
|
// Ignore registry, vendor and extract the image name with the tag
|
||||||
|
|
||||||
|
parts := strings.SplitN(filepath.Base(image), ":", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
return errors.Errorf("incorrect image field %q", image)
|
return errors.Errorf("incorrect image field %q", image)
|
||||||
}
|
}
|
||||||
namespacedName := parts[0]
|
|
||||||
|
imageName := parts[0]
|
||||||
versionStr := parts[1]
|
versionStr := parts[1]
|
||||||
|
|
||||||
parts = strings.Split(namespacedName, "/")
|
if imageName != expectedImageName {
|
||||||
name := parts[len(parts)-1]
|
return errors.Errorf("incorrect image name %q. Make sure you use '<vendor>/%s:<version>'", imageName, expectedImageName)
|
||||||
if name != expectedName {
|
|
||||||
return errors.Errorf("incorrect image name %q. Make sure you use '<vendor>/%s:<version>'", name, expectedName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ver, err := version.ParseSemantic(versionStr)
|
ver, err := version.ParseSemantic(versionStr)
|
||||||
|
Loading…
Reference in New Issue
Block a user