sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/gateway-with-attached-routes.go (about) 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 v1 "sigs.k8s.io/gateway-api/apis/v1" 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, GatewayWithAttachedRoutes, GatewayWithAttachedRoutesWithPort8080) 32 } 33 34 var GatewayWithAttachedRoutes = suite.ConformanceTest{ 35 ShortName: "GatewayWithAttachedRoutes", 36 Description: "A Gateway in the gateway-conformance-infra namespace should be attached to routes.", 37 Features: []suite.SupportedFeature{ 38 suite.SupportGateway, 39 suite.SupportHTTPRoute, 40 }, 41 Manifests: []string{"tests/gateway-with-attached-routes.yaml"}, 42 Test: func(t *testing.T, s *suite.ConformanceTestSuite) { 43 t.Run("Gateway listener should have one valid http routes attached", func(t *testing.T) { 44 gwNN := types.NamespacedName{Name: "gateway-with-one-attached-route", Namespace: "gateway-conformance-infra"} 45 listeners := []v1.ListenerStatus{{ 46 Name: v1.SectionName("http"), 47 SupportedKinds: []v1.RouteGroupKind{{ 48 Group: (*v1.Group)(&v1.GroupVersion.Group), 49 Kind: v1.Kind("HTTPRoute"), 50 }}, 51 Conditions: []metav1.Condition{ 52 { 53 Type: string(v1.ListenerConditionAccepted), 54 Status: metav1.ConditionTrue, 55 Reason: "", // any reason 56 }, 57 { 58 Type: string(v1.ListenerConditionResolvedRefs), 59 Status: metav1.ConditionTrue, 60 Reason: "", // any reason 61 }, 62 }, 63 AttachedRoutes: 1, 64 }} 65 66 kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners) 67 }) 68 69 t.Run("Gateway listener should have two valid http routes attached", func(t *testing.T) { 70 gwNN := types.NamespacedName{Name: "gateway-with-two-attached-routes", Namespace: "gateway-conformance-infra"} 71 listeners := []v1.ListenerStatus{{ 72 Name: v1.SectionName("http"), 73 SupportedKinds: []v1.RouteGroupKind{{ 74 Group: (*v1.Group)(&v1.GroupVersion.Group), 75 Kind: v1.Kind("HTTPRoute"), 76 }}, 77 Conditions: []metav1.Condition{ 78 { 79 Type: string(v1.ListenerConditionAccepted), 80 Status: metav1.ConditionTrue, 81 Reason: "", // any reason 82 }, 83 { 84 Type: string(v1.ListenerConditionResolvedRefs), 85 Status: metav1.ConditionTrue, 86 Reason: "", // any reason 87 }, 88 }, 89 AttachedRoutes: 2, 90 }} 91 92 kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners) 93 }) 94 95 t.Run("Gateway listener should have AttachedRoutes set even when Gateway has unresolved refs", func(t *testing.T) { 96 gwNN := types.NamespacedName{Name: "unresolved-gateway-with-one-attached-unresolved-route", Namespace: "gateway-conformance-infra"} 97 listeners := []v1.ListenerStatus{{ 98 Name: v1.SectionName("tls"), 99 SupportedKinds: []v1.RouteGroupKind{{ 100 Group: (*v1.Group)(&v1.GroupVersion.Group), 101 Kind: v1.Kind("HTTPRoute"), 102 }}, 103 Conditions: []metav1.Condition{ 104 { 105 Type: string(v1.ListenerConditionProgrammed), 106 Status: metav1.ConditionFalse, 107 Reason: "", // any reason 108 }, 109 { 110 Type: string(v1.ListenerConditionResolvedRefs), 111 Status: metav1.ConditionFalse, 112 Reason: "", // any reason 113 }, 114 }, 115 AttachedRoutes: 1, 116 }} 117 118 kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners) 119 120 hrouteNN := types.NamespacedName{Name: "http-route-4", Namespace: "gateway-conformance-infra"} 121 notAccepted := metav1.Condition{ 122 Type: string(v1.RouteConditionAccepted), 123 Status: metav1.ConditionFalse, 124 Reason: "", // any reason 125 } 126 unresolved := metav1.Condition{ 127 Type: string(v1.RouteConditionResolvedRefs), 128 Status: metav1.ConditionFalse, 129 Reason: "", // any reason 130 } 131 132 kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, hrouteNN, gwNN, notAccepted) 133 kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, hrouteNN, gwNN, unresolved) 134 }) 135 }, 136 } 137 138 var GatewayWithAttachedRoutesWithPort8080 = suite.ConformanceTest{ 139 ShortName: "GatewayWithAttachedRoutesWithPort8080", 140 Description: "A Gateway in the gateway-conformance-infra namespace should be attached to routes.", 141 Features: []suite.SupportedFeature{ 142 suite.SupportGateway, 143 suite.SupportGatewayPort8080, 144 suite.SupportHTTPRoute, 145 }, 146 Manifests: []string{"tests/gateway-with-attached-routes-with-port-8080.yaml"}, 147 Test: func(t *testing.T, s *suite.ConformanceTestSuite) { 148 t.Run("Gateway listener should have attached route by specifying the sectionName", func(t *testing.T) { 149 gwNN := types.NamespacedName{Name: "gateway-with-two-listeners-and-one-attached-route", Namespace: "gateway-conformance-infra"} 150 listeners := []v1.ListenerStatus{ 151 { 152 Name: v1.SectionName("http-unattached"), 153 SupportedKinds: []v1.RouteGroupKind{{ 154 Group: (*v1.Group)(&v1.GroupVersion.Group), 155 Kind: v1.Kind("HTTPRoute"), 156 }}, 157 Conditions: []metav1.Condition{ 158 { 159 Type: string(v1.ListenerConditionAccepted), 160 Status: metav1.ConditionTrue, 161 Reason: "", // any reason 162 }, 163 { 164 Type: string(v1.ListenerConditionResolvedRefs), 165 Status: metav1.ConditionTrue, 166 Reason: "", // any reason 167 }, 168 }, 169 AttachedRoutes: 0, 170 }, 171 { 172 Name: v1.SectionName("http"), 173 SupportedKinds: []v1.RouteGroupKind{{ 174 Group: (*v1.Group)(&v1.GroupVersion.Group), 175 Kind: v1.Kind("HTTPRoute"), 176 }}, 177 Conditions: []metav1.Condition{ 178 { 179 Type: string(v1.ListenerConditionAccepted), 180 Status: metav1.ConditionTrue, 181 Reason: "", // any reason 182 }, 183 { 184 Type: string(v1.ListenerConditionResolvedRefs), 185 Status: metav1.ConditionTrue, 186 Reason: "", // any reason 187 }, 188 }, 189 AttachedRoutes: 1, 190 }, 191 } 192 193 kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, gwNN, listeners) 194 }) 195 }, 196 }