Skip to content

Commit

Permalink
chore: cleanup of integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgough committed Jun 21, 2024
1 parent eb59047 commit 5a89f52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 66 deletions.
63 changes: 11 additions & 52 deletions internal/controller/thanosquery_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controller
import (
"context"
"fmt"
"slices"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -100,22 +99,11 @@ var _ = Describe("ThanosQuery Controller", Ordered, func() {
})
Expect(err).NotTo(HaveOccurred())

EventuallyWithOffset(1, func() error {
if !utils.VerifyServiceAccountExists(k8sClient, resourceName, ns) {
return fmt.Errorf("service account not found")
}

if !utils.VerifyServiceExists(k8sClient, resourceName, ns) {
return fmt.Errorf("service not found")
}

if !utils.VerifyDeploymentExists(k8sClient, resourceName, ns) {
return fmt.Errorf("deployment not found")
}

return nil
EventuallyWithOffset(1, func() bool {
return utils.VerifyExistenceOfRequiredNamedResources(
k8sClient, utils.ExpectApiResourceDeployment, resourceName, ns)

}, time.Minute*1, time.Second*10).Should(Succeed())
}, time.Minute*1, time.Second*10).Should(BeTrue())
})

By("setting endpoints on the thanos query", func() {
Expand Down Expand Up @@ -146,31 +134,10 @@ var _ = Describe("ThanosQuery Controller", Ordered, func() {
})
Expect(err).NotTo(HaveOccurred())

EventuallyWithOffset(1, func() error {
if !utils.VerifyServiceAccountExists(k8sClient, resourceName, ns) {
return fmt.Errorf("service account not found")
}

if !utils.VerifyServiceExists(k8sClient, resourceName, ns) {
return fmt.Errorf("service not found")
}

deployment := &appsv1.Deployment{}
if err := k8sClient.Get(ctx, types.NamespacedName{
Name: resourceName,
Namespace: ns,
}, deployment); err != nil {
return err
}

if !slices.Contains(deployment.Spec.Template.Spec.Containers[0].Args,
"--endpoint=dnssrv+_grpc._tcp.thanos-receive.tquery.svc.cluster.local") {
return fmt.Errorf("endpoint not set: %v", deployment.Spec.Template.Spec.Containers[0].Args)
}

return nil

}, time.Minute*1, time.Second*10).Should(Succeed())
EventuallyWithOffset(1, func() bool {
args := "--endpoint=dnssrv+_grpc._tcp.thanos-receive.tquery.svc.cluster.local"
return utils.VerifyDeploymentArgs(k8sClient, resourceName, ns, args)
}, time.Minute*1, time.Second*10).Should(BeTrue())
})

By("setting strict and ignoring services on the thanos query", func() {
Expand Down Expand Up @@ -223,14 +190,6 @@ var _ = Describe("ThanosQuery Controller", Ordered, func() {
Expect(err).NotTo(HaveOccurred())

EventuallyWithOffset(1, func() error {
if !utils.VerifyServiceAccountExists(k8sClient, resourceName, ns) {
return fmt.Errorf("service account not found")
}

if !utils.VerifyServiceExists(k8sClient, resourceName, ns) {
return fmt.Errorf("service not found")
}

deployment := &appsv1.Deployment{}
if err := k8sClient.Get(ctx, types.NamespacedName{
Name: resourceName,
Expand All @@ -245,9 +204,9 @@ var _ = Describe("ThanosQuery Controller", Ordered, func() {
deployment.Spec.Template.Spec.Containers[0].Args)
}

if !slices.Contains(deployment.Spec.Template.Spec.Containers[0].Args,
"--endpoint-strict=dnssrv+_grpc._tcp.thanos-receive.tquery.svc.cluster.local") {
return fmt.Errorf("endpoint strict not set: %v", deployment.Spec.Template.Spec.Containers[0].Args)
arg := "--endpoint-strict=dnssrv+_grpc._tcp.thanos-receive.tquery.svc.cluster.local"
if utils.VerifyDeploymentArgs(k8sClient, resourceName, ns, arg) == false {
return fmt.Errorf("expected arg %q", arg)
}

return nil
Expand Down
14 changes: 8 additions & 6 deletions internal/controller/thanosreceive_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ config:
Expect(k8sClient.Create(context.Background(), resource)).Should(Succeed())

name := receive.IngesterNameFromParent(resourceName, "test-hashring")
Eventually(func() error {
return validateExistenceOfRequiredNamedResources(expectApiResourceStatefulSet, name, ns)
}, time.Minute*1, time.Second*5).Should(Succeed())
Eventually(func() bool {
return utils.VerifyExistenceOfRequiredNamedResources(
k8sClient, utils.ExpectApiResourceStatefulSet, name, ns)
}, time.Minute*1, time.Second*5).Should(BeTrue())

})

Expand Down Expand Up @@ -326,9 +327,10 @@ config:
})

By("creating the router components", func() {
Eventually(func() error {
return validateExistenceOfRequiredNamedResources(expectApiResourceDeployment, resourceName, ns)
}, time.Minute*1, time.Second*1).Should(Succeed())
Eventually(func() bool {
return utils.VerifyExistenceOfRequiredNamedResources(
k8sClient, utils.ExpectApiResourceDeployment, resourceName, ns)
}, time.Minute*1, time.Second*1).Should(BeTrue())
})
})

Expand Down
13 changes: 5 additions & 8 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ func VerifyStatefulSetExists(c client.Client, name string, namespace string) boo
Name: name,
Namespace: namespace,
}, sts)
if err != nil {
return false
}
return true
return err == nil
}

func VerifyConfigMapContents(c client.Client, name, namespace, key, expect string) bool {
Expand Down Expand Up @@ -437,21 +434,21 @@ const (
// VerifyExistenceOfRequiredNamedResources checks if the required resources exist in the cluster.
// This is a named Service, ServiceAccount, and either a Deployment or StatefulSet.
func VerifyExistenceOfRequiredNamedResources(c client.Client, expectResource ExpectApiResource, name, ns string) bool {
if VerifyServiceAccountExists(c, name, ns) == false {
if !VerifyServiceAccountExists(c, name, ns) {
return false
}

if VerifyServiceExists(c, name, ns) == false {
if !VerifyServiceExists(c, name, ns) {
return false
}

switch expectResource {
case ExpectApiResourceDeployment:
if VerifyDeploymentExists(c, name, ns) == false {
if !VerifyDeploymentExists(c, name, ns) {
return false
}
case ExpectApiResourceStatefulSet:
if VerifyStatefulSetExists(c, name, ns) == false {
if !VerifyStatefulSetExists(c, name, ns) {
return false
}
default:
Expand Down

0 comments on commit 5a89f52

Please sign in to comment.