fix(webhook): fix hostname validation logic (#2015)

Signed-off-by: Lukas Boettcher <lukas.boettcher@sick.de>
This commit is contained in:
boettluSICKAG
2026-07-10 06:50:35 +02:00
committed by GitHub
parent 8ed873b2e0
commit 388d9f3f38
4 changed files with 218 additions and 33 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ func TestErrorConstructors(t *testing.T) {
{name: "ingress forbidden", err: apierrors.NewIngressClassForbidden("nginx", allowed), want: "Ingress Class nginx is forbidden"},
{name: "ingress collision", err: apierrors.NewIngressHostnameCollision("example.com"), want: "example.com is already used"},
{name: "empty ingress hostname", err: apierrors.NewEmptyIngressHostname(api.AllowedListSpec{Exact: []string{"example.com"}, Regex: ".*\\.example\\.com"}), want: "empty hostname is not allowed"},
{name: "ingress hostnames invalid", err: apierrors.NewIngressHostnamesNotValid([]string{"bad_host"}, []string{"other.com"}, api.AllowedListSpec{Exact: []string{"example.com"}}), want: "Hostnames [bad_host] are not valid"},
{name: "ingress hostnames invalid", err: apierrors.NewIngressHostnamesNotValid([]string{"bad_host"}, api.AllowedListSpec{Exact: []string{"example.com"}}), want: "Hostnames [bad_host] are not valid"},
{name: "ingress undefined", err: apierrors.NewIngressClassUndefined(allowed), want: "No Ingress Class is forbidden"},
{name: "ingress not valid", err: apierrors.NewIngressClassNotValid("nginx", allowed), want: "Ingress Class nginx is forbidden"},
{name: "namespace quota", err: apierrors.NewNamespaceQuotaExceededError(), want: "Cannot exceed Namespace quota"},
+6 -7
View File
@@ -45,9 +45,8 @@ func (i IngressClassForbiddenError) Error() string {
}
type IngressHostnameNotValidError struct {
invalidHostnames []string
notMatchingHostnames []string
spec api.AllowedListSpec
invalidHostnames []string
spec api.AllowedListSpec
}
type IngressHostnameCollisionError struct {
@@ -76,13 +75,13 @@ func (e EmptyIngressHostnameError) Error() string {
return fmt.Sprintf("empty hostname is not allowed for the current Tenant%s", appendHostnameError(e.spec))
}
func NewIngressHostnamesNotValid(invalidHostnames []string, notMatchingHostnames []string, spec api.AllowedListSpec) error {
return &IngressHostnameNotValidError{invalidHostnames: invalidHostnames, notMatchingHostnames: notMatchingHostnames, spec: spec}
func NewIngressHostnamesNotValid(hostnames []string, spec api.AllowedListSpec) error {
return &IngressHostnameNotValidError{invalidHostnames: hostnames, spec: spec}
}
func (i IngressHostnameNotValidError) Error() string {
return fmt.Sprintf("Hostnames %s are not valid for the current Tenant. Hostnames %s not matching for the current Tenant%s",
i.invalidHostnames, i.notMatchingHostnames, appendHostnameError(i.spec))
return fmt.Sprintf("Hostnames %v are not valid for the current Tenant%s",
i.invalidHostnames, appendHostnameError(i.spec))
}
type IngressClassUndefinedError struct {