Skip to content

Commit

Permalink
test: Add e2e test for thanso receive ingest
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgough committed Jun 17, 2024
1 parent cb3b250 commit 6bf64fb
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,42 @@ limitations under the License.
package e2e

import (
"context"
"fmt"
"os"
"os/exec"
"time"

"github.com/thanos-community/thanos-operator/internal/pkg/manifests/receive"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/thanos-community/thanos-operator/api/v1alpha1"
"github.com/thanos-community/thanos-operator/test/utils"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

const namespace = "thanos-operator-system"
const (
namespace = "thanos-operator-system"

objStoreSecret = "thanos-object-storage"
objStoreSecretKey = "thanos.yaml"

receiveName = "example-receive"
hashringName = "default"
)

var _ = Describe("controller", Ordered, func() {
var c client.Client

BeforeAll(func() {
By("installing prometheus operator")
Expect(utils.InstallPrometheusOperator()).To(Succeed())
Expand All @@ -40,6 +63,35 @@ var _ = Describe("controller", Ordered, func() {
By("creating manager namespace")
cmd := exec.Command("kubectl", "create", "ns", namespace)
_, _ = utils.Run(cmd)

By("install MinIO")
Expect(utils.InstallMinIO()).To(Succeed())

By("create secret")
Expect(utils.CreateMinioObjectStorageSecret()).To(Succeed())

scheme := runtime.NewScheme()
if err := v1alpha1.AddToScheme(scheme); err != nil {
fmt.Println("failed to add scheme")
os.Exit(1)
}
if err := appsv1.AddToScheme(scheme); err != nil {
fmt.Println("failed to add scheme")
os.Exit(1)
}
if err := corev1.AddToScheme(scheme); err != nil {
fmt.Println("failed to add scheme")
os.Exit(1)
}

cl, err := client.New(config.GetConfigOrDie(), client.Options{
Scheme: scheme,
})
if err != nil {
fmt.Println("failed to create client")
os.Exit(1)
}
c = cl
})

AfterAll(func() {
Expand All @@ -49,6 +101,9 @@ var _ = Describe("controller", Ordered, func() {
By("uninstalling the cert-manager bundle")
utils.UninstallCertManager()

By("uninstalling MinIO")
utils.UninstallMinIO()

By("removing manager namespace")
cmd := exec.Command("kubectl", "delete", "ns", namespace)
_, _ = utils.Run(cmd)
Expand Down Expand Up @@ -119,4 +174,39 @@ var _ = Describe("controller", Ordered, func() {

})
})

Context("Thanos Receive", func() {
It("should bring up the ingest components", func() {
cr := &v1alpha1.ThanosReceive{
ObjectMeta: metav1.ObjectMeta{
Name: receiveName,
Namespace: namespace,
},
Spec: v1alpha1.ThanosReceiveSpec{
CommonThanosFields: v1alpha1.CommonThanosFields{},
Ingester: v1alpha1.IngesterSpec{
DefaultObjectStorageConfig: v1alpha1.ObjectStorageConfig{
LocalObjectReference: corev1.LocalObjectReference{
Name: objStoreSecret,
},
Key: objStoreSecretKey,
},
Hashrings: []v1alpha1.IngestorHashringSpec{
{
Name: hashringName,
StorageSize: "100Mi",
},
},
},
},
}
err := c.Create(context.Background(), cr, &client.CreateOptions{})
Expect(err).To(BeNil())

stsName := receive.IngesterNameFromParent(receiveName, hashringName)
Eventually(func() bool {
return utils.VerifyStsReplicasRunning(c, 3, stsName, namespace)
}, time.Minute*5, time.Second*10).Should(BeTrue())
})
})
})

0 comments on commit 6bf64fb

Please sign in to comment.