@@ -17,8 +17,13 @@ limitations under the License.
1717package tests
1818
1919import (
20+ "context"
2021 "testing"
2122
23+ "github.com/stretchr/testify/require"
24+ corev1 "k8s.io/api/core/v1"
25+ "sigs.k8s.io/controller-runtime/pkg/client"
26+
2227 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2328 "k8s.io/apimachinery/pkg/types"
2429
@@ -152,5 +157,112 @@ var BackendTLSPolicy = suite.ConformanceTest{
152157 },
153158 })
154159 })
160+
161+ // Verify that changing a ConfigMap content should be reconciled by the controller
162+ t .Run ("Changing the content of a ConfigMap used by BackendTLSPolicy as CA certificate should be reconciled by the controller" , func (t * testing.T ) {
163+ ctx := t .Context ()
164+ routeNN := types.NamespacedName {Name : "backendtlspolicy" , Namespace : ns }
165+ gwNN := types.NamespacedName {Name : "same-namespace" , Namespace : ns }
166+ validconfigmap := types.NamespacedName {Name : "tls-checks-ca-certificate" , Namespace : ns }
167+
168+ kubernetes .NamespacesMustBeReady (t , suite .Client , suite .TimeoutConfig , []string {ns })
169+ gwAddr := kubernetes .GatewayAndRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), & gatewayv1.HTTPRoute {}, false , routeNN )
170+ kubernetes .HTTPRouteMustHaveResolvedRefsConditionsTrue (t , suite .Client , suite .TimeoutConfig , routeNN , gwNN )
171+
172+ validPolicyNN := types.NamespacedName {Name : "normative-test" , Namespace : ns }
173+ kubernetes .BackendTLSPolicyMustHaveCondition (t , suite .Client , suite .TimeoutConfig , validPolicyNN , gwNN , acceptedCond )
174+ kubernetes .BackendTLSPolicyMustHaveCondition (t , suite .Client , suite .TimeoutConfig , validPolicyNN , gwNN , resolvedRefsCond )
175+
176+ validcm := & corev1.ConfigMap {}
177+ err := suite .Client .Get (ctx , validconfigmap , validcm )
178+ require .NoErrorf (t , err , "failed to get valid configmap" )
179+
180+ originalCAData := validcm .Data ["ca.crt" ]
181+
182+ t .Cleanup (func () {
183+ cleanupCtx , cleanupCancel := context .WithTimeout (context .Background (),
184+ suite .TimeoutConfig .DefaultTestTimeout )
185+ defer cleanupCancel ()
186+
187+ currentCM := & corev1.ConfigMap {}
188+ err = suite .Client .Get (cleanupCtx , validconfigmap , currentCM )
189+ if err != nil {
190+ t .Logf ("cleanup: error getting ConfigMap: %v" , err )
191+ return
192+ }
193+
194+ if currentCM .Data ["ca.crt" ] != originalCAData {
195+ restored := currentCM .DeepCopy ()
196+ restored .Data ["ca.crt" ] = originalCAData
197+ err = suite .Client .Patch (cleanupCtx , restored , client .MergeFrom (currentCM ))
198+ if err != nil {
199+ t .Logf ("cleanup: error restoring ConfigMap: %v" , err )
200+ }
201+ }
202+ })
203+ h .MakeRequestAndExpectEventuallyConsistentResponse (t , suite .RoundTripper , suite .TimeoutConfig , gwAddr ,
204+ h.ExpectedResponse {
205+ Namespace : ns ,
206+ Request : h.Request {
207+ Host : "abc.example.com" ,
208+ Path : "/backendtlspolicy" ,
209+ },
210+ Response : h.Response {StatusCodes : []int {200 }},
211+ })
212+
213+ mutatedCM := validcm .DeepCopy ()
214+ mutatedCM .Data ["ca.crt" ] = ""
215+ err = suite .Client .Patch (ctx , mutatedCM , client .MergeFrom (validcm ))
216+ require .NoErrorf (t , err , "failed to mutate ConfigMap" )
217+
218+ invalidAcceptedCond := metav1.Condition {
219+ Type : string (gatewayv1 .PolicyConditionAccepted ),
220+ Status : metav1 .ConditionFalse ,
221+ Reason : string (gatewayv1 .BackendTLSPolicyReasonNoValidCACertificate ),
222+ }
223+ invalidResolvedRefsCond := metav1.Condition {
224+ Type : string (gatewayv1 .BackendTLSPolicyConditionResolvedRefs ),
225+ Status : metav1 .ConditionFalse ,
226+ Reason : string (gatewayv1 .BackendTLSPolicyReasonInvalidCACertificateRef ),
227+ }
228+
229+ kubernetes .BackendTLSPolicyMustHaveCondition (t , suite .Client , suite .TimeoutConfig , validPolicyNN , gwNN , invalidAcceptedCond )
230+ kubernetes .BackendTLSPolicyMustHaveCondition (t , suite .Client , suite .TimeoutConfig , validPolicyNN , gwNN , invalidResolvedRefsCond )
231+
232+ h .MakeRequestAndExpectEventuallyConsistentResponse (t , suite .RoundTripper , suite .TimeoutConfig , gwAddr ,
233+ h.ExpectedResponse {
234+ Namespace : ns ,
235+ Request : h.Request {
236+ Host : "abc.example.com" ,
237+ Path : "/backendtlspolicy" ,
238+ },
239+ Response : h.Response {
240+ StatusCodes : []int {500 , 502 , 503 },
241+ },
242+ })
243+
244+ currentCM := & corev1.ConfigMap {}
245+ err = suite .Client .Get (ctx , validconfigmap , currentCM )
246+ require .NoErrorf (t , err , "failed to get valid configmap" )
247+
248+ restoredCM := currentCM .DeepCopy ()
249+ restoredCM .Data ["ca.crt" ] = originalCAData
250+ err = suite .Client .Patch (ctx , restoredCM , client .MergeFrom (currentCM ))
251+ require .NoErrorf (t , err , "failed to mutate ConfigMap" )
252+
253+ kubernetes .BackendTLSPolicyMustHaveCondition (t , suite .Client , suite .TimeoutConfig , validPolicyNN , gwNN , acceptedCond )
254+ kubernetes .BackendTLSPolicyMustHaveCondition (t , suite .Client , suite .TimeoutConfig , validPolicyNN , gwNN , resolvedRefsCond )
255+
256+ h .MakeRequestAndExpectEventuallyConsistentResponse (t , suite .RoundTripper , suite .TimeoutConfig , gwAddr ,
257+ h.ExpectedResponse {
258+ Namespace : ns ,
259+ Request : h.Request {
260+ Host : "abc.example.com" ,
261+ Path : "/backendtlspolicy" ,
262+ SNI : "abc.example.com" ,
263+ },
264+ Response : h.Response {StatusCodes : []int {200 }},
265+ })
266+ })
155267 },
156268}
0 commit comments