Skip to content

Commit 1fd1953

Browse files
committed
Changes from #839 and #859
1 parent d4fb63d commit 1fd1953

19 files changed

+394
-546
lines changed

apis/v1alpha1/gateway_types.go

-9
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,6 @@ type TLSOverridePolicy struct {
298298
}
299299

300300
// GatewayTLSConfig describes a TLS configuration.
301-
//
302-
// References:
303-
//
304-
// - nginx: https://nginx.org/en/docs/http/configuring_https_servers.html
305-
// - envoy: https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/auth/cert.proto
306-
// - haproxy: https://www.haproxy.com/documentation/aloha/9-5/traffic-management/lb-layer7/tls/
307-
// - gcp: https://cloud.google.com/load-balancing/docs/use-ssl-policies#creating_an_ssl_policy_with_a_custom_profile
308-
// - aws: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html#describe-ssl-policies
309-
// - azure: https://docs.microsoft.com/en-us/azure/app-service/configure-ssl-bindings#enforce-tls-1112
310301
type GatewayTLSConfig struct {
311302
// Mode defines the TLS behavior for the TLS session initiated by the client.
312303
// There are two possible modes:

apis/v1alpha1/shared_types.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,21 @@ type RouteForwardTo struct {
169169
// RouteConditionType is a type of condition for a route.
170170
type RouteConditionType string
171171

172+
// RouteConditionReason is a reason for a route condition.
173+
type RouteConditionReason string
174+
172175
const (
173176
// This condition indicates whether the route has been admitted
174-
// or rejected by a Gateway, and why.
177+
// or refused by a Gateway.
175178
ConditionRouteAdmitted RouteConditionType = "Admitted"
179+
180+
// This reason is used with the "Admitted" condition when the Route has been
181+
// admitted by the Gateway.
182+
RouteReasonAdmitted RouteConditionReason = "Admitted"
183+
184+
// This reason is used with the "Admitted" condition when the Route has been
185+
// refused by the Gateway.
186+
RouteReasonRefused RouteConditionReason = "Refused"
176187
)
177188

178189
// RouteGatewayStatus describes the status of a route with respect to an

apis/v1alpha1/validation/validation.go

+15
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,18 @@ func validateHTTPRouteUniqueFilters(rules []gatewayv1a1.HTTPRouteRule, path *fie
122122

123123
return errs
124124
}
125+
126+
// ValidateGatewayClassUpdate validates an update to oldClass according to the
127+
// Gateway API specification. For additional details of the GatewayClass spec, refer to:
128+
// https://gateway-api.sigs.k8s.io/spec/#networking.x-k8s.io/v1alpha2.GatewayClass
129+
func ValidateGatewayClassUpdate(oldClass, newClass *gatewayv1a1.GatewayClass) field.ErrorList {
130+
if oldClass == nil || newClass == nil {
131+
return nil
132+
}
133+
var errs field.ErrorList
134+
if oldClass.Spec.Controller != newClass.Spec.Controller {
135+
errs = append(errs, field.Invalid(field.NewPath("spec.controller"), newClass.Spec.Controller,
136+
"cannot update an immutable field"))
137+
}
138+
return errs
139+
}

apis/v1alpha1/validation/validation_test.go

+75
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ limitations under the License.
1717
package validation
1818

1919
import (
20+
"reflect"
2021
"testing"
2122

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

2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/apimachinery/pkg/util/validation/field"
2527
utilpointer "k8s.io/utils/pointer"
2628
)
2729

@@ -424,3 +426,76 @@ func portNumberPtr(p int) *gatewayv1a1.PortNumber {
424426
result := gatewayv1a1.PortNumber(p)
425427
return &result
426428
}
429+
430+
func TestValidateGatewayClassUpdate(t *testing.T) {
431+
type args struct {
432+
oldClass *gatewayv1a1.GatewayClass
433+
newClass *gatewayv1a1.GatewayClass
434+
}
435+
tests := []struct {
436+
name string
437+
args args
438+
want field.ErrorList
439+
}{
440+
{
441+
name: "changing parameters reference is allowed",
442+
args: args{
443+
oldClass: &gatewayv1a1.GatewayClass{
444+
Spec: gatewayv1a1.GatewayClassSpec{
445+
Controller: "foo",
446+
},
447+
},
448+
newClass: &gatewayv1a1.GatewayClass{
449+
Spec: gatewayv1a1.GatewayClassSpec{
450+
Controller: "foo",
451+
ParametersRef: &gatewayv1a1.ParametersReference{
452+
Group: "example.com",
453+
Kind: "GatewayClassConfig",
454+
Name: "foo",
455+
},
456+
},
457+
},
458+
},
459+
want: nil,
460+
},
461+
{
462+
name: "changing controller field results in an error",
463+
args: args{
464+
oldClass: &gatewayv1a1.GatewayClass{
465+
Spec: gatewayv1a1.GatewayClassSpec{
466+
Controller: "foo",
467+
},
468+
},
469+
newClass: &gatewayv1a1.GatewayClass{
470+
Spec: gatewayv1a1.GatewayClassSpec{
471+
Controller: "bar",
472+
},
473+
},
474+
},
475+
want: field.ErrorList{
476+
{
477+
Type: field.ErrorTypeInvalid,
478+
Field: "spec.controller",
479+
Detail: "cannot update an immutable field",
480+
BadValue: "bar",
481+
},
482+
},
483+
},
484+
{
485+
name: "nil input result in no errors",
486+
args: args{
487+
oldClass: nil,
488+
newClass: nil,
489+
},
490+
want: nil,
491+
},
492+
}
493+
for _, tt := range tests {
494+
tt := tt
495+
t.Run(tt.name, func(t *testing.T) {
496+
if got := ValidateGatewayClassUpdate(tt.args.oldClass, tt.args.newClass); !reflect.DeepEqual(got, tt.want) {
497+
t.Errorf("ValidateGatewayClassUpdate() = %v, want %v", got, tt.want)
498+
}
499+
})
500+
}
501+
}

apis/v1alpha1/zz_generated.deepcopy.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)