Skip to content

Commit 6971026

Browse files
committed
add condition back and update graph tests
1 parent ad0583d commit 6971026

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

internal/controller/state/conditions/conditions.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,25 @@ func NewGatewayInvalid(msg string) []Condition {
854854
}
855855
}
856856

857+
// NewGatewayUnsupportedValue returns Conditions that indicate that a field of the Gateway has an unsupported value.
858+
// Unsupported means that the value is not supported by the implementation or invalid.
859+
func NewGatewayUnsupportedValue(msg string) []Condition {
860+
return []Condition{
861+
{
862+
Type: string(v1.GatewayConditionAccepted),
863+
Status: metav1.ConditionFalse,
864+
Reason: string(GatewayReasonUnsupportedValue),
865+
Message: msg,
866+
},
867+
{
868+
Type: string(v1.GatewayConditionProgrammed),
869+
Status: metav1.ConditionFalse,
870+
Reason: string(GatewayReasonUnsupportedValue),
871+
Message: msg,
872+
},
873+
}
874+
}
875+
857876
// NewGatewayUnsupportedAddress returns a Condition that indicates the Gateway is not accepted because it
858877
// contains an address type that is not supported.
859878
func NewGatewayUnsupportedAddress(msg string) Condition {

internal/controller/state/graph/graph_test.go

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,21 @@ func TestBuildGraph(t *testing.T) {
363363
},
364364
}
365365

366+
gatewaySecret := &v1.Secret{
367+
TypeMeta: metav1.TypeMeta{
368+
Kind: "Secret",
369+
},
370+
ObjectMeta: metav1.ObjectMeta{
371+
Namespace: testNs,
372+
Name: "gateway-secret",
373+
},
374+
Data: map[string][]byte{
375+
v1.TLSCertKey: cert,
376+
v1.TLSPrivateKeyKey: key,
377+
},
378+
Type: v1.SecretTypeTLS,
379+
}
380+
366381
ns := &v1.Namespace{
367382
ObjectMeta: metav1.ObjectMeta{
368383
Name: testNs,
@@ -442,6 +457,13 @@ func TestBuildGraph(t *testing.T) {
442457
TLS: &gatewayv1.GatewayTLSConfig{Mode: helpers.GetPointer(gatewayv1.TLSModePassthrough)},
443458
},
444459
},
460+
BackendTLS: &gatewayv1.GatewayBackendTLS{
461+
ClientCertificateRef: &gatewayv1.SecretObjectReference{
462+
Kind: helpers.GetPointer[gatewayv1.Kind]("Secret"),
463+
Name: gatewayv1.ObjectName(gatewaySecret.Name),
464+
Namespace: helpers.GetPointer(gatewayv1.Namespace(gatewaySecret.Namespace)),
465+
},
466+
},
445467
},
446468
},
447469
}
@@ -712,8 +734,9 @@ func TestBuildGraph(t *testing.T) {
712734
client.ObjectKeyFromObject(grToServiceNsRefGrant): grToServiceNsRefGrant,
713735
},
714736
Secrets: map[types.NamespacedName]*v1.Secret{
715-
client.ObjectKeyFromObject(secret): secret,
716-
client.ObjectKeyFromObject(plusSecret): plusSecret,
737+
client.ObjectKeyFromObject(secret): secret,
738+
client.ObjectKeyFromObject(plusSecret): plusSecret,
739+
client.ObjectKeyFromObject(gatewaySecret): gatewaySecret,
717740
},
718741
BackendTLSPolicies: map[types.NamespacedName]*v1alpha3.BackendTLSPolicy{
719742
client.ObjectKeyFromObject(btp.Source): btp.Source,
@@ -1093,6 +1116,7 @@ func TestBuildGraph(t *testing.T) {
10931116
Namespace: "test",
10941117
Name: "gateway-1-my-class",
10951118
},
1119+
SecretRef: helpers.GetPointer(client.ObjectKeyFromObject(gatewaySecret)),
10961120
},
10971121
{Namespace: testNs, Name: "gateway-2"}: {
10981122
Source: gw2.Source,
@@ -1169,6 +1193,7 @@ func TestBuildGraph(t *testing.T) {
11691193
Namespace: "test",
11701194
Name: "gateway-2-my-class",
11711195
},
1196+
SecretRef: helpers.GetPointer(client.ObjectKeyFromObject(gatewaySecret)),
11721197
},
11731198
},
11741199
Routes: map[RouteKey]*L7Route{
@@ -1188,6 +1213,13 @@ func TestBuildGraph(t *testing.T) {
11881213
TLSPrivateKey: key,
11891214
}),
11901215
},
1216+
client.ObjectKeyFromObject(gatewaySecret): {
1217+
Source: gatewaySecret,
1218+
CertBundle: NewCertificateBundle(client.ObjectKeyFromObject(gatewaySecret), "Secret", &Certificate{
1219+
TLSCert: cert,
1220+
TLSPrivateKey: key,
1221+
}),
1222+
},
11911223
},
11921224
ReferencedNamespaces: map[types.NamespacedName]*v1.Namespace{
11931225
client.ObjectKeyFromObject(ns): ns,
@@ -1277,14 +1309,13 @@ func TestBuildGraph(t *testing.T) {
12771309
{
12781310
store: createStateWithGatewayClass(normalGC),
12791311
expected: createExpectedGraphWithGatewayClass(normalGC),
1280-
experimentalEnabled: false,
1312+
experimentalEnabled: true,
12811313
name: "normal case",
12821314
},
12831315
{
1284-
store: createStateWithGatewayClass(differentControllerGC),
1285-
expected: &Graph{},
1286-
experimentalEnabled: true,
1287-
name: "gatewayclass belongs to a different controller",
1316+
store: createStateWithGatewayClass(differentControllerGC),
1317+
expected: &Graph{},
1318+
name: "gatewayclass belongs to a different controller",
12881319
},
12891320
}
12901321

0 commit comments

Comments
 (0)