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

Opensearch User integration test #560

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion controllers/clusters/opensearch_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var _ = Describe("OpenSearch Controller", func() {
openSearchNamespacedName := types.NamespacedName{Name: openSearchManifest.ObjectMeta.Name, Namespace: defaultNS}

ctx := context.Background()
clusterID := openSearchManifest.Spec.Name + openapi.CreatedID

When("apply a OpenSearch manifest", func() {
It("should create a OpenSearch resources", func() {
Expand All @@ -58,7 +59,7 @@ var _ = Describe("OpenSearch Controller", func() {
return false
}

return openSearch.Status.ID == openapi.CreatedID
return openSearch.Status.ID == clusterID
}).Should(BeTrue())

<-done
Expand Down
89 changes: 46 additions & 43 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 Expand Up @@ -411,7 +418,3 @@ var _ = Describe("Basic Cassandra User controller + Basic Cassandra cluster cont
})
})
})

func removeUserByIndex(s []*v1beta1.UserReference, index int) []*v1beta1.UserReference {
return append(s[:index], s[index+1:]...)
}

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.

10 changes: 9 additions & 1 deletion controllers/tests/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package tests

import "time"
import (
"time"

"github.com/instaclustr/operator/apis/clusters/v1beta1"
)

// NewChannelWithTimeout creates a new channel that will be closed after a timeout.
// This function is useful for synchronizing the execution of asynchronous assertion functions, such as Eventually().
Expand All @@ -12,3 +16,7 @@ func NewChannelWithTimeout(timeout time.Duration) chan struct{} {

return done
}

func removeUserByIndex(s []*v1beta1.UserReference, index int) []*v1beta1.UserReference {
return append(s[:index], s[index+1:]...)
}
Loading