Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIG-NETWORK v1alpha2 review round 2 #861

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions apis/v1alpha1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,6 @@ type TLSOverridePolicy struct {
}

// GatewayTLSConfig describes a TLS configuration.
//
// References:
//
// - nginx: https://nginx.org/en/docs/http/configuring_https_servers.html
// - envoy: https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/auth/cert.proto
// - haproxy: https://www.haproxy.com/documentation/aloha/9-5/traffic-management/lb-layer7/tls/
// - gcp: https://cloud.google.com/load-balancing/docs/use-ssl-policies#creating_an_ssl_policy_with_a_custom_profile
// - aws: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html#describe-ssl-policies
// - azure: https://docs.microsoft.com/en-us/azure/app-service/configure-ssl-bindings#enforce-tls-1112
type GatewayTLSConfig struct {
// Mode defines the TLS behavior for the TLS session initiated by the client.
// There are two possible modes:
Expand Down
13 changes: 12 additions & 1 deletion apis/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,21 @@ type RouteForwardTo struct {
// RouteConditionType is a type of condition for a route.
type RouteConditionType string

// RouteConditionReason is a reason for a route condition.
type RouteConditionReason string

const (
// This condition indicates whether the route has been admitted
// or rejected by a Gateway, and why.
// or refused by a Gateway.
ConditionRouteAdmitted RouteConditionType = "Admitted"

// This reason is used with the "Admitted" condition when the Route has been
// admitted by the Gateway.
RouteReasonAdmitted RouteConditionReason = "Admitted"

// This reason is used with the "Admitted" condition when the Route has been
// refused by the Gateway.
RouteReasonRefused RouteConditionReason = "Refused"
)

// RouteGatewayStatus describes the status of a route with respect to an
Expand Down
15 changes: 15 additions & 0 deletions apis/v1alpha1/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,18 @@ func validateHTTPRouteUniqueFilters(rules []gatewayv1a1.HTTPRouteRule, path *fie

return errs
}

// ValidateGatewayClassUpdate validates an update to oldClass according to the
// Gateway API specification. For additional details of the GatewayClass spec, refer to:
// https://gateway-api.sigs.k8s.io/spec/#networking.x-k8s.io/v1alpha2.GatewayClass
func ValidateGatewayClassUpdate(oldClass, newClass *gatewayv1a1.GatewayClass) field.ErrorList {
if oldClass == nil || newClass == nil {
return nil
}
var errs field.ErrorList
if oldClass.Spec.Controller != newClass.Spec.Controller {
errs = append(errs, field.Invalid(field.NewPath("spec.controller"), newClass.Spec.Controller,
"cannot update an immutable field"))
}
return errs
}
87 changes: 79 additions & 8 deletions apis/v1alpha1/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package validation

import (
"reflect"
"testing"

gatewayv1a1 "sigs.k8s.io/gateway-api/apis/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
utilpointer "k8s.io/utils/pointer"
)

Expand Down Expand Up @@ -145,7 +147,6 @@ func TestValidateGateway(t *testing.T) {
}

for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
gw := baseGateway.DeepCopy()
tc.mutate(gw)
Expand Down Expand Up @@ -403,13 +404,11 @@ func TestValidateHTTPRoute(t *testing.T) {
errCount: 0,
},
}
for _, tt := range tests {
// copy variable to avoid scope problems with ranges
tt := tt
t.Run(tt.name, func(t *testing.T) {
errs := ValidateHTTPRoute(&tt.hRoute)
if len(errs) != tt.errCount {
t.Errorf("ValidateHTTPRoute() got %v errors, want %v errors", len(errs), tt.errCount)
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
errs := ValidateHTTPRoute(&tc.hRoute)
if len(errs) != tc.errCount {
t.Errorf("ValidateHTTPRoute() got %v errors, want %v errors", len(errs), tc.errCount)
}
})
}
Expand All @@ -424,3 +423,75 @@ func portNumberPtr(p int) *gatewayv1a1.PortNumber {
result := gatewayv1a1.PortNumber(p)
return &result
}

func TestValidateGatewayClassUpdate(t *testing.T) {
type args struct {
oldClass *gatewayv1a1.GatewayClass
newClass *gatewayv1a1.GatewayClass
}
tests := []struct {
name string
args args
want field.ErrorList
}{
{
name: "changing parameters reference is allowed",
args: args{
oldClass: &gatewayv1a1.GatewayClass{
Spec: gatewayv1a1.GatewayClassSpec{
Controller: "foo",
},
},
newClass: &gatewayv1a1.GatewayClass{
Spec: gatewayv1a1.GatewayClassSpec{
Controller: "foo",
ParametersRef: &gatewayv1a1.ParametersReference{
Group: "example.com",
Kind: "GatewayClassConfig",
Name: "foo",
},
},
},
},
want: nil,
},
{
name: "changing controller field results in an error",
args: args{
oldClass: &gatewayv1a1.GatewayClass{
Spec: gatewayv1a1.GatewayClassSpec{
Controller: "foo",
},
},
newClass: &gatewayv1a1.GatewayClass{
Spec: gatewayv1a1.GatewayClassSpec{
Controller: "bar",
},
},
},
want: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "spec.controller",
Detail: "cannot update an immutable field",
BadValue: "bar",
},
},
},
{
name: "nil input result in no errors",
args: args{
oldClass: nil,
newClass: nil,
},
want: nil,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := ValidateGatewayClassUpdate(tc.args.oldClass, tc.args.newClass); !reflect.DeepEqual(got, tc.want) {
t.Errorf("ValidateGatewayClassUpdate() = %v, want %v", got, tc.want)
}
})
}
}
1 change: 1 addition & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions apis/v1alpha2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2020 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha2 contains API Schema definitions for the
// gateway.networking.k8s.io API group.
// +kubebuilder:object:generate=true
// +groupName=gateway.networking.k8s.io
package v1alpha2
Loading