-
Notifications
You must be signed in to change notification settings - Fork 638
conformance: add a conformance test for BackendTLSPolicy #4360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,10 @@ package tests | |
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
|
|
@@ -152,5 +156,109 @@ var BackendTLSPolicy = suite.ConformanceTest{ | |
| }, | ||
| }) | ||
| }) | ||
|
|
||
| // Verify that changing a ConfigMap content should be reconciled by the controller | ||
| t.Run("Changing the content of a ConfigMap used by BackendTLSPolicy as CA certificate should be reconciled by the controller", func(t *testing.T) { | ||
| ctx := t.Context() | ||
| routeNN := types.NamespacedName{Name: "backendtlspolicy", Namespace: ns} | ||
| gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} | ||
| validconfigmap := types.NamespacedName{Name: "tls-checks-ca-certificate", Namespace: ns} | ||
|
|
||
| kubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, []string{ns}) | ||
| gwAddr := kubernetes.GatewayAndRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), &gatewayv1.HTTPRoute{}, false, routeNN) | ||
| kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN) | ||
|
|
||
| validPolicyNN := types.NamespacedName{Name: "normative-test", Namespace: ns} | ||
| kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validPolicyNN, gwNN, acceptedCond) | ||
| kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validPolicyNN, gwNN, resolvedRefsCond) | ||
|
|
||
| validcm := &corev1.ConfigMap{} | ||
| err := suite.Client.Get(ctx, validconfigmap, validcm) | ||
| require.NoErrorf(t, err, "failed to get valid configmap") | ||
|
|
||
| originalCAData := validcm.Data["ca.crt"] | ||
|
|
||
| t.Cleanup(func() { | ||
|
|
||
| currentCM := &corev1.ConfigMap{} | ||
| err = suite.Client.Get(ctx, validconfigmap, currentCM) | ||
| if err != nil { | ||
| t.Logf("cleanup: error getting ConfigMap: %v", err) | ||
| return | ||
| } | ||
|
|
||
| if currentCM.Data["ca.crt"] != originalCAData { | ||
| restored := currentCM.DeepCopy() | ||
| restored.Data["ca.crt"] = originalCAData | ||
| err = suite.Client.Patch(ctx, restored, client.MergeFrom(currentCM)) | ||
| if err != nil { | ||
| t.Logf("cleanup: error restoring ConfigMap: %v", err) | ||
| } | ||
| } | ||
| }) | ||
| h.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, | ||
| h.ExpectedResponse{ | ||
| Namespace: ns, | ||
| Request: h.Request{ | ||
| Host: "abc.example.com", | ||
| Path: "/backendtlspolicy", | ||
| }, | ||
| Response: h.Response{StatusCodes: []int{200}}, | ||
| }) | ||
|
|
||
| mutatedCM := validcm.DeepCopy() | ||
| mutatedCM.Data["ca.crt"] = "" | ||
| err = suite.Client.Patch(ctx, mutatedCM, client.MergeFrom(validcm)) | ||
| require.NoErrorf(t, err, "failed to mutate ConfigMap") | ||
|
|
||
| invalidAcceptedCond := metav1.Condition{ | ||
| Type: string(gatewayv1.PolicyConditionAccepted), | ||
| Status: metav1.ConditionFalse, | ||
| Reason: string(gatewayv1.BackendTLSPolicyReasonNoValidCACertificate), | ||
| } | ||
| invalidResolvedRefsCond := metav1.Condition{ | ||
| Type: string(gatewayv1.BackendTLSPolicyConditionResolvedRefs), | ||
| Status: metav1.ConditionFalse, | ||
| Reason: string(gatewayv1.BackendTLSPolicyReasonInvalidCACertificateRef), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tested this on Envoy Gateway, the test passes (apparently eg watches and reconciles correctly!). The only issue on envoy gateway is that this reason here is wrong there (it is getting us InvalidKind when per the GEP it should be @arkodg fyi
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for flagging this, will raise a GH issue in EG |
||
| } | ||
|
|
||
| kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validPolicyNN, gwNN, invalidAcceptedCond) | ||
| kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validPolicyNN, gwNN, invalidResolvedRefsCond) | ||
|
|
||
| h.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, | ||
| h.ExpectedResponse{ | ||
| Namespace: ns, | ||
| Request: h.Request{ | ||
| Host: "abc.example.com", | ||
| Path: "/backendtlspolicy", | ||
| }, | ||
| Response: h.Response{ | ||
| StatusCodes: []int{500, 502, 503}, | ||
| }, | ||
| }) | ||
|
|
||
| currentCM := &corev1.ConfigMap{} | ||
| err = suite.Client.Get(ctx, validconfigmap, currentCM) | ||
| require.NoErrorf(t, err, "failed to get valid configmap") | ||
|
|
||
| restoredCM := currentCM.DeepCopy() | ||
| restoredCM.Data["ca.crt"] = originalCAData | ||
| err = suite.Client.Patch(ctx, restoredCM, client.MergeFrom(currentCM)) | ||
| require.NoErrorf(t, err, "failed to mutate ConfigMap") | ||
|
|
||
| kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validPolicyNN, gwNN, acceptedCond) | ||
| kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validPolicyNN, gwNN, resolvedRefsCond) | ||
|
|
||
| h.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, | ||
Thealisyed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| h.ExpectedResponse{ | ||
| Namespace: ns, | ||
| Request: h.Request{ | ||
| Host: "abc.example.com", | ||
| Path: "/backendtlspolicy", | ||
| SNI: "abc.example.com", | ||
| }, | ||
| Response: h.Response{StatusCodes: []int{200}}, | ||
| }) | ||
| }) | ||
| }, | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tls-checks-ca-certificateConfigMap is used by multiple conformance tests, which may run in parallel. For this reason, patching this object is not a good idea, as it could interfere with other tests.