Skip to content
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

tests: speed & other minor improvements #565

Merged
merged 20 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fa4238f
refactor: wasm plugin tests use spec context
KevFan Apr 23, 2024
2e1bd0c
refactor: envoy filter tests use spec context
KevFan Apr 23, 2024
1611804
refactor: rlp tests use spec context
KevFan Apr 23, 2024
e72432b
refactor: kuadrant tests use spec context
KevFan Apr 23, 2024
07f0e1f
refactor: auth policy tests use spec context
KevFan Apr 23, 2024
8e4e584
refactor: status tests use spec context
KevFan Apr 23, 2024
3c48bde
refactor: tests setup/delete toystore app once
KevFan Apr 23, 2024
fdb03c7
refactor: remove node timeouts
KevFan Apr 23, 2024
f89cf6a
refactor: remove eventually for deleting limitador deployment
KevFan Apr 24, 2024
c490cc7
refactor: add timeouts for cleanups
KevFan Apr 24, 2024
adfcaaf
refactor: remove deploying toystore app in tests
KevFan Apr 24, 2024
227a041
test: add debug lines to flaky test
KevFan Apr 24, 2024
5feca34
refactor: pass context to rlp test helper functions
KevFan Apr 25, 2024
420f598
fix: remove some testRLPIsEnforced
KevFan Apr 25, 2024
023ccaa
refactor: single kuadrant install in before/after suite
KevFan Apr 25, 2024
a9c8fc9
fix: wrap updates in wasm controller test in Eventually
KevFan Apr 25, 2024
9c87907
refactor: move single kuadrant to BeforeAll/AfterAll instead
KevFan Apr 25, 2024
7b55ee6
refactor: remove building docker image as part of test workflow
KevFan Apr 25, 2024
b5188f9
refactor: return created ns string rather than use pointer
KevFan Apr 25, 2024
933a00e
refactor: single eventually assert for policy accepted and enforced s…
KevFan Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ on:
schedule:
- cron: "15 1 * * *"

env:
TEST_IMG: quay.io/kuadrant/kuadrant-operator:${{ github.sha }}

jobs:
unit-tests:
name: Unit Tests
Expand Down Expand Up @@ -72,9 +69,6 @@ jobs:
id: go
- name: Check out code
uses: actions/checkout@v3
- name: Run make docker-build
run: |
make docker-build IMG=${{ env.TEST_IMG }}
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
Expand Down
596 changes: 290 additions & 306 deletions controllers/authpolicy_controller_test.go

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions controllers/dnspolicy_controller_multi_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {

BeforeEach(func() {
ctx = context.Background()
CreateNamespace(&testNamespace)
testNamespace = CreateNamespaceWithContext(ctx)

var err error
ownerID, err = utils.GetClusterUID(ctx, k8sClient)
Expand Down Expand Up @@ -123,7 +123,7 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
err := k8sClient.Delete(ctx, gatewayClass)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
DeleteNamespaceCallback(&testNamespace)()
DeleteNamespaceCallbackWithContext(ctx, testNamespace)
})

Context("simple routing strategy", func() {
Expand Down Expand Up @@ -704,7 +704,5 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
}, TestTimeoutMedium, TestRetryIntervalMedium, ctx).Should(Succeed())
})
})

})

})
5 changes: 2 additions & 3 deletions controllers/dnspolicy_controller_single_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() {

BeforeEach(func() {
ctx = context.Background()
CreateNamespace(&testNamespace)
testNamespace = CreateNamespaceWithContext(ctx)

var err error
clusterUID, err := utils.GetClusterUID(ctx, k8sClient)
Expand Down Expand Up @@ -109,7 +109,7 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
err := k8sClient.Delete(ctx, gatewayClass)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
DeleteNamespaceCallback(&testNamespace)()
DeleteNamespaceCallbackWithContext(ctx, testNamespace)
})

Context("simple routing strategy", func() {
Expand Down Expand Up @@ -294,5 +294,4 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
})

})

})
4 changes: 2 additions & 2 deletions controllers/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("DNSPolicy controller", func() {

BeforeEach(func() {
ctx = context.Background()
CreateNamespace(&testNamespace)
testNamespace = CreateNamespaceWithContext(ctx)

gatewayClass = testBuildGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())
Expand All @@ -63,7 +63,7 @@ var _ = Describe("DNSPolicy controller", func() {
err := k8sClient.Delete(ctx, gatewayClass)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
DeleteNamespaceCallback(&testNamespace)()
DeleteNamespaceCallbackWithContext(ctx, testNamespace)
})

It("should validate routing strategy field correctly", func() {
Expand Down
97 changes: 50 additions & 47 deletions controllers/gateway_kuadrant_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,157 +17,160 @@ import (
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
)

var _ = Describe("Kuadrant Gateway controller", func() {
var _ = Describe("Kuadrant Gateway controller", Ordered, func() {
const (
testTimeOut = SpecTimeout(2 * time.Minute)
afterEachTimeOut = NodeTimeout(3 * time.Minute)
)
var (
testNamespace string
gwAName = "gw-a"
gwBName = "gw-b"
)

beforeEachCallback := func() {
CreateNamespace(&testNamespace)

beforeEachCallback := func(ctx SpecContext) {
testNamespace = CreateNamespaceWithContext(ctx)
}

BeforeEach(beforeEachCallback)
AfterEach(DeleteNamespaceCallback(&testNamespace))
AfterEach(func(ctx SpecContext) { DeleteNamespaceCallbackWithContext(ctx, testNamespace) }, afterEachTimeOut)

Context("two gateways created after Kuadrant instance", func() {
It("gateways should have required annotation", func() {
It("gateways should have required annotation", func(ctx SpecContext) {
ApplyKuadrantCR(testNamespace)

gwA := testBuildBasicGateway(gwAName, testNamespace)
err := k8sClient.Create(context.Background(), gwA)
err := k8sClient.Create(ctx, gwA)
Expect(err).ToNot(HaveOccurred())
Eventually(testGatewayIsReady(gwA), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gwA)).WithContext(ctx).Should(BeTrue())

gwB := testBuildBasicGateway(gwBName, testNamespace)
err = k8sClient.Create(context.Background(), gwB)
err = k8sClient.Create(ctx, gwB)
Expect(err).ToNot(HaveOccurred())
Eventually(testGatewayIsReady(gwB), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gwB)).WithContext(ctx).Should(BeTrue())

// Check gwA is annotated with kuadrant annotation
Eventually(testIsGatewayKuadrantManaged(gwA, testNamespace), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testIsGatewayKuadrantManaged(ctx, gwA, testNamespace)).WithContext(ctx).Should(BeTrue())

// Check gwB is annotated with kuadrant annotation
Eventually(testIsGatewayKuadrantManaged(gwB, testNamespace), 15*time.Second, 5*time.Second).Should(BeTrue())
})
Eventually(testIsGatewayKuadrantManaged(ctx, gwB, testNamespace)).WithContext(ctx).Should(BeTrue())
}, testTimeOut)
})

Context("two gateways created before Kuadrant instance", func() {
It("gateways should have required annotation", func() {
It("gateways should have required annotation", func(ctx SpecContext) {
gwA := testBuildBasicGateway(gwAName, testNamespace)
err := k8sClient.Create(context.Background(), gwA)
err := k8sClient.Create(ctx, gwA)
Expect(err).ToNot(HaveOccurred())
Eventually(testGatewayIsReady(gwA), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gwA)).WithContext(ctx).Should(BeTrue())

gwB := testBuildBasicGateway(gwBName, testNamespace)
err = k8sClient.Create(context.Background(), gwB)
err = k8sClient.Create(ctx, gwB)
Expect(err).ToNot(HaveOccurred())
Eventually(testGatewayIsReady(gwB), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gwB)).WithContext(ctx).Should(BeTrue())

ApplyKuadrantCR(testNamespace)

// Check gwA is annotated with kuadrant annotation
Eventually(testIsGatewayKuadrantManaged(gwA, testNamespace), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testIsGatewayKuadrantManaged(ctx, gwA, testNamespace)).WithContext(ctx).Should(BeTrue())

// Check gwB is annotated with kuadrant annotation
Eventually(testIsGatewayKuadrantManaged(gwB, testNamespace), 15*time.Second, 5*time.Second).Should(BeTrue())
})
Eventually(testIsGatewayKuadrantManaged(ctx, gwB, testNamespace)).WithContext(ctx).Should(BeTrue())
}, testTimeOut)
})

Context("when Kuadrant instance is deleted", func() {
It("gateways should not have kuadrant annotation", func() {
It("gateways should not have kuadrant annotation", func(ctx SpecContext) {
kuadrantName := "sample"
ApplyKuadrantCRWithName(testNamespace, kuadrantName)

gwA := testBuildBasicGateway(gwAName, testNamespace)
err := k8sClient.Create(context.Background(), gwA)
err := k8sClient.Create(ctx, gwA)
Expect(err).ToNot(HaveOccurred())
Eventually(testGatewayIsReady(gwA), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gwA)).WithContext(ctx).Should(BeTrue())

gwB := testBuildBasicGateway(gwBName, testNamespace)
err = k8sClient.Create(context.Background(), gwB)
err = k8sClient.Create(ctx, gwB)
Expect(err).ToNot(HaveOccurred())
Eventually(testGatewayIsReady(gwB), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gwB)).WithContext(ctx).Should(BeTrue())

// Check gwA is annotated with kuadrant annotation
Eventually(testIsGatewayKuadrantManaged(gwA, testNamespace), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testIsGatewayKuadrantManaged(ctx, gwA, testNamespace)).WithContext(ctx).Should(BeTrue())

// Check gwB is annotated with kuadrant annotation
Eventually(testIsGatewayKuadrantManaged(gwB, testNamespace), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testIsGatewayKuadrantManaged(ctx, gwB, testNamespace)).WithContext(ctx).Should(BeTrue())

kObj := &kuadrantv1beta1.Kuadrant{ObjectMeta: metav1.ObjectMeta{Name: kuadrantName, Namespace: testNamespace}}
err = testClient().Delete(context.Background(), kObj)
err = testClient().Delete(ctx, kObj)

// Check gwA is not annotated with kuadrant annotation
Eventually(func() bool {
existingGateway := &gatewayapiv1.Gateway{}
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gwA), existingGateway)
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gwA), existingGateway)
if err != nil {
logf.Log.Info("[WARN] Getting gateway failed", "error", err)
return false
}
_, isSet := existingGateway.GetAnnotations()[kuadrant.KuadrantNamespaceAnnotation]
return !isSet
}, 15*time.Second, 5*time.Second).Should(BeTrue())
}).WithContext(ctx).Should(BeTrue())

// Check gwB is not annotated with kuadrant annotation
Eventually(func() bool {
existingGateway := &gatewayapiv1.Gateway{}
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gwB), existingGateway)
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gwB), existingGateway)
if err != nil {
logf.Log.Info("[WARN] Getting gateway failed", "error", err)
return false
}
_, isSet := existingGateway.GetAnnotations()[kuadrant.KuadrantNamespaceAnnotation]
return !isSet
}, 15*time.Second, 5*time.Second).Should(BeTrue())
})
}).WithContext(ctx).Should(BeTrue())
}, testTimeOut)
})

Context("Two kuadrant instances", func() {
var (
secondNamespace string
kuadrantAName string = "kuadrant-a"
kuadrantBName string = "kuadrant-b"
kuadrantAName = "kuadrant-a"
kuadrantBName = "kuadrant-b"
)

BeforeEach(func() {
BeforeEach(func(ctx SpecContext) {
ApplyKuadrantCRWithName(testNamespace, kuadrantAName)

CreateNamespace(&secondNamespace)
secondNamespace = CreateNamespaceWithContext(ctx)
ApplyKuadrantCRWithName(secondNamespace, kuadrantBName)
})

AfterEach(DeleteNamespaceCallback(&secondNamespace))
AfterEach(func(ctx SpecContext) { DeleteNamespaceCallbackWithContext(ctx, secondNamespace) }, afterEachTimeOut)

It("new gateway should not be annotated", func() {
It("new gateway should not be annotated", func(ctx SpecContext) {
gateway := testBuildBasicGateway("gw-a", testNamespace)
err := k8sClient.Create(context.Background(), gateway)
err := k8sClient.Create(ctx, gateway)
Expect(err).ToNot(HaveOccurred())

Eventually(testGatewayIsReady(gateway), 15*time.Second, 5*time.Second).Should(BeTrue())
Eventually(testGatewayIsReady(gateway)).WithContext(ctx).Should(BeTrue())

// Check gateway is not annotated with kuadrant annotation
Eventually(func() bool {
existingGateway := &gatewayapiv1.Gateway{}
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gateway), existingGateway)
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gateway), existingGateway)
if err != nil {
logf.Log.V(1).Info("[WARN] Getting gateway failed", "error", err)
return false
}
_, isSet := existingGateway.GetAnnotations()[kuadrant.KuadrantNamespaceAnnotation]
return !isSet
}, 15*time.Second, 5*time.Second).Should(BeTrue())
})
}).WithContext(ctx).Should(BeTrue())
}, testTimeOut)
})
})

func testIsGatewayKuadrantManaged(gw *gatewayapiv1.Gateway, ns string) func() bool {
func testIsGatewayKuadrantManaged(ctx context.Context, gw *gatewayapiv1.Gateway, ns string) func() bool {
return func() bool {
existingGateway := &gatewayapiv1.Gateway{}
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gw), existingGateway)
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(gw), existingGateway)
if err != nil {
logf.Log.Info("[WARN] Getting gateway failed", "error", err)
return false
Expand Down
Loading
Loading