Skip to content

Commit

Permalink
fix failed job. refresh integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ribaraka committed Aug 31, 2023
1 parent 05bd37a commit fee0242
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 508 deletions.
28 changes: 5 additions & 23 deletions controllers/clusters/cassandra_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package clusters
import (
"context"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -29,21 +28,13 @@ import (

"github.com/instaclustr/operator/apis/clusters/v1beta1"
openapi "github.com/instaclustr/operator/pkg/instaclustr/mock/server/go"
"github.com/instaclustr/operator/pkg/models"
)

const newCassandraNodeSize = "CAS-DEV-t4g.small-30"

var _ = Describe("Cassandra Controller", func() {
var (
ns = "default"

cassandra v1beta1.Cassandra
cassandraManifest v1beta1.Cassandra

timeout = time.Second * 40
interval = time.Second * 2
)
cassandra := v1beta1.Cassandra{}
cassandraManifest := v1beta1.Cassandra{}

yfile, err := os.ReadFile("datatest/cassandra_v1beta1.yaml")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -54,15 +45,13 @@ var _ = Describe("Cassandra Controller", func() {
ctx := context.Background()

clusterID := cassandraManifest.Spec.Name + openapi.CreatedID
cassandraNamespacedName := types.NamespacedName{Name: cassandraManifest.ObjectMeta.Name, Namespace: ns}
cassandraNamespacedName := types.NamespacedName{Name: cassandraManifest.ObjectMeta.Name, Namespace: defaultNS}

When("apply a cassandra manifest", func() {
It("should create a cassandra resources", func() {
Expect(k8sClient.Create(ctx, &cassandraManifest)).Should(Succeed())
By("sending cassandra specification to the Instaclustr API and get ID of created cluster.")

Eventually(func() bool {

if err := k8sClient.Get(ctx, cassandraNamespacedName, &cassandra); err != nil {
return false
}
Expand All @@ -75,16 +64,13 @@ var _ = Describe("Cassandra Controller", func() {
When("changing a node size", func() {
It("should update a cassandra resources", func() {
Expect(k8sClient.Get(ctx, cassandraNamespacedName, &cassandra)).Should(Succeed())
patch := cassandra.NewPatch()

patch := cassandra.NewPatch()
cassandra.Spec.DataCentres[0].NodeSize = newCassandraNodeSize

cassandra.Annotations = map[string]string{models.ResourceStateAnnotation: models.UpdatingEvent}
Expect(k8sClient.Patch(ctx, &cassandra, patch)).Should(Succeed())

By("sending a resize request to the Instaclustr API. And when the resize is completed, " +
"the status job get new data from the InstAPI and update it in k8s cassandra resource")

Eventually(func() bool {
if err := k8sClient.Get(ctx, cassandraNamespacedName, &cassandra); err != nil {
return false
Expand All @@ -102,19 +88,15 @@ var _ = Describe("Cassandra Controller", func() {
When("delete the cassandra resource", func() {
It("should send delete request to the Instaclustr API", func() {
Expect(k8sClient.Get(ctx, cassandraNamespacedName, &cassandra)).Should(Succeed())

cassandra.Annotations = map[string]string{models.ResourceStateAnnotation: models.DeletingEvent}

Expect(k8sClient.Delete(ctx, &cassandra)).Should(Succeed())

By("sending delete request to Instaclustr API")
Eventually(func() bool {
err := k8sClient.Get(ctx, cassandraNamespacedName, &cassandra)
if err != nil && !k8serrors.IsNotFound(err) {
return false
}

return true
return k8serrors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())
})
})
Expand Down
3 changes: 3 additions & 0 deletions controllers/clusters/datatest/kafka_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: clusters.instaclustr.com/v1beta1
kind: Kafka
metadata:
name: kafka
namespace: default
annotations:
defaulter: webhook
spec:
name: "kafka"
version: "2.8.2"
Expand Down
3 changes: 3 additions & 0 deletions controllers/clusters/datatest/kafkaconnect_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: clusters.instaclustr.com/v1beta1
kind: KafkaConnect
metadata:
name: kafkaconnect-sample
namespace: default
annotations:
defaulter: webhook
spec:
dataCentres:
- name: "US_EAST_1_DC_KAFKA"
Expand Down
3 changes: 3 additions & 0 deletions controllers/clusters/datatest/opensearch_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: clusters.instaclustr.com/v1beta1
kind: OpenSearch
metadata:
name: opensearch
namespace: default
annotations:
defaulter: webhook
spec:
alertingPlugin: false
anomalyDetectionPlugin: false
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/datatest/postgresql_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: clusters.instaclustr.com/v1beta1
kind: PostgreSQL
metadata:
name: postgresql-sample
namespace: default
annotations:
testAnnotation: test
spec:
Expand Down
4 changes: 3 additions & 1 deletion controllers/clusters/datatest/redis_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ apiVersion: clusters.instaclustr.com/v1beta1
kind: Redis
metadata:
name: redis-sample
namespace: default
annotations:
defaulter: webhook
spec:
name: "testRedis"
version: "7.0.5"
slaTier: "NON_PRODUCTION"
pciCompliance: true
concurrentResizes: 1
clientToNodeEncryption: true
privateNetworkCluster: true
notifySupportContacts: true
Expand Down
3 changes: 3 additions & 0 deletions controllers/clusters/datatest/zookeeper_v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: clusters.instaclustr.com/v1beta1
kind: Zookeeper
metadata:
name: zookeeper-sample
namespace: default
annotations:
defaulter: webhook
spec:
dataCentres:
- clientToServerEncryption: true
Expand Down
62 changes: 18 additions & 44 deletions controllers/clusters/kafka_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,109 +19,83 @@ package clusters
import (
"context"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/instaclustr/operator/apis/clusters/v1beta1"
openapi "github.com/instaclustr/operator/pkg/instaclustr/mock/server/go"
"github.com/instaclustr/operator/pkg/models"
)

const newKafkaNodeSize = "KFK-DEV-t4g.medium-80"

var _ = Describe("Kafka Controller", func() {
var (
kafkaResource v1beta1.Kafka
kafkaYAML v1beta1.Kafka
k = "kafka"
ns = "default"
kafkaNS = types.NamespacedName{Name: k, Namespace: ns}
timeout = time.Second * 40
interval = time.Second * 2
)
kafka := v1beta1.Kafka{}
kafkaManifest := v1beta1.Kafka{}

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

err = yaml.Unmarshal(yfile, &kafkaYAML)
err = yaml.Unmarshal(yfile, &kafkaManifest)
Expect(err).NotTo(HaveOccurred())

kafkaObjMeta := metav1.ObjectMeta{
Name: k,
Namespace: ns,
Annotations: map[string]string{
models.ResourceStateAnnotation: models.CreatingEvent,
},
}

kafkaYAML.ObjectMeta = kafkaObjMeta
kafkaNamespacedName := types.NamespacedName{Name: kafkaManifest.ObjectMeta.Name, Namespace: defaultNS}

ctx := context.Background()

When("apply a Kafka manifest", func() {
It("should create a Kafka resources", func() {
Expect(k8sClient.Create(ctx, &kafkaYAML)).Should(Succeed())
Expect(k8sClient.Create(ctx, &kafkaManifest)).Should(Succeed())
By("sending Kafka specification to the Instaclustr API and get ID of created cluster.")

Eventually(func() bool {
if err := k8sClient.Get(ctx, kafkaNS, &kafkaResource); err != nil {
if err := k8sClient.Get(ctx, kafkaNamespacedName, &kafka); err != nil {
return false
}

return kafkaResource.Status.ID == openapi.CreatedID
return kafka.Status.ID == openapi.CreatedID
}).Should(BeTrue())
})
})

When("changing a node size", func() {
It("should update a Kafka resources", func() {
Expect(k8sClient.Get(ctx, kafkaNS, &kafkaResource)).Should(Succeed())
patch := kafkaResource.NewPatch()
Expect(k8sClient.Get(ctx, kafkaNamespacedName, &kafka)).Should(Succeed())

kafkaResource.Spec.DataCentres[0].NodeSize = newKafkaNodeSize

kafkaResource.Annotations = map[string]string{models.ResourceStateAnnotation: models.UpdatingEvent}
Expect(k8sClient.Patch(ctx, &kafkaResource, patch)).Should(Succeed())
patch := kafka.NewPatch()
kafka.Spec.DataCentres[0].NodeSize = newKafkaNodeSize
Expect(k8sClient.Patch(ctx, &kafka, patch)).Should(Succeed())

By("sending a resize request to the Instaclustr API. And when the resize is completed, " +
"the status job get new data from the InstAPI and update it in k8s Kafka resource")

Eventually(func() bool {
if err := k8sClient.Get(ctx, kafkaNS, &kafkaResource); err != nil {
if err := k8sClient.Get(ctx, kafkaNamespacedName, &kafka); err != nil {
return false
}

if len(kafkaResource.Status.DataCentres) == 0 || len(kafkaResource.Status.DataCentres[0].Nodes) == 0 {
if len(kafka.Status.DataCentres) == 0 || len(kafka.Status.DataCentres[0].Nodes) == 0 {
return false
}

return kafkaResource.Status.DataCentres[0].Nodes[0].Size == newKafkaNodeSize
return kafka.Status.DataCentres[0].Nodes[0].Size == newKafkaNodeSize
}, timeout, interval).Should(BeTrue())
})
})

When("delete the Kafka resource", func() {
It("should send delete request to the Instaclustr API", func() {
Expect(k8sClient.Get(ctx, kafkaNS, &kafkaResource)).Should(Succeed())

kafkaResource.Annotations = map[string]string{models.ResourceStateAnnotation: models.DeletingEvent}

Expect(k8sClient.Delete(ctx, &kafkaResource)).Should(Succeed())

Expect(k8sClient.Get(ctx, kafkaNamespacedName, &kafka)).Should(Succeed())
Expect(k8sClient.Delete(ctx, &kafka)).Should(Succeed())
By("sending delete request to Instaclustr API")
Eventually(func() bool {
err := k8sClient.Get(ctx, kafkaNS, &kafkaResource)
err := k8sClient.Get(ctx, kafkaNamespacedName, &kafka)
if err != nil && !k8serrors.IsNotFound(err) {
return false
}

return true
return k8serrors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())
})
})
Expand Down
Loading

0 comments on commit fee0242

Please sign in to comment.