Skip to content

Commit

Permalink
opensearch integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ribaraka committed Sep 15, 2023
1 parent 7c0608c commit d44050e
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 127 deletions.
2 changes: 2 additions & 0 deletions config/crd/bases/clusters.instaclustr.com_cadences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ spec:
- nodesNumber
- region
type: object
maxItems: 1
minItems: 1
type: array
description:
type: string
Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/clusters.instaclustr.com_kafkas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ spec:
- region
type: object
maxItems: 1
minItems: 1
type: array
dedicatedZookeeper:
description: Provision additional dedicated nodes for Apache Zookeeper
Expand Down
85 changes: 46 additions & 39 deletions controllers/tests/cassandra_plus_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,20 @@ import (

var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster controllers flow", func() {
var (
ns = "default"
user1 clusterresource.CassandraUser
user2 clusterresource.CassandraUser

user1 clusterresource.CassandraUser
user2 clusterresource.CassandraUser
userManifest1 clusterresource.CassandraUser
userManifest2 clusterresource.CassandraUser

secret v1.Secret
secretManifest v1.Secret
cassandra1 v1beta1.Cassandra
cassandra2 v1beta1.Cassandra

cassandra1 v1beta1.Cassandra
cassandra2 v1beta1.Cassandra
cassandraManifest v1beta1.Cassandra

timeout = time.Millisecond * 300
interval = time.Millisecond * 100
secret v1.Secret
)

ctx := context.Background()

cassandraUserYAML, err := os.ReadFile("datatest/clusterresources_v1beta1_cassandrauser.yaml")
Expect(err).NotTo(HaveOccurred())

err = yaml.Unmarshal(cassandraUserYAML, &userManifest1)
Expect(err).NotTo(HaveOccurred())

userNamespacedName1 := types.NamespacedName{Name: userManifest1.ObjectMeta.Name, Namespace: ns}
userNamespacedName2 := types.NamespacedName{}

secretYAML, err := os.ReadFile("datatest/secret.yaml")
Expect(err).NotTo(HaveOccurred())

err = yaml.Unmarshal(secretYAML, &secretManifest)
Expect(err).NotTo(HaveOccurred())

secretNS := types.NamespacedName{Name: secretManifest.ObjectMeta.Name, Namespace: ns}

cassandraYAML, err := os.ReadFile("datatest/clusters_v1beta1_cassandra.yaml")
cassandraYAML, err := os.ReadFile("../clusters/datatest/cassandra_v1beta1.yaml")
Expect(err).NotTo(HaveOccurred())

err = yaml.Unmarshal(cassandraYAML, &cassandraManifest)
Expand All @@ -87,12 +63,43 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
cassandraManifest2.ObjectMeta.Name += "-2"
cassandraManifest2.Spec.Name += "-2"

cassandraNamespacedName1 := types.NamespacedName{Name: cassandraManifest.ObjectMeta.Name, Namespace: ns}
cassandraNamespacedName2 := types.NamespacedName{Name: cassandraManifest2.ObjectMeta.Name, Namespace: ns}
secretManifest := v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "secret-sample-c",
Namespace: defaultNS,
},
StringData: map[string]string{
"password": "password",
"username": "username",
},
}

userManifest1 := clusterresource.CassandraUser{
ObjectMeta: metav1.ObjectMeta{
Name: "cassandrauser-sample",
Namespace: defaultNS,
},
Spec: clusterresource.CassandraUserSpec{
SecretRef: &clusterresource.SecretReference{
Namespace: defaultNS,
Name: secretManifest.ObjectMeta.Name,
},
},
}

secretNamespacedName := types.NamespacedName{Name: secretManifest.ObjectMeta.Name, Namespace: defaultNS}

userNamespacedName1 := types.NamespacedName{Name: userManifest1.ObjectMeta.Name, Namespace: defaultNS}
userNamespacedName2 := types.NamespacedName{}

cassandraNamespacedName1 := types.NamespacedName{Name: cassandraManifest.ObjectMeta.Name, Namespace: defaultNS}
cassandraNamespacedName2 := types.NamespacedName{Name: cassandraManifest2.ObjectMeta.Name, Namespace: defaultNS}

clusterID1 := cassandraManifest.Spec.Name + openapi.CreatedID
clusterID2 := cassandraManifest2.Spec.Name + openapi.CreatedID

ctx := context.Background()

When("apply a secret and a cassandra user manifests", func() {
It("should create both resources and they've got to have a link them through a finalizer", func() {
Expect(k8sClient.Create(ctx, &secretManifest)).Should(Succeed())
Expand All @@ -102,7 +109,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
return false
}

if err := k8sClient.Get(ctx, secretNS, &secret); err != nil {
if err := k8sClient.Get(ctx, secretNamespacedName, &secret); err != nil {
return false
}

Expand Down Expand Up @@ -190,7 +197,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
secretManifest2 := v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secret.Name + "-2",
Namespace: ns,
Namespace: defaultNS,
},
StringData: map[string]string{
"username": "carlo",
Expand All @@ -202,7 +209,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
userManifest2 = clusterresource.CassandraUser{
ObjectMeta: metav1.ObjectMeta{
Name: userManifest1.Name + "-2",
Namespace: ns,
Namespace: defaultNS,
},
Spec: clusterresource.CassandraUserSpec{
SecretRef: &clusterresource.SecretReference{
Expand Down Expand Up @@ -230,7 +237,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
cassandra1.Spec.UserRefs = newUsers
Expect(k8sClient.Patch(ctx, &cassandra1, patch)).Should(Succeed())

userNamespacedName2 = types.NamespacedName{Name: userManifest2.ObjectMeta.Name, Namespace: ns}
userNamespacedName2 = types.NamespacedName{Name: userManifest2.ObjectMeta.Name, Namespace: defaultNS}
Eventually(func() bool {
if err := k8sClient.Get(ctx, userNamespacedName1, &user1); err != nil {
return false
Expand All @@ -255,7 +262,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
userManifest3 := &clusterresource.CassandraUser{
ObjectMeta: metav1.ObjectMeta{
Name: userManifest1.Name + "-3",
Namespace: ns,
Namespace: defaultNS,
},
Spec: *userManifest1.Spec.DeepCopy(),
}
Expand All @@ -264,7 +271,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
Expect(k8sClient.Create(ctx, userManifest3)).Should(Succeed())

user3 := clusterresource.CassandraUser{}
userNamespacedName3 := types.NamespacedName{Name: userManifest3.ObjectMeta.Name, Namespace: ns}
userNamespacedName3 := types.NamespacedName{Name: userManifest3.ObjectMeta.Name, Namespace: defaultNS}

Eventually(func() bool {
if err := k8sClient.Get(ctx, userNamespacedName1, &user1); err != nil {
Expand All @@ -275,7 +282,7 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
return false
}

if err := k8sClient.Get(ctx, secretNS, &secret); err != nil {
if err := k8sClient.Get(ctx, secretNamespacedName, &secret); err != nil {
return false
}

Expand Down

This file was deleted.

56 changes: 0 additions & 56 deletions controllers/tests/datatest/clusters_v1beta1_cassandra.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions controllers/tests/datatest/secret.yaml

This file was deleted.

Loading

0 comments on commit d44050e

Please sign in to comment.