Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed May 4, 2022
1 parent 224aef1 commit 3a65c56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 9 additions & 1 deletion internal/webhooks/runtime/extensionconfig_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func validateExtensionConfigSpec(e *runtimev1.ExtensionConfig) field.ErrorList {
))
}

if errs := validation.IsDNS1123Subdomain(e.Spec.ClientConfig.Service.Name); len(errs) != 0 {
if errs := validation.IsDNS1035Label(e.Spec.ClientConfig.Service.Name); len(errs) != 0 {
allErrs = append(allErrs, field.Invalid(
specPath.Child("clientConfig", "service", "name"),
e.Spec.ClientConfig.Service.Name,
Expand All @@ -176,6 +176,14 @@ func validateExtensionConfigSpec(e *runtimev1.ExtensionConfig) field.ErrorList {
))
}

if errs := validation.IsDNS1123Label(e.Spec.ClientConfig.Service.Namespace); len(errs) != 0 {
allErrs = append(allErrs, field.Invalid(
specPath.Child("clientConfig", "service", "name"),
e.Spec.ClientConfig.Service.Name,
"invalid namespace",
))
}

if e.Spec.ClientConfig.Service.Path != nil {
path := *e.Spec.ClientConfig.Service.Path
if _, err := url.ParseRequestURI(path); err != nil {
Expand Down
18 changes: 13 additions & 5 deletions internal/webhooks/runtime/extensionconfig_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func TestExtensionConfigValidate(t *testing.T) {
extensionWithNoServiceNamespace := extensionWithService.DeepCopy()
extensionWithNoServiceNamespace.Spec.ClientConfig.Service.Namespace = ""

extensionWithBadServiceNamespace := extensionWithService.DeepCopy()
extensionWithBadServiceNamespace.Spec.ClientConfig.Service.Namespace = "INVALID"

badURLExtension := extensionWithURL.DeepCopy()
badURLExtension.Spec.ClientConfig.URL = pointer.String("https//extension-address.com")

Expand Down Expand Up @@ -210,23 +213,29 @@ func TestExtensionConfigValidate(t *testing.T) {
expectErr: true,
},
{
name: "creation should fail if no name is defined",
name: "creation should fail if no Service Name is defined",
in: extensionWithNoServiceName,
featureGate: true,
expectErr: true,
},
{
name: "creation should fail if name violates Kubernetes naming rules",
name: "creation should fail if Service Name violates Kubernetes naming rules",
in: extensionWithBadServiceName,
featureGate: true,
expectErr: true,
},
{
name: "creation should fail if no namespace is defined",
name: "creation should fail if no Service Namespace is defined",
in: extensionWithNoServiceNamespace,
featureGate: true,
expectErr: true,
},
{
name: "creation should fail if no Service Namespace is defined",
in: extensionWithBadServiceNamespace,
featureGate: true,
expectErr: true,
},
{
name: "update should fail if URL is invalid",
old: extensionWithURL,
Expand Down Expand Up @@ -262,7 +271,6 @@ func TestExtensionConfigValidate(t *testing.T) {
featureGate: true,
expectErr: true,
},

{
name: "update should fail if Service Port is invalid",
old: extensionWithService,
Expand All @@ -271,7 +279,7 @@ func TestExtensionConfigValidate(t *testing.T) {
expectErr: true,
},
{
name: "update should pass if Service Path is valid",
name: "update should pass if updated Extension is valid",
old: extensionWithService,
in: extensionWithService,
featureGate: true,
Expand Down
2 changes: 1 addition & 1 deletion internal/webhooks/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package util includes the util functions webhooks.
// Package util includes the utility functions for testing webhooks.
package util

import (
Expand Down

0 comments on commit 3a65c56

Please sign in to comment.