From 81500542c7f10fee6541255307419ea7a06e70aa Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Mon, 6 Dec 2021 20:03:29 +0900 Subject: [PATCH] Relax label validation for networking.knative.dev/visibility This patch removes `networking.knative.dev/visibility` validation. Curently only `cluster-local` can be specified. Fix https://github.com/knative/serving/issues/8185 Part of https://github.com/knative-sandbox/net-gateway-api/issues/198 --- pkg/apis/serving/v1/route_validation.go | 4 ---- pkg/apis/serving/v1/route_validation_test.go | 12 ------------ pkg/apis/serving/v1/service_validation.go | 10 ---------- pkg/apis/serving/v1/service_validation_test.go | 15 --------------- 4 files changed, 41 deletions(-) diff --git a/pkg/apis/serving/v1/route_validation.go b/pkg/apis/serving/v1/route_validation.go index f0ba152139f4..bf29a6c32a4b 100644 --- a/pkg/apis/serving/v1/route_validation.go +++ b/pkg/apis/serving/v1/route_validation.go @@ -203,10 +203,6 @@ func validateClusterVisibilityLabel(label string) *apis.FieldError { // validateLabels function validates route labels. func (r *Route) validateLabels() (errs *apis.FieldError) { - if val, ok := r.Labels[network.VisibilityLabelKey]; ok { - errs = errs.Also(validateClusterVisibilityLabel(val)) - } - if val, ok := r.Labels[serving.ServiceLabelKey]; ok { errs = errs.Also(verifyLabelOwnerRef(val, serving.ServiceLabelKey, "Service", r.GetOwnerReferences())) } diff --git a/pkg/apis/serving/v1/route_validation_test.go b/pkg/apis/serving/v1/route_validation_test.go index 76678adfa94d..99e24bebe747 100644 --- a/pkg/apis/serving/v1/route_validation_test.go +++ b/pkg/apis/serving/v1/route_validation_test.go @@ -490,18 +490,6 @@ func TestRouteLabelValidation(t *testing.T) { }, Spec: validRouteSpec, }, - }, { - name: "invalid visibility name", - r: &Route{ - ObjectMeta: metav1.ObjectMeta{ - Name: "byo-name", - Labels: map[string]string{ - network.VisibilityLabelKey: "bad-value", - }, - }, - Spec: validRouteSpec, - }, - want: apis.ErrInvalidValue("bad-value", "metadata.labels."+network.VisibilityLabelKey), }, { name: "valid knative service name", r: &Route{ diff --git a/pkg/apis/serving/v1/service_validation.go b/pkg/apis/serving/v1/service_validation.go index 33b54aadb242..4f63ced3f777 100644 --- a/pkg/apis/serving/v1/service_validation.go +++ b/pkg/apis/serving/v1/service_validation.go @@ -19,7 +19,6 @@ package v1 import ( "context" - network "knative.dev/networking/pkg" "knative.dev/pkg/apis" "knative.dev/serving/pkg/apis/serving" ) @@ -32,7 +31,6 @@ func (s *Service) Validate(ctx context.Context) (errs *apis.FieldError) { // spec validation. if !apis.IsInStatusUpdate(ctx) { errs = errs.Also(serving.ValidateObjectMetadata(ctx, s.GetObjectMeta(), false)) - errs = errs.Also(s.validateLabels().ViaField("labels")) errs = errs.Also(serving.ValidateRolloutDurationAnnotation( s.GetAnnotations()).ViaField("annotations")) errs = errs.ViaField("metadata") @@ -61,11 +59,3 @@ func (ss *ServiceSpec) Validate(ctx context.Context) *apis.FieldError { // configurationName. ss.RouteSpec.Validate(WithDefaultConfigurationName(ctx))) } - -// validateLabels function validates service labels -func (s *Service) validateLabels() (errs *apis.FieldError) { - if val, ok := s.Labels[network.VisibilityLabelKey]; ok { - errs = errs.Also(validateClusterVisibilityLabel(val)) - } - return errs -} diff --git a/pkg/apis/serving/v1/service_validation_test.go b/pkg/apis/serving/v1/service_validation_test.go index 07cd57dbe82c..b482d1e7de84 100644 --- a/pkg/apis/serving/v1/service_validation_test.go +++ b/pkg/apis/serving/v1/service_validation_test.go @@ -97,21 +97,6 @@ func TestServiceValidation(t *testing.T) { RouteSpec: goodRouteSpec, }, }, - }, { - name: "invalid visibility label value", - r: &Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: "valid", - Labels: map[string]string{ - network.VisibilityLabelKey: "bad-label", - }, - }, - Spec: ServiceSpec{ - ConfigurationSpec: goodConfigSpec, - RouteSpec: goodRouteSpec, - }, - }, - wantErr: apis.ErrInvalidValue("bad-label", "metadata.labels."+network.VisibilityLabelKey), }, { name: "valid release", r: &Service{