From 666e1a71c6e1523683552c2c8f8318e209a0323e Mon Sep 17 00:00:00 2001 From: Carlos Salas Date: Wed, 26 Jul 2023 18:22:12 +0200 Subject: [PATCH] Revert "fix: align Makefile and test/e2e with master" This reverts commit 41b5a0bbb77cc49fd30af5ac9a11449ebd056861. --- Makefile | 117 +-------- test/e2e/Dockerfile.e2e | 26 -- test/e2e/basic_cluster_test.go | 59 ----- test/e2e/config/config.go | 155 ------------ test/e2e/config/config.yaml | 13 - test/e2e/suite_test.go | 348 -------------------------- test/e2e/templates/basic-cluster.yaml | 37 --- 7 files changed, 1 insertion(+), 754 deletions(-) delete mode 100644 test/e2e/Dockerfile.e2e delete mode 100644 test/e2e/basic_cluster_test.go delete mode 100644 test/e2e/config/config.go delete mode 100644 test/e2e/config/config.yaml delete mode 100644 test/e2e/suite_test.go delete mode 100644 test/e2e/templates/basic-cluster.yaml diff --git a/Makefile b/Makefile index 8898ecfb..a59c8d3b 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,5 @@ TARGETS := $(shell ls scripts) -ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -BIN_DIR := $(abspath $(ROOT_DIR)/bin) -GO_INSTALL = ./scripts/go_install.sh -CLUSTER_NAME?="eks-operator-e2e" -GIT_COMMIT?=$(shell git rev-parse HEAD) -GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD) -GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" ) -TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT} -REPO?=ghcr.io/rancher/eks-operator -E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/config.yaml -CHART_VERSION?=$(subst v,,$(GIT_TAG)) -RAWCOMMITDATE=$(shell git log -n1 --format="%at") -OPERATOR_CHART?=$(shell find $(ROOT_DIR) -type f -name "rancher-eks-operator-[0-9]*.tgz" -print) -CRD_CHART?=$(shell find $(ROOT_DIR) -type f -name "rancher-eks-operator-crd*.tgz" -print) - -ifeq ($(shell go env GOOS),darwin) # Use the darwin/amd64 binary until an arm64 version is available - COMMITDATE?=$(shell gdate -d @"${RAWCOMMITDATE}" "+%FT%TZ") -else - COMMITDATE?=$(shell date -d @"${RAWCOMMITDATE}" "+%FT%TZ") -endif - -MOCKGEN_VER := v1.6.0 -MOCKGEN_BIN := mockgen -MOCKGEN := $(BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER) - -GINKGO_VER := v2.9.4 -GINKGO_BIN := ginkgo -GINKGO := $(BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER) - .dapper: @echo Downloading dapper @curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp @@ -36,96 +7,10 @@ GINKGO := $(BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER) @./.dapper.tmp -v @mv .dapper.tmp .dapper -.PHONY: $(TARGETS) $(TARGETS): .dapper ./.dapper $@ -$(MOCKGEN): - GOBIN=$(BIN_DIR) $(GO_INSTALL) github.com/golang/mock/mockgen $(MOCKGEN_BIN) $(MOCKGEN_VER) - -$(GINKGO): - GOBIN=$(BIN_DIR) $(GO_INSTALL) github.com/onsi/ginkgo/v2/ginkgo $(GINKGO_BIN) $(GINKGO_VER) - -.PHONY: operator -operator: - go build -o bin/eks-operator main.go - -.PHONY: generate-go -generate-go: $(MOCKGEN) - go generate ./pkg/eks/... - -.PHONY: generate-crd -generate-crd: $(MOCKGEN) - go generate main.go - -.PHONY: generate -generate: - $(MAKE) generate-go - $(MAKE) generate-crd - -ALL_VERIFY_CHECKS = generate - -.PHONY: verify -verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) - -.PHONY: verify-generate -verify-generate: generate - @if !(git diff --quiet HEAD); then \ - git diff; \ - echo "generated files are out of date, run make generate"; exit 1; \ - fi - -.PHONY: test -test: $(GINKGO) - $(GINKGO) -v -r --trace --race ./pkg/... ./controller/... - -.PHONY: clean clean: rm -rf build bin dist -.PHONY: operator-chart -operator-chart: - mkdir -p $(BIN_DIR) - cp -rf $(ROOT_DIR)/charts/eks-operator $(BIN_DIR)/chart - sed -i -e 's/tag:.*/tag: '${TAG}'/' $(BIN_DIR)/chart/values.yaml - sed -i -e 's|repository:.*|repository: '${REPO}'|' $(BIN_DIR)/chart/values.yaml - helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(BIN_DIR)/ $(BIN_DIR)/chart - rm -Rf $(BIN_DIR)/chart - -.PHONY: crd-chart -crd-chart: - mkdir -p $(BIN_DIR) - helm package --version ${CHART_VERSION} --app-version ${GIT_TAG} -d $(BIN_DIR)/ $(ROOT_DIR)/charts/eks-operator-crd - rm -Rf $(BIN_DIR)/chart - -.PHONY: charts -charts: - $(MAKE) operator-chart - $(MAKE) crd-chart - -.PHONY: setup-kind -setup-kind: - $(ROOT_DIR)/scripts/setup-kind-cluster.sh - -.PHONY: e2e-tests -e2e-tests: $(GINKGO) charts - export EXTERNAL_IP=`kubectl get nodes -o jsonpath='{.items[].status.addresses[?(@.type == "InternalIP")].address}'` && \ - export BRIDGE_IP="172.18.0.1" && \ - export CONFIG_PATH=$(E2E_CONF_FILE) && \ - export OPERATOR_CHART=$(OPERATOR_CHART) && \ - export CRD_CHART=$(CRD_CHART) && \ - cd $(ROOT_DIR)/test && $(GINKGO) -r -v ./e2e - -.PHONY: kind-e2e-tests -kind-e2e-tests: docker-build-e2e setup-kind - kind load docker-image --name $(CLUSTER_NAME) ${REPO}:${TAG} - $(MAKE) e2e-tests - -.PHONY: docker-build-e2e -docker-build-e2e: - DOCKER_BUILDKIT=1 docker build \ - -f test/e2e/Dockerfile.e2e \ - --build-arg "TAG=${GIT_TAG}" \ - --build-arg "COMMIT=${GIT_COMMIT}" \ - --build-arg "COMMITDATE=${COMMITDATE}" \ - -t ${REPO}:${TAG} . +.PHONY: $(TARGETS) diff --git a/test/e2e/Dockerfile.e2e b/test/e2e/Dockerfile.e2e deleted file mode 100644 index 2c34acd6..00000000 --- a/test/e2e/Dockerfile.e2e +++ /dev/null @@ -1,26 +0,0 @@ -FROM registry.suse.com/bci/golang:1.19 AS build -RUN zypper -n install -l openssl-devel -WORKDIR /src -COPY go.mod go.sum /src/ -RUN go mod download -COPY main.go /src/ -COPY controller /src/controller -COPY pkg /src/pkg -COPY templates /src/templates -COPY utils /src/utils -FROM build AS build-operator -ARG TAG=v0.0.0 -ARG COMMIT="" -ARG COMMITDATE="" -ENV CGO_ENABLED=0 -RUN go build \ - -ldflags "-w -s \ - -X github.com/rancher/eks-operator/pkg/version.Version=$TAG \ - -X github.com/rancher/eks-operator/pkg/version.Commit=$COMMIT \ - -X github.com/rancher/eks-operator/pkg/version.CommitDate=$COMMITDATE" \ - -o /usr/sbin/eks-operator . - -FROM scratch AS eks-operator -COPY --from=build /var/lib/ca-certificates/ca-bundle.pem /etc/ssl/certs/ca-certificates.crt -COPY --from=build-operator /usr/sbin/eks-operator /usr/sbin/eks-operator -ENTRYPOINT ["/usr/sbin/eks-operator"] diff --git a/test/e2e/basic_cluster_test.go b/test/e2e/basic_cluster_test.go deleted file mode 100644 index 2f1e40ef..00000000 --- a/test/e2e/basic_cluster_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package e2e - -import ( - "fmt" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - eksv1 "github.com/rancher/eks-operator/pkg/apis/eks.cattle.io/v1" - managementv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" -) - -var _ = Describe("BasicCluster", func() { - var eksConfig *eksv1.EKSClusterConfig - var cluster *managementv3.Cluster - - BeforeEach(func() { - var ok bool - eksConfig, ok = clusterTemplates[basicClusterTemplateName] - Expect(ok).To(BeTrue()) - Expect(eksConfig).NotTo(BeNil()) - - cluster = &managementv3.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: eksConfig.Name, - Namespace: eksClusterConfigNamespace, - }, - Spec: managementv3.ClusterSpec{ - EKSConfig: &eksConfig.Spec, - }, - } - - }) - - It("Succesfully creates a cluster", func() { - By("Creating a cluster") - Expect(cl.Create(ctx, cluster)).Should(Succeed()) - - By("Waiting for cluster to be ready") - Eventually(func() error { - currentCluster := &eksv1.EKSClusterConfig{} - - if err := cl.Get(ctx, runtimeclient.ObjectKey{ - Name: cluster.Name, - Namespace: eksClusterConfigNamespace, - }, currentCluster); err != nil { - return err - } - - if currentCluster.Status.Phase == "active" { - return nil - } - - return fmt.Errorf("cluster is not ready yet. Current phase: %s", currentCluster.Status.Phase) - }, waitLong, pollInterval).ShouldNot(HaveOccurred()) - }) -}) diff --git a/test/e2e/config/config.go b/test/e2e/config/config.go deleted file mode 100644 index c0f7d2a4..00000000 --- a/test/e2e/config/config.go +++ /dev/null @@ -1,155 +0,0 @@ -package config - -import ( - "errors" - "fmt" - "os" - - "github.com/drone/envsubst/v2" - "sigs.k8s.io/yaml" -) - -type E2EConfig struct { - OperatorChart string `yaml:"operatorChart"` - CRDChart string `yaml:"crdChart"` - ExternalIP string `yaml:"externalIP"` - MagicDNS string `yaml:"magicDNS"` - BridgeIP string `yaml:"bridgeIP"` - ArtifactsDir string `yaml:"artifactsDir"` - - CertManagerVersion string `yaml:"certManagerVersion"` - CertManagerChartURL string `yaml:"certManagerChartURL"` - - RancherVersion string `yaml:"rancherVersion"` - RancherChartURL string `yaml:"rancherChartURL"` - - AWSAccessKey string `yaml:"awsAccessKey"` - AWSSecretAccessKey string `yaml:"awsSecretAccessKey"` - - AWSRegion string `yaml:"awsRegion"` -} - -// ReadE2EConfig read config from yaml and substitute variables using envsubst. -// All variables can be overridden by environmental variables. -func ReadE2EConfig(configPath string) (*E2EConfig, error) { //nolint:gocyclo - config := &E2EConfig{} - - configData, err := os.ReadFile(configPath) - if err != nil { - return nil, fmt.Errorf("failed to read config file: %w", err) - } - - if configData == nil { - return nil, errors.New("config file can't be empty") - } - - if err := yaml.Unmarshal(configData, config); err != nil { - return nil, fmt.Errorf("failed to unmarhal config file: %s", err) - } - - if operatorChart := os.Getenv("OPERATOR_CHART"); operatorChart != "" { - config.OperatorChart = operatorChart - } - - if config.OperatorChart == "" { - return nil, errors.New("no OPERATOR_CHART provided, an operator helm chart is required to run e2e tests") - } - - if crdChart := os.Getenv("CRD_CHART"); crdChart != "" { - config.CRDChart = crdChart - } - - if config.CRDChart == "" { - return nil, errors.New("no CRD_CHART provided, a crd helm chart is required to run e2e tests") - } - - if externalIP := os.Getenv("EXTERNAL_IP"); externalIP != "" { - config.ExternalIP = externalIP - } - - if config.ExternalIP == "" { - return nil, errors.New("no EXTERNAL_IP provided, a known (reachable) node external ip it is required to run e2e tests") - } - - if magicDNS := os.Getenv("MAGIC_DNS"); magicDNS != "" { - config.MagicDNS = magicDNS - } - - if bridgeIP := os.Getenv("BRIDGE_IP"); bridgeIP != "" { - config.BridgeIP = bridgeIP - } - - if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" { - config.ArtifactsDir = artifactsDir - } - - if awsAccessKey := os.Getenv("AWS_ACCESS_KEY_ID"); awsAccessKey != "" { - config.AWSAccessKey = awsAccessKey - } - - if awsSecretAccessKey := os.Getenv("AWS_SECRET_ACCESS_KEY"); awsSecretAccessKey != "" { - config.AWSSecretAccessKey = awsSecretAccessKey - } - - if awsRegion := os.Getenv("AWS_REGION"); awsRegion != "" { - config.AWSRegion = awsRegion - } - - if certManagerVersion := os.Getenv("CERT_MANAGER_VERSION"); certManagerVersion != "" { - config.CertManagerVersion = certManagerVersion - } - - if certManagerURL := os.Getenv("CERT_MANAGER_CHART_URL"); certManagerURL != "" { - config.CertManagerChartURL = certManagerURL - } - - if rancherVersion := os.Getenv("RANCHER_VERSION"); rancherVersion != "" { - config.RancherVersion = rancherVersion - } - - if rancherURL := os.Getenv("RANCHER_CHART_URL"); rancherURL != "" { - config.RancherChartURL = rancherURL - } - - if err := substituteVersions(config); err != nil { - return nil, err - } - - return config, validateAWSCredentials(config) -} - -func substituteVersions(config *E2EConfig) error { - certManagerURL, err := envsubst.Eval(config.CertManagerChartURL, func(s string) string { - return config.CertManagerVersion - }) - if err != nil { - return fmt.Errorf("failed to substitute cert manager chart url: %w", err) - } - config.CertManagerChartURL = certManagerURL - - rancherURL, err := envsubst.Eval(config.RancherChartURL, func(s string) string { - return config.RancherVersion - }) - if err != nil { - return fmt.Errorf("failed to substitute rancher chart url: %w", err) - } - config.RancherChartURL = rancherURL - - return nil -} - -func validateAWSCredentials(config *E2EConfig) error { - if config.AWSAccessKey == "" { - return errors.New("no AWS_ACCESS_KEY_ID provided, an aws access key is required to run e2e tests") - } - - if config.AWSSecretAccessKey == "" { - return errors.New("no AWS_SECRET_ACCESS_KEY provided, an aws secret access key is required to run e2e tests") - } - - if config.AWSRegion == "" { - return errors.New("no AWS_REGION provided, an aws region is required to run e2e tests") - } - - return nil -} diff --git a/test/e2e/config/config.yaml b/test/e2e/config/config.yaml deleted file mode 100644 index d0360402..00000000 --- a/test/e2e/config/config.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# E2E Tests config - -magicDNS: sslip.io -bridgeIP: 172.17.0.1 -operatorReplicas: 1 -artifactsDir: ../../_artifacts - -certManagerVersion: v1.11.1 -certManagerChartURL: https://charts.jetstack.io/charts/cert-manager-${CERT_MANAGER_VERSION}.tgz - -rancherVersion: 2.7.2 -rancherChartURL: https://releases.rancher.com/server-charts/latest/rancher-${RANCHER_VERSION}.tgz - diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go deleted file mode 100644 index 3a61416a..00000000 --- a/test/e2e/suite_test.go +++ /dev/null @@ -1,348 +0,0 @@ -package e2e - -import ( - "bytes" - "context" - "embed" - "fmt" - "os" - "path" - "path/filepath" - "strings" - "testing" - "time" - - "github.com/aws/aws-sdk-go/aws" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - kubectl "github.com/rancher-sandbox/ele-testhelpers/kubectl" - eksv1 "github.com/rancher/eks-operator/pkg/apis/eks.cattle.io/v1" - e2eConfig "github.com/rancher/eks-operator/test/e2e/config" - managementv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apiserver/pkg/storage/names" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" - runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" - runtimeconfig "sigs.k8s.io/controller-runtime/pkg/client/config" - "sigs.k8s.io/yaml" -) - -func init() { - utilruntime.Must(clientgoscheme.AddToScheme(clientgoscheme.Scheme)) - utilruntime.Must(managementv3.AddToScheme(clientgoscheme.Scheme)) - utilruntime.Must(apiextensionsv1.AddToScheme(clientgoscheme.Scheme)) - utilruntime.Must(eksv1.AddToScheme(clientgoscheme.Scheme)) -} - -const ( - operatorName = "eks-config-operator" - crdChartName = "eks-config-operator-crd" - certManagerNamespace = "cert-manager" - certManagerName = "cert-manager" - certManagerCAInjectorName = "cert-manager-cainjector" - awsCredentialsSecretName = "aws-credentials" - cattleSystemNamespace = "cattle-system" - rancherName = "rancher" - eksClusterConfigNamespace = "cattle-global-data" -) - -// Test configuration -var ( - e2eCfg *e2eConfig.E2EConfig - cl runtimeclient.Client - ctx = context.Background() - crdNames = []string{ - "eksclusterconfigs.eks.cattle.io", - } - - pollInterval = 10 * time.Second - waitLong = 25 * time.Minute -) - -// Cluster Templates -var ( - //go:embed templates/* - templates embed.FS - - clusterTemplates = map[string]*eksv1.EKSClusterConfig{} - basicClusterTemplateName = "basic-cluster" -) - -func TestE2e(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "eks-operator e2e test Suite") -} - -var _ = BeforeSuite(func() { - configPath := os.Getenv("CONFIG_PATH") - if configPath == "" { - Fail("config path can't be empty") - } - - var err error - e2eCfg, err = e2eConfig.ReadE2EConfig(configPath) - Expect(err).ToNot(HaveOccurred()) - - cfg, err := runtimeconfig.GetConfig() - Expect(err).ToNot(HaveOccurred()) - - cl, err = runtimeclient.New(cfg, runtimeclient.Options{}) - Expect(err).ToNot(HaveOccurred()) - - By("Deploying rancher and cert-manager", func() { - By("installing cert-manager", func() { - if isDeploymentReady(certManagerNamespace, certManagerName) { - By("already installed") - } else { - Expect(kubectl.RunHelmBinaryWithCustomErr( - "-n", - certManagerNamespace, - "install", - "--set", - "installCRDs=true", - "--create-namespace", - certManagerNamespace, - e2eCfg.CertManagerChartURL, - )).To(Succeed()) - Eventually(func() bool { - return isDeploymentReady(certManagerNamespace, certManagerName) - }, 5*time.Minute, 2*time.Second).Should(BeTrue()) - Eventually(func() bool { - return isDeploymentReady(certManagerNamespace, certManagerCAInjectorName) - }, 5*time.Minute, 2*time.Second).Should(BeTrue()) - } - }) - - By("installing rancher", func() { - if isDeploymentReady(cattleSystemNamespace, rancherName) { - By("already installed") - } else { - Expect(kubectl.RunHelmBinaryWithCustomErr( - "-n", - cattleSystemNamespace, - "install", - "--set", - "bootstrapPassword=admin", - "--set", - "global.cattle.psp.enabled=false", - "--set", - "replicas=1", - "--set", fmt.Sprintf("hostname=%s.%s", e2eCfg.ExternalIP, e2eCfg.MagicDNS), - "--create-namespace", - rancherName, - fmt.Sprintf(e2eCfg.RancherChartURL), - )).To(Succeed()) - Eventually(func() bool { - return isDeploymentReady(cattleSystemNamespace, rancherName) - }, 5*time.Minute, 2*time.Second).Should(BeTrue()) - } - }) - }) - - By("Deploying eks operator CRD chart", func() { - if isDeploymentReady(cattleSystemNamespace, operatorName) { - By("already installed") - } else { - Expect(kubectl.RunHelmBinaryWithCustomErr( - "-n", - crdChartName, - "install", - "--create-namespace", - "--set", "debug=true", - operatorName, - e2eCfg.CRDChart, - )).To(Succeed()) - - By("Waiting for CRDs to be created") - Eventually(func() bool { - for _, crdName := range crdNames { - crd := &apiextensionsv1.CustomResourceDefinition{} - if err := cl.Get(ctx, - runtimeclient.ObjectKey{ - Name: crdName, - }, - crd, - ); err != nil { - return false - } - } - return true - }, 5*time.Minute, 2*time.Second).Should(BeTrue()) - } - }) - - By("Deploying eks operator chart", func() { - if isDeploymentReady(cattleSystemNamespace, operatorName) { - By("already installed") - } else { - Expect(kubectl.RunHelmBinaryWithCustomErr( - "-n", - cattleSystemNamespace, - "install", - "--create-namespace", - "--set", "debug=true", - operatorName, - e2eCfg.OperatorChart, - )).To(Succeed()) - - By("Waiting for eks operator deployment to be available") - Eventually(func() bool { - return isDeploymentReady(cattleSystemNamespace, operatorName) - }, 5*time.Minute, 2*time.Second).Should(BeTrue()) - } - // As we are not bootstrapping rancher in the tests (going to the first login page, setting new password and rancher-url) - // We need to manually set this value, which is the same value you would get from doing the bootstrap - setting := &managementv3.Setting{} - Expect(cl.Get(ctx, - runtimeclient.ObjectKey{ - Name: "server-url", - }, - setting, - )).To(Succeed()) - - setting.Source = "env" - setting.Value = fmt.Sprintf("https://%s.%s", e2eCfg.ExternalIP, e2eCfg.MagicDNS) - - Expect(cl.Update(ctx, setting)).To(Succeed()) - - }) - - By("Creating aws credentials secret", func() { - secret := &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: awsCredentialsSecretName, - Namespace: "default", - }, - Data: map[string][]byte{ - "amazonec2credentialConfig-accessKey": []byte(e2eCfg.AWSAccessKey), - "amazonec2credentialConfig-secretKey": []byte(e2eCfg.AWSSecretAccessKey), - }, - } - - err := cl.Create(ctx, secret) - if err != nil { - fmt.Println(err) - Expect(apierrors.IsAlreadyExists(err)).To(BeTrue()) - } - }) - - By("Reading cluster templates", func() { - assets, err := templates.ReadDir("templates") - Expect(err).ToNot(HaveOccurred()) - - for _, asset := range assets { - b, err := templates.ReadFile(path.Join("templates", asset.Name())) - Expect(err).ToNot(HaveOccurred()) - - eksCluster := &eksv1.EKSClusterConfig{} - Expect(yaml.Unmarshal(b, eksCluster)).To(Succeed()) - - name := strings.TrimSuffix(asset.Name(), ".yaml") - generatedName := names.SimpleNameGenerator.GenerateName(name + "-") - eksCluster.Name = generatedName - eksCluster.Spec.DisplayName = generatedName - eksCluster.Spec.Region = e2eCfg.AWSRegion - Expect(eksCluster.Spec.NodeGroups).To(HaveLen(1)) - eksCluster.Spec.NodeGroups[0].NodeRole = aws.String("") - - clusterTemplates[name] = eksCluster - } - }) -}) - -var _ = AfterSuite(func() { - By("Creating artifact directory") - - if _, err := os.Stat(e2eCfg.ArtifactsDir); os.IsNotExist(err) { - Expect(os.Mkdir(e2eCfg.ArtifactsDir, os.ModePerm)).To(Succeed()) - } - - By("Getting eks operator logs") - - podList := &corev1.PodList{} - Expect(cl.List(ctx, podList, runtimeclient.MatchingLabels{ - "ke.cattle.io/operator": "eks", - }, runtimeclient.InNamespace(cattleSystemNamespace), - )).To(Succeed()) - - for _, pod := range podList.Items { - for _, container := range pod.Spec.Containers { - output, err := kubectl.Run("logs", pod.Name, "-c", container.Name, "-n", pod.Namespace) - Expect(err).ToNot(HaveOccurred()) - Expect(os.WriteFile(filepath.Join(e2eCfg.ArtifactsDir, pod.Name+"-"+container.Name+".log"), redactSensitiveData([]byte(output)), 0644)).To(Succeed()) - } - } - - By("Getting eks Clusters") - - eksClusterList := &eksv1.EKSClusterConfigList{} - Expect(cl.List(ctx, eksClusterList, &runtimeclient.ListOptions{})).To(Succeed()) - - for _, eksCluster := range eksClusterList.Items { - output, err := yaml.Marshal(eksCluster) - Expect(err).ToNot(HaveOccurred()) - Expect(os.WriteFile(filepath.Join(e2eCfg.ArtifactsDir, "eks-cluster-config-"+eksCluster.Name+".yaml"), redactSensitiveData([]byte(output)), 0644)).To(Succeed()) - } - - By("Getting Rancher Clusters") - - rancherClusterList := &managementv3.ClusterList{} - Expect(cl.List(ctx, rancherClusterList, &runtimeclient.ListOptions{})).To(Succeed()) - - for _, rancherCluster := range rancherClusterList.Items { - output, err := yaml.Marshal(rancherCluster) - Expect(err).ToNot(HaveOccurred()) - Expect(os.WriteFile(filepath.Join(e2eCfg.ArtifactsDir, "rancher-cluster-"+rancherCluster.Name+".yaml"), redactSensitiveData([]byte(output)), 0644)).To(Succeed()) - } - - By("Cleaning up Rancher Clusters") - - for _, rancherCluster := range rancherClusterList.Items { - if rancherCluster.Name == "local" { - continue - } - - Expect(cl.Delete(ctx, &rancherCluster)).To(Succeed()) - Eventually(func() bool { - if err := cl.Get(ctx, runtimeclient.ObjectKey{ - Name: rancherCluster.Name, - Namespace: eksClusterConfigNamespace, - }, &eksv1.EKSClusterConfig{}); err != nil { - return apierrors.IsNotFound(err) - } - - return false - }, waitLong, pollInterval).Should(BeTrue()) - } -}) - -func isDeploymentReady(namespace, name string) bool { - deployment := &appsv1.Deployment{} - if err := cl.Get(ctx, - runtimeclient.ObjectKey{ - Namespace: namespace, - Name: name, - }, - deployment, - ); err != nil { - return false - } - - if deployment.Status.AvailableReplicas == *deployment.Spec.Replicas { - return true - } - - return false -} - -func redactSensitiveData(input []byte) []byte { - output := bytes.Replace(input, []byte(e2eCfg.AWSAccessKey), []byte("***"), -1) - output = bytes.Replace(output, []byte(e2eCfg.AWSSecretAccessKey), []byte("***"), -1) - output = bytes.Replace(output, []byte(e2eCfg.AWSRegion), []byte("***"), -1) - return output -} diff --git a/test/e2e/templates/basic-cluster.yaml b/test/e2e/templates/basic-cluster.yaml deleted file mode 100644 index 89a2eb73..00000000 --- a/test/e2e/templates/basic-cluster.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: eks.cattle.io/v1 -kind: EKSClusterConfig -metadata: - namespace: default -spec: - amazonCredentialSecret: default:aws-credentials - imported: false - kmsKey: "" - kubernetesVersion: "1.25" - loggingTypes: [] - nodeGroups: - - desiredSize: 2 - diskSize: 20 - ec2SshKey: "" - gpu: false - imageId: "" - instanceType: t3.medium - labels: {} - launchTemplate: null - maxSize: 2 - minSize: 2 - nodegroupName: nodenametest - requestSpotInstances: false - resourceTags: {} - spotInstanceTypes: [] - subnets: [] - tags: {} - userData: "" - version: "1.25" - privateAccess: false - publicAccess: true - publicAccessSources: [] - secretsEncryption: false - securityGroups: [] - serviceRole: "" - subnets: [] - tags: {}