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

Added Koperator end to end tests #987

Merged
merged 22 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
128 changes: 9 additions & 119 deletions tests/e2e/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,94 +16,6 @@ package e2e

import "time"

// HelmDescriptors.
var (
// certManagerHelmDescriptor describes the cert-manager Helm component.
certManagerHelmDescriptor = helmDescriptor{
Repository: "https://charts.jetstack.io",
ChartName: "cert-manager",
ChartVersion: "v1.11.0",
ReleaseName: "cert-manager",
Namespace: "cert-manager",
SetValues: map[string]string{
"installCRDs": "true",
},
RemoteCRDPathVersionTemplate: "https://github.com/jetstack/cert-manager/releases/download/v%s/cert-manager.crds.yaml",
}

// koperatorLocalHelmDescriptor describes the Koperator Helm component with
// a local chart and version.
koperatorLocalHelmDescriptor = helmDescriptor{
Repository: "../../charts/kafka-operator",
ChartVersion: LocalVersion,
ReleaseName: "kafka-operator",
Namespace: "kafka",
SetValues: map[string]string{
"crd.enabled": "true",
},
LocalCRDSubpaths: []string{"templates/crds.yaml"},
LocalCRDTemplateRenderValues: map[string]string{
"crd.enabled": "true",
},
}

// koperatorLocalHelmDescriptor describes the Koperator Helm component with
// a remote latest chart and version.
koperatorRemoteLatestHelmDescriptor = helmDescriptor{ //nolint:unused // Note: intentional possibly needed in the future for upgrade test.
Repository: "https://kubernetes-charts.banzaicloud.com",
ChartName: "kafka-operator",
ChartVersion: "", // Note: empty string translates to latest final version.
ReleaseName: "kafka-operator",
Namespace: "kafka",
SetValues: map[string]string{
"crd.enabled": "true",
},
RemoteCRDPathVersionTemplate: "https://github.com/banzaicloud/koperator/releases/download/%s/kafka-operator.crds.yaml",
}

// prometheusOperatorHelmDescriptor describes the prometheus-operator Helm
// component.
prometheusOperatorHelmDescriptor = helmDescriptor{
Repository: "https://prometheus-community.github.io/helm-charts",
ChartName: "kube-prometheus-stack",
ChartVersion: "42.0.1",
ReleaseName: "prometheus-operator",
Namespace: "prometheus",
SetValues: map[string]string{
"prometheusOperator.createCustomResource": "true",
"defaultRules.enabled": "false",
"alertmanager.enabled": "false",
"grafana.enabled": "false",
"kubeApiServer.enabled": "false",
"kubelet.enabled": "false",
"kubeControllerManager.enabled": "false",
"coreDNS.enabled": "false",
"kubeEtcd.enabled": "false",
"kubeScheduler.enabled": "false",
"kubeProxy.enabled": "false",
"kubeStateMetrics.enabled": "false",
"nodeExporter.enabled": "false",
"prometheus.enabled": "false",
},
}

// zookeeperOperatorHelmDescriptor describes the zookeeper-operator Helm
// component.
zookeeperOperatorHelmDescriptor = helmDescriptor{
Repository: "https://charts.pravega.io",
ChartName: "zookeeper-operator",
ChartVersion: "0.2.14",
ReleaseName: "zookeeper-operator",
Namespace: "zookeeper",
SetValues: map[string]string{
"crd.create": "true",
},
}
)

// Versions.
type Version = string

const (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really somewhat unsure if we should handle these consts like this. Instead I'd think it would be better to have them locally where they are relevant. Like for example we keep this file for stuff that we use everywhere, like default timeouts, some templates, that sort of thing. We also move all of the other stuff to where they are relevant, like kcat to the listener tests or zookeeper kind to the zookeeper tests.

What do others think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I better like this. I dont have to find const variables in different places especially when they can be used in other test files. Im not sure yet which const variable will be not used in another tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Im working and dont know have we got const variable for this so far or not then it is better to just check the const.go and use if there is. I dont like to waste time for searching in multiple files.


// LocalVersion means using the files in the local repository snapshot.
Expand Down Expand Up @@ -140,6 +52,14 @@ const (
kubectlNotFoundErrorMsg = "NotFound"
)

func apiGroupKoperatorDependencies() map[string]string {
return map[string]string{
"cert-manager": "cert-manager.io",
"zookeeper": "zookeeper.pravega.io",
"prometheus": "monitoring.coreos.com",
}
}

func basicK8sResourceKinds() []string {
return []string{
"pods",
Expand All @@ -162,36 +82,6 @@ func basicK8sResourceKinds() []string {
}
}

func certManagerCRDs() []string {
return []string{
"certificaterequests.cert-manager.io",
"certificates.cert-manager.io",
"challenges.acme.cert-manager.io",
"clusterissuers.cert-manager.io",
"issuers.cert-manager.io",
"orders.acme.cert-manager.io",
}
}

func prometheusCRDs() []string {
return []string{
"alertmanagerconfigs.monitoring.coreos.com",
"alertmanagers.monitoring.coreos.com",
"probes.monitoring.coreos.com",
"prometheuses.monitoring.coreos.com",
"prometheusrules.monitoring.coreos.com",
"servicemonitors.monitoring.coreos.com",
"thanosrulers.monitoring.coreos.com",
"podmonitors.monitoring.coreos.com",
}
}

func zookeeperCRDs() []string {
return []string{
"zookeeperclusters.zookeeper.pravega.io",
}
}

func koperatorCRDs() []string {
return []string{
"kafkatopics.kafka.banzaicloud.io",
Expand All @@ -201,7 +91,7 @@ func koperatorCRDs() []string {
}
}

func getKoperatorRelatedResourceKinds() []string {
func koperatorRelatedResourceKinds() []string {
return []string{
"nodepoollabelsets.labels.banzaicloud.io",
"kafkatopics.kafka.banzaicloud.io",
Expand Down
111 changes: 111 additions & 0 deletions tests/e2e/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright © 2023 Cisco Systems, Inc. and/or its affiliates
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"errors"
)

// HelmDescriptors.
var (
// certManagerHelmDescriptor describes the cert-manager Helm component.
certManagerHelmDescriptor = helmDescriptor{
Repository: "https://charts.jetstack.io",
ChartName: "cert-manager",
ChartVersion: "v1.11.0",
ReleaseName: "cert-manager",
Namespace: "cert-manager",
SetValues: map[string]string{
"installCRDs": "true",
},
RemoteCRDPathVersionTemplate: "https://github.com/jetstack/cert-manager/releases/download/v%s/cert-manager.crds.yaml",
}

// koperatorLocalHelmDescriptor describes the Koperator Helm component with
// a local chart and version.
koperatorLocalHelmDescriptor = helmDescriptor{
Repository: "../../charts/kafka-operator",
ChartVersion: LocalVersion,
ReleaseName: "kafka-operator",
Namespace: "kafka",
SetValues: map[string]string{
"crd.enabled": "true",
},
LocalCRDSubpaths: []string{"templates/crds.yaml"},
LocalCRDTemplateRenderValues: map[string]string{
"crd.enabled": "true",
},
}

// koperatorLocalHelmDescriptor describes the Koperator Helm component with
// a remote latest chart and version.
koperatorRemoteLatestHelmDescriptor = helmDescriptor{ //nolint:unused // Note: intentional possibly needed in the future for upgrade test.
Repository: "https://kubernetes-charts.banzaicloud.com",
ChartName: "kafka-operator",
ChartVersion: "", // Note: empty string translates to latest final version.
ReleaseName: "kafka-operator",
Namespace: "kafka",
SetValues: map[string]string{
"crd.enabled": "true",
},
RemoteCRDPathVersionTemplate: "https://github.com/banzaicloud/koperator/releases/download/%s/kafka-operator.crds.yaml",
}

// prometheusOperatorHelmDescriptor describes the prometheus-operator Helm
// component.
prometheusOperatorHelmDescriptor = helmDescriptor{
Repository: "https://prometheus-community.github.io/helm-charts",
ChartName: "kube-prometheus-stack",
ChartVersion: "42.0.1",
ReleaseName: "prometheus-operator",
Namespace: "prometheus",
SetValues: map[string]string{
"prometheusOperator.createCustomResource": "true",
"defaultRules.enabled": "false",
"alertmanager.enabled": "false",
"grafana.enabled": "false",
"kubeApiServer.enabled": "false",
"kubelet.enabled": "false",
"kubeControllerManager.enabled": "false",
"coreDNS.enabled": "false",
"kubeEtcd.enabled": "false",
"kubeScheduler.enabled": "false",
"kubeProxy.enabled": "false",
"kubeStateMetrics.enabled": "false",
"nodeExporter.enabled": "false",
"prometheus.enabled": "false",
},
}

// zookeeperOperatorHelmDescriptor describes the zookeeper-operator Helm
// component.
zookeeperOperatorHelmDescriptor = helmDescriptor{
Repository: "https://charts.pravega.io",
ChartName: "zookeeper-operator",
ChartVersion: "0.2.14",
ReleaseName: "zookeeper-operator",
Namespace: "zookeeper",
SetValues: map[string]string{
"crd.create": "true",
},
}

// dependencyCRDs storing the Koperator dependencies CRDs name
// It should be initialized once with the Initialize() member function
dependencyCRDs dependencyCRDsType

// ErrorNotFound is for handling that error case when resource is not found
ErrorNotFound = errors.New("not found")
)
2 changes: 1 addition & 1 deletion tests/e2e/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func applyK8sResourceFromTemplate(kubectlOptions k8s.KubectlOptions, templateFil
// extraArgs can be any kubectl api-resources parameter.
func listK8sResourceKinds(kubectlOptions k8s.KubectlOptions, apiGroupSelector string, extraArgs ...string) ([]string, error) {
logMsg := "Listing K8s resource kind"
args := []string{"api-resources", "--verbs", "list", "-output", "name", "--sort-by", "name"}
args := []string{"api-resources", "--verbs", "list", "--output", "name", "--sort-by", "name"}

if apiGroupSelector != "" {
logMsg = fmt.Sprintf("%s group selector: %s", logMsg, apiGroupSelector)
Expand Down
14 changes: 11 additions & 3 deletions tests/e2e/test_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ func testUninstall() bool {
var kubectlOptions k8s.KubectlOptions
var err error

It("Acquiring K8s config and context", func() {
kubectlOptions, err = kubectlOptionsForCurrentContext()
Expect(err).NotTo(HaveOccurred())
When("Initializing", func() {
It("Acquiring K8s config and context", func() {
kubectlOptions, err = kubectlOptionsForCurrentContext()
Expect(err).NotTo(HaveOccurred())
})

It("Setting globals", func() {
err := dependencyCRDs.Initialize(kubectlOptions)
Expect(err).NotTo(HaveOccurred())
})
Comment on lines +34 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This needs to be moved to the per case before once we handle that ticket. Nothing to do now.


})

requireUninstallingKoperator(k8s.KubectlOptions{
Expand Down
52 changes: 52 additions & 0 deletions tests/e2e/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package e2e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For some reason my file level commend does not work this morning.)

Optional: IMO this other than the version type which I commented, the rest of the file would fit into k8s.go with the dependencyCRDsType and the functions because we are doing k8s related ops with those.

I'm fine to leave this here if others agree it's more clear this way, but it's weird for me.


import (
"fmt"

"github.com/gruntwork-io/terratest/modules/k8s"
)

// Versions.
type Version = string
pregnor marked this conversation as resolved.
Show resolved Hide resolved

type dependencyCRDsType struct {
zookeeper []string
prometheus []string
certManager []string
}

func (c *dependencyCRDsType) Zookeeper() []string {
return c.zookeeper
}
func (c *dependencyCRDsType) Prometheus() []string {
return c.prometheus
}
func (c *dependencyCRDsType) CertManager() []string {
return c.certManager
}

func (c *dependencyCRDsType) Initialize(kubectlOptions k8s.KubectlOptions) error {
var err error
c.certManager, err = listK8sResourceKinds(kubectlOptions, apiGroupKoperatorDependencies()["cert-manager"])
if len(c.certManager) == 0 {
if err != nil {
return fmt.Errorf("initialize Cert-manager CRDs error: %w", err)
}
return fmt.Errorf("Cert-manager CRDs %w", ErrorNotFound)
}
c.prometheus, err = listK8sResourceKinds(kubectlOptions, apiGroupKoperatorDependencies()["prometheus"])
if len(c.prometheus) == 0 {
if err != nil {
return fmt.Errorf("initialize Prometheus CRDs error: %w", err)
}
return fmt.Errorf("Prometheus CRDs %w", ErrorNotFound)
}
c.zookeeper, err = listK8sResourceKinds(kubectlOptions, apiGroupKoperatorDependencies()["zookeeper"])
if len(c.zookeeper) == 0 {
if err != nil {
return fmt.Errorf("initialize Zookeeper CRDs error: %w", err)
}
return fmt.Errorf("Zookeeper CRDs %w", ErrorNotFound)
}
return nil
}
Loading