From 03de6e2de666a5ce5399e7e3c8307e7a132a7306 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Fri, 26 Apr 2024 15:27:58 +0100 Subject: [PATCH] feat: graduate the garbage collection feature This moves the "garbage collection" feature out of experimental and to be enabled by default. Signed-off-by: Richard Case --- Makefile | 3 - config/manager/manager.yaml | 2 +- docs/book/src/topics/external-resource-gc.md | 19 ++- docs/book/src/topics/reference/reference.md | 2 +- feature/feature.go | 4 +- scripts/ci-e2e-eks-gc.sh | 112 ------------------ scripts/ci-e2e-gc.sh | 112 ------------------ test/e2e/data/e2e_conf.yaml | 1 - test/e2e/data/e2e_eks_conf.yaml | 1 - .../gc_managed/gc_managed_suite_test.go | 77 ------------ .../gc_unmanaged/gc_unmanaged_suite_test.go | 64 ---------- .../eks_gc_test.go} | 42 ++----- .../unmanaged_gc_test.go} | 34 +----- 13 files changed, 30 insertions(+), 443 deletions(-) delete mode 100755 scripts/ci-e2e-eks-gc.sh delete mode 100755 scripts/ci-e2e-gc.sh delete mode 100644 test/e2e/suites/gc_managed/gc_managed_suite_test.go delete mode 100644 test/e2e/suites/gc_unmanaged/gc_unmanaged_suite_test.go rename test/e2e/suites/{gc_managed/gc_managed_test.go => managed/eks_gc_test.go} (87%) rename test/e2e/suites/{gc_unmanaged/gc_unmanaged_test.go => unmanaged/unmanaged_gc_test.go} (85%) diff --git a/Makefile b/Makefile index 46c2dba654..1741cdfe3b 100644 --- a/Makefile +++ b/Makefile @@ -468,9 +468,6 @@ compile-e2e: ## Test e2e compilation go test -c -o /dev/null -tags=e2e ./test/e2e/suites/unmanaged go test -c -o /dev/null -tags=e2e ./test/e2e/suites/conformance go test -c -o /dev/null -tags=e2e ./test/e2e/suites/managed - go test -c -o /dev/null -tags=e2e ./test/e2e/suites/gc_managed - go test -c -o /dev/null -tags=e2e ./test/e2e/suites/gc_unmanaged - .PHONY: docker-pull-e2e-preloads docker-pull-e2e-preloads: ## Preloads the docker images used for e2e testing and can speed it up diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 95102f41c6..a928c5ff4b 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -19,7 +19,7 @@ spec: containers: - args: - "--leader-elect" - - "--feature-gates=EKS=${CAPA_EKS:=true},EKSEnableIAM=${CAPA_EKS_IAM:=false},EKSAllowAddRoles=${CAPA_EKS_ADD_ROLES:=false},EKSFargate=${EXP_EKS_FARGATE:=false},MachinePool=${EXP_MACHINE_POOL:=false},EventBridgeInstanceState=${EVENT_BRIDGE_INSTANCE_STATE:=false},AutoControllerIdentityCreator=${AUTO_CONTROLLER_IDENTITY_CREATOR:=true},BootstrapFormatIgnition=${EXP_BOOTSTRAP_FORMAT_IGNITION:=false},ExternalResourceGC=${EXP_EXTERNAL_RESOURCE_GC:=false},AlternativeGCStrategy=${EXP_ALTERNATIVE_GC_STRATEGY:=false},TagUnmanagedNetworkResources=${TAG_UNMANAGED_NETWORK_RESOURCES:=true},ROSA=${EXP_ROSA:=false}" + - "--feature-gates=EKS=${CAPA_EKS:=true},EKSEnableIAM=${CAPA_EKS_IAM:=false},EKSAllowAddRoles=${CAPA_EKS_ADD_ROLES:=false},EKSFargate=${EXP_EKS_FARGATE:=false},MachinePool=${EXP_MACHINE_POOL:=false},EventBridgeInstanceState=${EVENT_BRIDGE_INSTANCE_STATE:=false},AutoControllerIdentityCreator=${AUTO_CONTROLLER_IDENTITY_CREATOR:=true},BootstrapFormatIgnition=${EXP_BOOTSTRAP_FORMAT_IGNITION:=false},ExternalResourceGC=${CAPA_EXTERNAL_RESOURCE_GC:=true},AlternativeGCStrategy=${EXP_ALTERNATIVE_GC_STRATEGY:=false},TagUnmanagedNetworkResources=${TAG_UNMANAGED_NETWORK_RESOURCES:=true},ROSA=${EXP_ROSA:=false}" - "--v=${CAPA_LOGLEVEL:=0}" - "--diagnostics-address=${CAPA_DIAGNOSTICS_ADDRESS:=:8443}" - "--insecure-diagnostics=${CAPA_INSECURE_DIAGNOSTICS:=false}" diff --git a/docs/book/src/topics/external-resource-gc.md b/docs/book/src/topics/external-resource-gc.md index 5f7ce6fdda..76b2d71311 100644 --- a/docs/book/src/topics/external-resource-gc.md +++ b/docs/book/src/topics/external-resource-gc.md @@ -1,6 +1,6 @@ # External Resource Garbage Collection -- **Feature status:** Experimental +- **Feature status:** Stable - **Feature gate (required):** ExternalResourceGC=true ## Overview @@ -21,16 +21,25 @@ We will look to support deleting EBS volumes in the future potentially. > Note: this feature will likely be superseded by an upstream CAPI feature in the future when [this issue](https://github.com/kubernetes-sigs/cluster-api/issues/3075) is resolved. -## Enabling +## Disabling -To enable garbage collection, you must set the `ExternalResourceGC` feature gate to `true` on the controller manager. The easiest way to do this is via an environment variable: +The garbage collection feature is enabled by default. It can be disabled by setting the `ExternalResourceGC` feature gate to `false` on the controller manager. The easiest way to do this is via an environment variable: ```bash -export EXP_EXTERNAL_RESOURCE_GC=true +export CAPA_EXTERNAL_RESOURCE_GC=false clusterctl init --infrastructure aws ``` -> Note: if you enable this feature **ALL** clusters will be marked as requiring garbage collection. +## Enabling Alternative Strategy + +The default strategy is to use the AWS resource tagging API. This may not be suitable in all cases and so an alternative strategy can be enabled. The alternative strategy is usually needed in a airgapped environment where the resource tagging API is not available. + +To enable the alternative strategy you need to set the `AlternativeGCStrategy` feature gate to `true` on the controller manager. The easiest way to do this is via an environment variable: + +```bash +export EXP_ALTERNATIVE_GC_STRATEGY=true +clusterctl init --infrastructure aws +``` ## Operations diff --git a/docs/book/src/topics/reference/reference.md b/docs/book/src/topics/reference/reference.md index 4e91a0f21b..2618160fbe 100644 --- a/docs/book/src/topics/reference/reference.md +++ b/docs/book/src/topics/reference/reference.md @@ -12,7 +12,7 @@ | EventBridgeInstanceState | EVENT_BRIDGE_INSTANCE_STATE | flase | | AutoControllerIdentityCreator | AUTO_CONTROLLER_IDENTITY_CREATOR | true | | BootstrapFormatIgnition | EXP_BOOTSTRAP_FORMAT_IGNITION | false | -| ExternalResourceGC | EXP_EXTERNAL_RESOURCE_GC | false | +| ExternalResourceGC | CAPA_EXTERNAL_RESOURCE_GC | true | | AlternativeGCStrategy | EXP_ALTERNATIVE_GC_STRATEGY | false | | TagUnmanagedNetworkResources | TAG_UNMANAGED_NETWORK_RESOURCES | true | | ROSA | EXP_ROSA | false | \ No newline at end of file diff --git a/feature/feature.go b/feature/feature.go index 061e4edd57..2d40f252d1 100644 --- a/feature/feature.go +++ b/feature/feature.go @@ -69,7 +69,7 @@ const ( // ExternalResourceGC is used to enable the garbage collection of external resources like NLB/ALB on deletion // owner: @richardcase - // alpha: v1.5 + // beta: v2.5.0 ExternalResourceGC featuregate.Feature = "ExternalResourceGC" // AlternativeGCStrategy is used to enable garbage collection of external resources to be performed without resource group tagging API. It is usually needed in airgap env when tagging API is not available. @@ -104,7 +104,7 @@ var defaultCAPAFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ MachinePool: {Default: true, PreRelease: featuregate.Beta}, AutoControllerIdentityCreator: {Default: true, PreRelease: featuregate.Alpha}, BootstrapFormatIgnition: {Default: false, PreRelease: featuregate.Alpha}, - ExternalResourceGC: {Default: false, PreRelease: featuregate.Alpha}, + ExternalResourceGC: {Default: true, PreRelease: featuregate.Beta}, AlternativeGCStrategy: {Default: false, PreRelease: featuregate.Alpha}, TagUnmanagedNetworkResources: {Default: true, PreRelease: featuregate.Alpha}, ROSA: {Default: false, PreRelease: featuregate.Alpha}, diff --git a/scripts/ci-e2e-eks-gc.sh b/scripts/ci-e2e-eks-gc.sh deleted file mode 100755 index e9e9329631..0000000000 --- a/scripts/ci-e2e-eks-gc.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash - -# Copyright 2022 The Kubernetes Authors. -# -# 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. - -################################################################################ -# usage: e2e.sh -# This program runs the e2e tests. -# -# ENVIRONMENT VARIABLES -# JANITOR_ENABLED -# Set to 1 to run the aws-janitor command after running the e2e tests. -################################################################################ - -set -o nounset -set -o pipefail - -REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -cd "${REPO_ROOT}" || exit 1 - -# shellcheck source=../hack/ensure-go.sh -source "${REPO_ROOT}/hack/ensure-go.sh" -# shellcheck source=../hack/ensure-kind.sh -source "${REPO_ROOT}/hack/ensure-kind.sh" -# shellcheck source=../hack/ensure-kubectl.sh -source "${REPO_ROOT}/hack/ensure-kubectl.sh" - -ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}" -mkdir -p "$ARTIFACTS/logs/" - -# our exit handler (trap) -cleanup() { - # stop boskos heartbeat - [[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}" -} -trap cleanup EXIT - -#Install requests module explicitly for HTTP calls -apt update -apt install -y python3-pip python3-requests - -# If BOSKOS_HOST is set then acquire an AWS account from Boskos. -if [ -n "${BOSKOS_HOST:-}" ]; then - # Check out the account from Boskos and store the produced environment - # variables in a temporary file. - account_env_var_file="$(mktemp)" - python3 hack/boskos.py --get 1>"${account_env_var_file}" - checkout_account_status="${?}" - - # If the checkout process was a success then load the account's - # environment variables into this process. - # shellcheck disable=SC1090 - [ "${checkout_account_status}" = "0" ] && . "${account_env_var_file}" - - # Always remove the account environment variable file. It contains - # sensitive information. - rm -f "${account_env_var_file}" - - if [ ! "${checkout_account_status}" = "0" ]; then - echo "error getting account from boskos" 1>&2 - exit "${checkout_account_status}" - fi - - # run the heart beat process to tell boskos that we are still - # using the checked out account periodically - python3 -u hack/boskos.py --heartbeat >>$ARTIFACTS/logs/boskos.log 2>&1 & - HEART_BEAT_PID=$(echo $!) -fi - -# Prevent a disallowed AWS key from being used. -if grep -iqF "$(echo "${AWS_ACCESS_KEY_ID-}" | - { md5sum 2>/dev/null || md5; } | - awk '{print $1}')" hack/e2e-aws-disallowed.txt; then - echo "The provided AWS key is not allowed" 1>&2 - exit 1 -fi - -EXP_EXTERNAL_RESOURCE_GC="true" GC_WORKLOAD="../../data/gcworkload.yaml" make test-e2e-eks-gc ARTIFACTS=$ARTIFACTS - -test_status="${?}" - -# If Boskos is being used then release the AWS account back to Boskos. -[ -z "${BOSKOS_HOST:-}" ] || python3 -u hack/boskos.py --release - -# The janitor is typically not run as part of the e2e process, but rather -# in a parallel process via a service on the same cluster that runs Prow and -# Boskos. -# -# However, setting JANITOR_ENABLED=1 tells this program to run the janitor -# after the e2e test is executed. -if [ "${JANITOR_ENABLED:-0}" = "1" ]; then - if ! command -v aws-janitor >/dev/null 2>&1; then - echo "skipping janitor; aws-janitor not found" 1>&2 - else - aws-janitor -all -v 2 - fi -else - echo "skipping janitor; JANITOR_ENABLED=${JANITOR_ENABLED:-0}" 1>&2 -fi - -exit "${test_status}" diff --git a/scripts/ci-e2e-gc.sh b/scripts/ci-e2e-gc.sh deleted file mode 100755 index baccf8525d..0000000000 --- a/scripts/ci-e2e-gc.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash - -# Copyright 2022 The Kubernetes Authors. -# -# 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. - -################################################################################ -# usage: e2e.sh -# This program runs the e2e tests. -# -# ENVIRONMENT VARIABLES -# JANITOR_ENABLED -# Set to 1 to run the aws-janitor command after running the e2e tests. -################################################################################ - -set -o nounset -set -o pipefail - -REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -cd "${REPO_ROOT}" || exit 1 - -# shellcheck source=../hack/ensure-go.sh -source "${REPO_ROOT}/hack/ensure-go.sh" -# shellcheck source=../hack/ensure-kind.sh -source "${REPO_ROOT}/hack/ensure-kind.sh" -# shellcheck source=../hack/ensure-kubectl.sh -source "${REPO_ROOT}/hack/ensure-kubectl.sh" - -ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}" -mkdir -p "$ARTIFACTS/logs/" - -# our exit handler (trap) -cleanup() { - # stop boskos heartbeat - [[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}" -} -trap cleanup EXIT - -#Install requests module explicitly for HTTP calls -apt update -apt install -y python3-pip python3-requests - -# If BOSKOS_HOST is set then acquire an AWS account from Boskos. -if [ -n "${BOSKOS_HOST:-}" ]; then - # Check out the account from Boskos and store the produced environment - # variables in a temporary file. - account_env_var_file="$(mktemp)" - python3 hack/boskos.py --get 1>"${account_env_var_file}" - checkout_account_status="${?}" - - # If the checkout process was a success then load the account's - # environment variables into this process. - # shellcheck disable=SC1090 - [ "${checkout_account_status}" = "0" ] && . "${account_env_var_file}" - - # Always remove the account environment variable file. It contains - # sensitive information. - rm -f "${account_env_var_file}" - - if [ ! "${checkout_account_status}" = "0" ]; then - echo "error getting account from boskos" 1>&2 - exit "${checkout_account_status}" - fi - - # run the heart beat process to tell boskos that we are still - # using the checked out account periodically - python3 -u hack/boskos.py --heartbeat >>$ARTIFACTS/logs/boskos.log 2>&1 & - HEART_BEAT_PID=$(echo $!) -fi - -# Prevent a disallowed AWS key from being used. -if grep -iqF "$(echo "${AWS_ACCESS_KEY_ID-}" | - { md5sum 2>/dev/null || md5; } | - awk '{print $1}')" hack/e2e-aws-disallowed.txt; then - echo "The provided AWS key is not allowed" 1>&2 - exit 1 -fi - -EXP_EXTERNAL_RESOURCE_GC="true" GC_WORKLOAD="../../data/gcworkload.yaml" make test-e2e-gc ARTIFACTS=$ARTIFACTS - -test_status="${?}" - -# If Boskos is being used then release the AWS account back to Boskos. -[ -z "${BOSKOS_HOST:-}" ] || python3 -u hack/boskos.py --release - -# The janitor is typically not run as part of the e2e process, but rather -# in a parallel process via a service on the same cluster that runs Prow and -# Boskos. -# -# However, setting JANITOR_ENABLED=1 tells this program to run the janitor -# after the e2e test is executed. -if [ "${JANITOR_ENABLED:-0}" = "1" ]; then - if ! command -v aws-janitor >/dev/null 2>&1; then - echo "skipping janitor; aws-janitor not found" 1>&2 - else - aws-janitor -all -v 2 - fi -else - echo "skipping janitor; JANITOR_ENABLED=${JANITOR_ENABLED:-0}" 1>&2 -fi - -exit "${test_status}" diff --git a/test/e2e/data/e2e_conf.yaml b/test/e2e/data/e2e_conf.yaml index 01692cf959..e96ee34b6e 100644 --- a/test/e2e/data/e2e_conf.yaml +++ b/test/e2e/data/e2e_conf.yaml @@ -209,7 +209,6 @@ variables: INIT_WITH_KUBERNETES_VERSION: "v1.25.0" EXP_BOOTSTRAP_FORMAT_IGNITION: "true" EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION: "true" - EXP_EXTERNAL_RESOURCE_GC: "true" GC_WORKLOAD: "../../data/gcworkload.yaml" intervals: diff --git a/test/e2e/data/e2e_eks_conf.yaml b/test/e2e/data/e2e_eks_conf.yaml index 4a342a72ef..711b2659c9 100644 --- a/test/e2e/data/e2e_eks_conf.yaml +++ b/test/e2e/data/e2e_eks_conf.yaml @@ -133,7 +133,6 @@ variables: CONFORMANCE_CI_ARTIFACTS_KUBERNETES_VERSION: "1.29.1" IP_FAMILY: "IPv4" CAPA_LOGLEVEL: "4" - EXP_EXTERNAL_RESOURCE_GC: "true" GC_WORKLOAD: "../../data/gcworkload.yaml" intervals: diff --git a/test/e2e/suites/gc_managed/gc_managed_suite_test.go b/test/e2e/suites/gc_managed/gc_managed_suite_test.go deleted file mode 100644 index e5bb7c3de4..0000000000 --- a/test/e2e/suites/gc_managed/gc_managed_suite_test.go +++ /dev/null @@ -1,77 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright 2022 The Kubernetes Authors. - -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 gc_managed //nolint:stylecheck - -import ( - "testing" - - "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/klog/v2" - ctrl "sigs.k8s.io/controller-runtime" - - ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" - expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2" - "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" -) - -var ( - e2eCtx *shared.E2EContext -) - -func init() { - e2eCtx = shared.NewE2EContext(shared.WithManaged(), shared.WithSchemeInit(initScheme)) - - shared.CreateDefaultFlags(e2eCtx) -} - -func TestE2E(t *testing.T) { - ctrl.SetLogger(klog.Background()) - RegisterFailHandler(ginkgo.Fail) - ginkgo.RunSpecs(t, "capa-eks-gc-e2e") -} - -var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { - return shared.Node1BeforeSuite(e2eCtx) -}, func(data []byte) { - shared.AllNodesBeforeSuite(e2eCtx, data) -}) - -var _ = ginkgo.SynchronizedAfterSuite( - func() { - shared.AllNodesAfterSuite(e2eCtx) - }, - func() { - shared.Node1AfterSuite(e2eCtx) - }, -) - -func initScheme() *runtime.Scheme { - sc := shared.DefaultScheme() - _ = expinfrav1.AddToScheme(sc) - _ = clusterv1.AddToScheme(sc) - _ = ekscontrolplanev1.AddToScheme(sc) - _ = expclusterv1.AddToScheme(sc) - - return sc -} diff --git a/test/e2e/suites/gc_unmanaged/gc_unmanaged_suite_test.go b/test/e2e/suites/gc_unmanaged/gc_unmanaged_suite_test.go deleted file mode 100644 index 1beeb1ac6b..0000000000 --- a/test/e2e/suites/gc_unmanaged/gc_unmanaged_suite_test.go +++ /dev/null @@ -1,64 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright 2022 The Kubernetes Authors. - -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 gc_unmanaged //nolint:stylecheck - -import ( - "testing" - "time" - - "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "k8s.io/klog/v2" - ctrl "sigs.k8s.io/controller-runtime" - - "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" -) - -var ( - e2eCtx *shared.E2EContext -) - -func init() { - e2eCtx = shared.NewE2EContext() - shared.CreateDefaultFlags(e2eCtx) - SetDefaultEventuallyTimeout(20 * time.Minute) - SetDefaultEventuallyPollingInterval(10 * time.Second) -} - -func TestE2E(t *testing.T) { - ctrl.SetLogger(klog.Background()) - RegisterFailHandler(ginkgo.Fail) - ginkgo.RunSpecs(t, "capa-e2e") -} - -var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { - return shared.Node1BeforeSuite(e2eCtx) -}, func(data []byte) { - shared.AllNodesBeforeSuite(e2eCtx, data) -}) - -var _ = ginkgo.SynchronizedAfterSuite( - func() { - shared.AllNodesAfterSuite(e2eCtx) - }, - func() { - shared.Node1AfterSuite(e2eCtx) - }, -) diff --git a/test/e2e/suites/gc_managed/gc_managed_test.go b/test/e2e/suites/managed/eks_gc_test.go similarity index 87% rename from test/e2e/suites/gc_managed/gc_managed_test.go rename to test/e2e/suites/managed/eks_gc_test.go index 4bd79b930f..ebf10bd932 100644 --- a/test/e2e/suites/gc_managed/gc_managed_test.go +++ b/test/e2e/suites/managed/eks_gc_test.go @@ -17,25 +17,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -package gc_managed //nolint:stylecheck +package managed //nolint:stylecheck import ( "context" "fmt" "os" - "path/filepath" "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" - ms "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/suites/managed" "sigs.k8s.io/cluster-api/test/framework" - "sigs.k8s.io/cluster-api/test/framework/clusterctl" "sigs.k8s.io/cluster-api/util" ) @@ -59,18 +55,18 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests", clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) ginkgo.By("default iam role should exist") - ms.VerifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSession) + VerifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSession) ginkgo.By("should create an EKS control plane") - ms.ManagedClusterSpec(ctx, func() ms.ManagedClusterSpecInput { - return ms.ManagedClusterSpecInput{ + ManagedClusterSpec(ctx, func() ManagedClusterSpecInput { + return ManagedClusterSpecInput{ E2EConfig: e2eCtx.E2EConfig, ConfigClusterFn: defaultConfigCluster, BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, AWSSession: e2eCtx.BootstrapUserAWSSession, Namespace: namespace, ClusterName: clusterName, - Flavour: ms.EKSManagedPoolFlavor, + Flavour: EKSManagedPoolFlavor, ControlPlaneMachineCount: 1, // NOTE: this cannot be zero as clusterctl returns an error WorkerMachineCount: 1, } @@ -85,7 +81,7 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests", Expect(cluster).NotTo(BeNil(), "couldn't find cluster") ginkgo.By("getting AWSManagedControlPlane") - cp := ms.GetControlPlaneByName(ctx, ms.GetControlPlaneByNameInput{ + cp := GetControlPlaneByName(ctx, GetControlPlaneByNameInput{ Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), Namespace: cluster.Spec.InfrastructureRef.Namespace, Name: cluster.Spec.ControlPlaneRef.Name, @@ -180,18 +176,18 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests", clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) ginkgo.By("default iam role should exist") - ms.VerifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSession) + VerifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSession) ginkgo.By("should create an EKS control plane") - ms.ManagedClusterSpec(ctx, func() ms.ManagedClusterSpecInput { - return ms.ManagedClusterSpecInput{ + ManagedClusterSpec(ctx, func() ManagedClusterSpecInput { + return ManagedClusterSpecInput{ E2EConfig: e2eCtx.E2EConfig, ConfigClusterFn: defaultConfigCluster, BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, AWSSession: e2eCtx.BootstrapUserAWSSession, Namespace: namespace, ClusterName: clusterName, - Flavour: ms.EKSManagedPoolFlavor, + Flavour: EKSManagedPoolFlavor, ControlPlaneMachineCount: 1, // NOTE: this cannot be zero as clusterctl returns an error WorkerMachineCount: 1, } @@ -206,7 +202,7 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests", Expect(cluster).NotTo(BeNil(), "couldn't find cluster") ginkgo.By("getting AWSManagedControlPlane") - cp := ms.GetControlPlaneByName(ctx, ms.GetControlPlaneByNameInput{ + cp := GetControlPlaneByName(ctx, GetControlPlaneByNameInput{ Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), Namespace: cluster.Spec.InfrastructureRef.Namespace, Name: cluster.Spec.ControlPlaneRef.Name, @@ -289,19 +285,3 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests", }, shared.DisableAlternativeGCStrategy, shared.ValidateAlternativeGCStrategyDisabled) }) }) - -// TODO (richardcase): remove this when we merge these tests with the main eks e2e tests. -func defaultConfigCluster(clusterName, namespace string) clusterctl.ConfigClusterInput { - return clusterctl.ConfigClusterInput{ - LogFolder: filepath.Join(e2eCtx.Settings.ArtifactFolder, "clusters", e2eCtx.Environment.BootstrapClusterProxy.GetName()), - ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath, - KubeconfigPath: e2eCtx.Environment.BootstrapClusterProxy.GetKubeconfigPath(), - InfrastructureProvider: "aws", - Flavor: ms.EKSManagedPoolFlavor, - Namespace: namespace, - ClusterName: clusterName, - KubernetesVersion: e2eCtx.E2EConfig.GetVariable(shared.KubernetesVersion), - ControlPlaneMachineCount: ptr.To[int64](1), - WorkerMachineCount: ptr.To[int64](0), - } -} diff --git a/test/e2e/suites/gc_unmanaged/gc_unmanaged_test.go b/test/e2e/suites/unmanaged/unmanaged_gc_test.go similarity index 85% rename from test/e2e/suites/gc_unmanaged/gc_unmanaged_test.go rename to test/e2e/suites/unmanaged/unmanaged_gc_test.go index 0136501c3b..c18a9e4e15 100644 --- a/test/e2e/suites/gc_unmanaged/gc_unmanaged_test.go +++ b/test/e2e/suites/unmanaged/unmanaged_gc_test.go @@ -17,13 +17,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package gc_unmanaged //nolint:stylecheck +package unmanaged //nolint:stylecheck import ( "context" "fmt" "os" - "path/filepath" "github.com/gofrs/flock" "github.com/onsi/ginkgo/v2" @@ -32,8 +31,6 @@ import ( infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/test/framework/clusterctl" "sigs.k8s.io/cluster-api/util" @@ -251,32 +248,3 @@ var _ = ginkgo.Context("[unmanaged] [gc]", func() { }, shared.DisableAlternativeGCStrategy, shared.ValidateAlternativeGCStrategyDisabled) }) }) - -// TODO (richardcase): remove this when we merge these tests with the main eks e2e tests. -func defaultConfigCluster(clusterName, namespace string) clusterctl.ConfigClusterInput { - return clusterctl.ConfigClusterInput{ - LogFolder: filepath.Join(e2eCtx.Settings.ArtifactFolder, "clusters", e2eCtx.Environment.BootstrapClusterProxy.GetName()), - ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath, - KubeconfigPath: e2eCtx.Environment.BootstrapClusterProxy.GetKubeconfigPath(), - InfrastructureProvider: clusterctl.DefaultInfrastructureProvider, - Flavor: clusterctl.DefaultFlavor, - Namespace: namespace, - ClusterName: clusterName, - KubernetesVersion: e2eCtx.E2EConfig.GetVariable(shared.KubernetesVersion), - ControlPlaneMachineCount: ptr.To[int64](1), - WorkerMachineCount: ptr.To[int64](0), - } -} - -// TODO (richardcase): remove this when we merge these tests with the main eks e2e tests. -func createCluster(ctx context.Context, configCluster clusterctl.ConfigClusterInput, result *clusterctl.ApplyClusterTemplateAndWaitResult) (*clusterv1.Cluster, []*clusterv1.MachineDeployment, *controlplanev1.KubeadmControlPlane) { - clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ - ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, - ConfigCluster: configCluster, - WaitForClusterIntervals: e2eCtx.E2EConfig.GetIntervals("", "wait-cluster"), - WaitForControlPlaneIntervals: e2eCtx.E2EConfig.GetIntervals("", "wait-control-plane"), - WaitForMachineDeployments: e2eCtx.E2EConfig.GetIntervals("", "wait-worker-nodes"), - }, result) - - return result.Cluster, result.MachineDeployments, result.ControlPlane -}