Skip to content

Commit

Permalink
Fix flaky invalid RLP/AP tests (#558)
Browse files Browse the repository at this point in the history
* Fix flaky invalid RLP/AP tests

* create the RLP and AP test policies in another namespace instead of the targets for the invalid policies test
  • Loading branch information
guicassolato authored Apr 22, 2024
1 parent b5e6bf1 commit 478a880
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
19 changes: 9 additions & 10 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,22 +1133,21 @@ var _ = Describe("AuthPolicy controller", func() {
fmt.Sprintf("AuthPolicy is conflicted by %[1]v/toystore: the gateway.networking.k8s.io/v1, Kind=HTTPRoute target %[1]v/toystore-route is already referenced by policy %[1]v/toystore", testNamespace),
), 30*time.Second, 5*time.Second).Should(BeTrue())
})

It("Invalid reason", func() {
const targetRefName, targetRefNamespace = "istio-ingressgateway", "istio-system"
var otherNamespace string
CreateNamespace(&otherNamespace)
defer DeleteNamespaceCallback(&otherNamespace)

policy := policyFactory(func(policy *api.AuthPolicy) {
policy.Namespace = otherNamespace // create the policy in a different namespace than the target
policy.Spec.TargetRef.Kind = "Gateway"
policy.Spec.TargetRef.Name = targetRefName
policy.Spec.TargetRef.Namespace = ptr.To(gatewayapiv1.Namespace(targetRefNamespace))
policy.Spec.TargetRef.Name = gatewayapiv1.ObjectName(testGatewayName)
policy.Spec.TargetRef.Namespace = ptr.To(gatewayapiv1.Namespace(testNamespace))
})
Expect(k8sClient.Create(context.Background(), policy)).To(Succeed())

err := k8sClient.Create(context.Background(), policy)
logf.Log.V(1).Info("Creating AuthPolicy", "key", client.ObjectKeyFromObject(policy).String(), "error", err)
Expect(err).ToNot(HaveOccurred())

Eventually(assertAcceptedCondFalseAndEnforcedCondNil(policy, string(gatewayapiv1alpha2.PolicyReasonInvalid),
fmt.Sprintf("AuthPolicy target is invalid: invalid targetRef.Namespace %s. Currently only supporting references to the same namespace", targetRefNamespace),
), 30*time.Second, 5*time.Second).Should(BeTrue())
Eventually(assertAcceptedCondFalseAndEnforcedCondNil(policy, string(gatewayapiv1alpha2.PolicyReasonInvalid), fmt.Sprintf("AuthPolicy target is invalid: invalid targetRef.Namespace %s. Currently only supporting references to the same namespace", testNamespace)), 30*time.Second, 5*time.Second).Should(BeTrue())
})
})

Expand Down
20 changes: 10 additions & 10 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,20 @@ var _ = Describe("RateLimitPolicy controller", func() {
time.Minute, 5*time.Second).Should(BeTrue())
})

It("Validation reason", func() {
const targetRefName, targetRefNamespace = "istio-ingressgateway", "istio-system"
It("Invalid reason", func() {
var otherNamespace string
CreateNamespace(&otherNamespace)
defer DeleteNamespaceCallback(&otherNamespace)

rlp := policyFactory(func(policy *kuadrantv1beta2.RateLimitPolicy) {
policy := policyFactory(func(policy *kuadrantv1beta2.RateLimitPolicy) {
policy.Namespace = otherNamespace // create the policy in a different namespace than the target
policy.Spec.TargetRef.Kind = "Gateway"
policy.Spec.TargetRef.Name = targetRefName
policy.Spec.TargetRef.Namespace = ptr.To(gatewayapiv1.Namespace(targetRefNamespace))
policy.Spec.TargetRef.Name = gatewayapiv1.ObjectName(gateway.Name)
policy.Spec.TargetRef.Namespace = ptr.To(gatewayapiv1.Namespace(testNamespace))
})
err := k8sClient.Create(context.Background(), rlp)
Expect(err).ToNot(HaveOccurred())
Expect(k8sClient.Create(context.Background(), policy)).To(Succeed())

Eventually(assertAcceptedConditionFalse(rlp, string(gatewayapiv1alpha2.PolicyReasonInvalid),
fmt.Sprintf("RateLimitPolicy target is invalid: invalid targetRef.Namespace %s. Currently only supporting references to the same namespace", targetRefNamespace)),
time.Minute, 5*time.Second).Should(BeTrue())
Eventually(assertAcceptedConditionFalse(policy, string(gatewayapiv1alpha2.PolicyReasonInvalid), fmt.Sprintf("RateLimitPolicy target is invalid: invalid targetRef.Namespace %s. Currently only supporting references to the same namespace", testNamespace)), 30*time.Second, 5*time.Second).Should(BeTrue())
})
})

Expand Down

0 comments on commit 478a880

Please sign in to comment.