Skip to content

Commit 94bf615

Browse files
mlavaccarobscott
authored andcommitted
conformance: listener references invalid secret
A new conformance test case has been added to ensure that whenever a listener references an unexisting secret as CertificateRef, the Condition ResolvedRefs is set as failed with reason InvalidCertificateRef. Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
1 parent cd020d8 commit 94bf615

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package tests
18+
19+
import (
20+
"testing"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/types"
24+
25+
"sigs.k8s.io/gateway-api/apis/v1alpha2"
26+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
27+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
28+
)
29+
30+
func init() {
31+
ConformanceTests = append(ConformanceTests, GatewaySecretMissingReferencedSecret)
32+
}
33+
34+
var GatewaySecretMissingReferencedSecret = suite.ConformanceTest{
35+
ShortName: "GatewaySecretMissingReferencedSecret",
36+
Description: "A Gateway should fail to become ready if the Gateway has a certificateRef for a nonexistent Secret",
37+
Manifests: []string{"tests/gateway-secret-missing-referenced-secret.yaml"},
38+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
39+
gwNN := types.NamespacedName{Name: "gateway-secret-missing-referenced-secret", Namespace: "gateway-conformance-infra"}
40+
41+
t.Run("Gateway listener should have a false ResolvedRefs condition with reason InvalidCertificateRef", func(t *testing.T) {
42+
listeners := []v1alpha2.ListenerStatus{{
43+
Name: v1alpha2.SectionName("https"),
44+
SupportedKinds: []v1alpha2.RouteGroupKind{{
45+
Group: (*v1alpha2.Group)(&v1alpha2.GroupVersion.Group),
46+
Kind: v1alpha2.Kind("HTTPRoute"),
47+
}},
48+
Conditions: []metav1.Condition{{
49+
Type: string(v1alpha2.ListenerConditionResolvedRefs),
50+
Status: metav1.ConditionFalse,
51+
Reason: string(v1alpha2.ListenerReasonInvalidCertificateRef),
52+
}},
53+
}}
54+
55+
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, gwNN, listeners, 60)
56+
})
57+
},
58+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: gateway.networking.k8s.io/v1alpha2
2+
kind: Gateway
3+
metadata:
4+
name: gateway-secret-missing-referenced-secret
5+
namespace: gateway-conformance-infra
6+
spec:
7+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
8+
listeners:
9+
- name: https
10+
port: 443
11+
protocol: HTTPS
12+
allowedRoutes:
13+
namespaces:
14+
from: All
15+
tls:
16+
certificateRefs:
17+
- group: ""
18+
kind: Secret
19+
name: nonexistent-secret

0 commit comments

Comments
 (0)