Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 111348f

Browse files
Kuveszpregnorbartam1panyuenlau
authored
Add kafka cluster create test (#988)
* test(docs/install): added install e2e test * test(docs/install): added localversion 4 Koperator * feat(e2e): added uninstall koperator and dep * fix: make ordered root container * fix: typos * refact 1 * refact 2 * add(beta): topic produce-consume test * refactor 3 * refactor 4 * refactor 5 * add(beta) example for external produce consume * Fix getK8sResources * fix: checking all resource type * refactor 6 * add: more log messages * add(beta) zookeepercluster remove * fix: remove warnings from output * add: const.go * fix: zookeeper import * refactor 7 * refactor 8 * fix: remove David test * fix: typo * Initial simplekafkaclsuter test * Updated zookeper address to zookeeper-server * Updated tests to use Marton's wait function * Various small fixes, added uninstall steps * Various small fixes * Random updates regarding reviews * Update after rebase * add: const.go * added ssl kafkacluster * Removed debugging stuff accidentally left there * refactor 7 * refactor 8 * Initial simplekafkaclsuter test * Updated tests to use Marton's wait function * added ssl kafkacluster * Updated to latest of the uninstall branch * Fixes after messing up the rebase a bit * fix: remove zookeeperclusterready fn * remove: unnecessary tests * add: externalListener go-template * Updates requested by reviews * Using time.Duration everywhere * remove: ordered keyword from unnecessary places * fix: uninstallHelmChartIfExists * fix: typos * refactor: based on Kuvesz review * Fixed rest of review comments * remove: external consumer-producer test (another PR) * Remove unnecessary timeout check * fix: requireUninstallingKoperator description * Update zookeeper_cluster_test.go * Update zookeeper_cluster_test.go * Update tests/e2e/koperator_test.go Co-authored-by: Darren Lau <[email protected]> * Update kafka_cluster_test.go * Update zookeeper_cluster_test.go * Updated implementation to reflect changes on master * fixed rebase messup * Review updates, removed zookeeper renaming * Updated configmap_test zookeeper name to original * updates requested in reviews * added debug error log --------- Co-authored-by: Patrik Egyed <[email protected]> Co-authored-by: marbarta <[email protected]> Co-authored-by: Darren Lau <[email protected]> Co-authored-by: Kuvesz <[email protected]>
1 parent 2d4c6d4 commit 111348f

File tree

7 files changed

+183
-9
lines changed

7 files changed

+183
-9
lines changed

tests/e2e/const.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,23 @@ const (
4444
zookeeperClusterName = "zookeeper-server"
4545
managedByHelmLabelTemplate = "app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=%s"
4646

47+
cruiseControlPodReadinessTimeout = 50 * time.Second
48+
kafkaClusterResourceReadinessTimeout = 60 * time.Second
4749
defaultDeletionTimeout = 20 * time.Second
4850
defaultPodReadinessWaitTime = 10 * time.Second
4951
defaultTopicCreationWaitTime = 10 * time.Second
50-
kafkaClusterResourceCleanupTimeout = 30 * time.Second
52+
kafkaClusterCreateTimeout = 500 * time.Second
53+
kafkaClusterResourceCleanupTimeout = 120 * time.Second
54+
zookeeperClusterCreateTimeout = 4 * time.Minute
5155
zookeeperClusterResourceCleanupTimeout = 60 * time.Second
5256
externalConsumerTimeout = 5 * time.Second
5357
externalProducerTimeout = 5 * time.Second
5458

55-
kcatPodTemplate = "templates/kcat.yaml.tmpl"
56-
kafkaTopicTemplate = "templates/topic.yaml.tmpl"
59+
zookeeperClusterReplicaCount = 1
60+
61+
kcatPodTemplate = "templates/kcat.yaml.tmpl"
62+
kafkaTopicTemplate = "templates/topic.yaml.tmpl"
63+
zookeeperClusterTemplate = "templates/zookeeper_cluster.yaml.tmpl"
5764

5865
kubectlNotFoundErrorMsg = "NotFound"
5966
)

tests/e2e/helm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ func listHelmReleases(kubectlOptions k8s.KubectlOptions) ([]*HelmRelease, error)
313313
"list",
314314
"--output", "json",
315315
)
316+
316317
if err != nil {
317318
return nil, errors.WrapIf(err, "listing Helm releases failed")
318319
}

tests/e2e/install_cluster.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright © 2023 Cisco Systems, Inc. and/or its affiliates
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"time"
21+
22+
"github.com/banzaicloud/koperator/api/v1beta1"
23+
"github.com/gruntwork-io/terratest/modules/k8s"
24+
25+
. "github.com/onsi/ginkgo/v2"
26+
. "github.com/onsi/gomega"
27+
)
28+
29+
// requireCreatingKafkaCluster creates a KafkaCluster and
30+
// checks the success of that operation.
31+
func requireCreatingKafkaCluster(kubectlOptions k8s.KubectlOptions, manifestPath string) {
32+
It("Deploying a KafkaCluster", func() {
33+
34+
By("Checking existing KafkaClusters")
35+
found := isExistingK8SResource(kubectlOptions, kafkaKind, kafkaClusterName)
36+
if found {
37+
By(fmt.Sprintf("KafkaCluster %s already exists\n", kafkaClusterName))
38+
} else {
39+
By("Deploying a KafkaCluster")
40+
applyK8sResourceManifest(kubectlOptions, manifestPath)
41+
}
42+
43+
By("Verifying the KafkaCluster state")
44+
err := waitK8sResourceCondition(kubectlOptions, kafkaKind, fmt.Sprintf("jsonpath={.status.state}=%s", string(v1beta1.KafkaClusterRunning)), kafkaClusterCreateTimeout, "", kafkaClusterName)
45+
Expect(err).NotTo(HaveOccurred())
46+
47+
By("Verifying the CruiseControl pod")
48+
Eventually(context.Background(), func() error {
49+
return waitK8sResourceCondition(kubectlOptions, "pod", "condition=Ready", cruiseControlPodReadinessTimeout, v1beta1.KafkaCRLabelKey+"="+kafkaClusterName+",app=cruisecontrol", "")
50+
}, kafkaClusterResourceReadinessTimeout, 3*time.Second).ShouldNot(HaveOccurred())
51+
52+
By("Verifying all Kafka pods")
53+
err = waitK8sResourceCondition(kubectlOptions, "pod", "condition=Ready", defaultPodReadinessWaitTime, v1beta1.KafkaCRLabelKey+"="+kafkaClusterName, "")
54+
Expect(err).NotTo(HaveOccurred())
55+
})
56+
}
57+
58+
// requireCreatingZookeeperCluster creates a ZookeeperCluster and
59+
// checks the success of that operation.
60+
func requireCreatingZookeeperCluster(kubectlOptions k8s.KubectlOptions) {
61+
It("Deploying a ZookeeperCluster", func() {
62+
63+
By("Checking existing ZookeeperClusters")
64+
found := isExistingK8SResource(kubectlOptions, zookeeperKind, zookeeperClusterName)
65+
if found {
66+
By(fmt.Sprintf("ZookeeperCluster %s already exists\n", zookeeperClusterName))
67+
} else {
68+
By("Deploying the sample ZookeeperCluster")
69+
err := applyK8sResourceFromTemplate(kubectlOptions,
70+
zookeeperClusterTemplate,
71+
map[string]interface{}{
72+
"Name": zookeeperClusterName,
73+
"Namespace": kubectlOptions.Namespace,
74+
"Replicas": zookeeperClusterReplicaCount,
75+
},
76+
)
77+
Expect(err).NotTo(HaveOccurred())
78+
}
79+
80+
By("Verifying the ZookeeperCluster resource")
81+
err := waitK8sResourceCondition(kubectlOptions, zookeeperKind, "jsonpath={.status.readyReplicas}=1", zookeeperClusterCreateTimeout, "", zookeeperClusterName)
82+
Expect(err).NotTo(HaveOccurred())
83+
84+
By("Verifying the ZookeeperCluster's pods")
85+
err = waitK8sResourceCondition(kubectlOptions, "pod", "condition=Ready", defaultPodReadinessWaitTime, "app="+zookeeperClusterName, "")
86+
Expect(err).NotTo(HaveOccurred())
87+
})
88+
}

tests/e2e/k8s.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ func applyK8sResourceManifest(kubectlOptions k8s.KubectlOptions, manifestPath st
5151
k8s.KubectlApply(GinkgoT(), &kubectlOptions, manifestPath)
5252
}
5353

54+
// isExistingK8SResource queries a Resource by it's kind, namespace and name and
55+
// returns true if it's found, false otherwise
56+
func isExistingK8SResource(
57+
kubectlOptions k8s.KubectlOptions,
58+
resourceKind string,
59+
resourceName string,
60+
) bool {
61+
By(fmt.Sprintf("Checking the existence of resource %s in namespace %s (kind: %s)", resourceName, kubectlOptions.Namespace, resourceKind))
62+
err := k8s.RunKubectlE(GinkgoT(), &kubectlOptions, "get", resourceKind, resourceName)
63+
if err != nil {
64+
By(fmt.Sprintf("Received error when getting resource: %s", err))
65+
return false
66+
}
67+
return true
68+
}
69+
5470
// createOrReplaceK8sResourcesFromManifest creates non-existent Kubernetes
5571
// resources or replaces existing ones from the specified manifest to the
5672
// provided kubectl context and namespace.

tests/e2e/koperator_suite_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ var _ = BeforeSuite(func() {
5454
})
5555

5656
var _ = When("Testing e2e test altogether", Ordered, func() {
57-
// testInstall()
58-
testProduceConsumeExternal("kafka-controller")
59-
// testProduceConsumeInternal()
60-
// testUninstallZookeeperCluster()
61-
// testUninstallKafkaCluster()
62-
// testUninstall()
57+
//testInstall()
58+
testInstallZookeeperCluster()
59+
testInstallKafkaCluster("../../config/samples/simplekafkacluster.yaml")
60+
testUninstallKafkaCluster()
61+
testInstallKafkaCluster("../../config/samples/simplekafkacluster_ssl.yaml")
62+
testUninstallKafkaCluster()
63+
testUninstallZookeeperCluster()
64+
//testUninstall()
6365
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: zookeeper.pravega.io/v1beta1
2+
kind: ZookeeperCluster
3+
metadata:
4+
name: {{ .Name }}
5+
namespace: {{ or .Namespace "zookeeper" }}
6+
spec:
7+
replicas: {{ or .Replicas 1 }}
8+
persistence:
9+
reclaimPolicy: Delete

tests/e2e/test_install_cluster.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright © 2023 Cisco Systems, Inc. and/or its affiliates
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"github.com/gruntwork-io/terratest/modules/k8s"
19+
. "github.com/onsi/ginkgo/v2"
20+
. "github.com/onsi/gomega"
21+
)
22+
23+
func testInstallZookeeperCluster() bool {
24+
return When("Installing Zookeeper cluster", func() {
25+
var kubectlOptions k8s.KubectlOptions
26+
var err error
27+
28+
It("Acquiring K8s config and context", func() {
29+
kubectlOptions, err = kubectlOptionsForCurrentContext()
30+
Expect(err).NotTo(HaveOccurred())
31+
})
32+
33+
kubectlOptions.Namespace = zookeeperOperatorHelmDescriptor.Namespace
34+
requireCreatingZookeeperCluster(kubectlOptions)
35+
})
36+
}
37+
38+
func testInstallKafkaCluster(kafkaClusterManifestPath string) bool {
39+
return When("Installing Kafka cluster", func() {
40+
var kubectlOptions k8s.KubectlOptions
41+
var err error
42+
43+
It("Acquiring K8s config and context", func() {
44+
kubectlOptions, err = kubectlOptionsForCurrentContext()
45+
Expect(err).NotTo(HaveOccurred())
46+
})
47+
48+
kubectlOptions.Namespace = koperatorLocalHelmDescriptor.Namespace
49+
requireCreatingKafkaCluster(kubectlOptions, kafkaClusterManifestPath)
50+
})
51+
}

0 commit comments

Comments
 (0)