Skip to content

Commit 3c0f617

Browse files
authored
Merge pull request #608 from ozhuraki/validate-plugin-image
webhook_common: Support domains with a custom port in the image string
2 parents 60f23f4 + 7d40758 commit 3c0f617

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pkg/apis/deviceplugin/v1/webhook_common.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package v1
1616

1717
import (
18+
"path/filepath"
1819
"strings"
1920

2021
"github.com/pkg/errors"
@@ -23,18 +24,19 @@ import (
2324

2425
// common functions for webhooks
2526

26-
func validatePluginImage(image, expectedName string, expectedMinVersion *version.Version) error {
27-
parts := strings.SplitN(image, ":", 2)
27+
func validatePluginImage(image, expectedImageName string, expectedMinVersion *version.Version) error {
28+
// Ignore registry, vendor and extract the image name with the tag
29+
30+
parts := strings.SplitN(filepath.Base(image), ":", 2)
2831
if len(parts) != 2 {
2932
return errors.Errorf("incorrect image field %q", image)
3033
}
31-
namespacedName := parts[0]
34+
35+
imageName := parts[0]
3236
versionStr := parts[1]
3337

34-
parts = strings.Split(namespacedName, "/")
35-
name := parts[len(parts)-1]
36-
if name != expectedName {
37-
return errors.Errorf("incorrect image name %q. Make sure you use '<vendor>/%s:<version>'", name, expectedName)
38+
if imageName != expectedImageName {
39+
return errors.Errorf("incorrect image name %q. Make sure you use '<vendor>/%s:<version>'", imageName, expectedImageName)
3840
}
3941

4042
ver, err := version.ParseSemantic(versionStr)

0 commit comments

Comments
 (0)