|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +/* |
| 5 | +Copyright 2025 The Kubernetes Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +*/ |
| 19 | + |
| 20 | +package managed |
| 21 | + |
| 22 | +import ( |
| 23 | + "context" |
| 24 | + "fmt" |
| 25 | + |
| 26 | + "github.com/onsi/ginkgo/v2" |
| 27 | + . "github.com/onsi/gomega" |
| 28 | + corev1 "k8s.io/api/core/v1" |
| 29 | + crclient "sigs.k8s.io/controller-runtime/pkg/client" |
| 30 | + |
| 31 | + infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" |
| 32 | + ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2" |
| 33 | + "sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared" |
| 34 | + "sigs.k8s.io/cluster-api/test/framework" |
| 35 | + "sigs.k8s.io/cluster-api/util" |
| 36 | +) |
| 37 | + |
| 38 | +// Validates the eks-nodeadm-clusterclass flavor provisions a cluster with Nodeadm bootstrap and expected machine template settings. |
| 39 | +var _ = ginkgo.Describe("[managed] [general] EKS nodeadm ClusterClass tests", func() { |
| 40 | + var ( |
| 41 | + namespace *corev1.Namespace |
| 42 | + ctx context.Context |
| 43 | + specName = "eks-nodeadm-clusterclass" |
| 44 | + clusterName string |
| 45 | + ) |
| 46 | + |
| 47 | + shared.ConditionalIt(runGeneralTests, "should create a cluster using Nodeadm ClusterClass and validate configuration", func() { |
| 48 | + ginkgo.By("should have a valid test configuration") |
| 49 | + Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "BootstrapClusterProxy can't be nil") |
| 50 | + Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "E2EConfig can't be nil") |
| 51 | + Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.KubernetesVersion)) |
| 52 | + |
| 53 | + ctx = context.TODO() |
| 54 | + namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx) |
| 55 | + clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) |
| 56 | + eksClusterName := getEKSClusterName(namespace.Name, clusterName) |
| 57 | + |
| 58 | + ginkgo.By("default iam role should exist") |
| 59 | + VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, eksClusterName, false, e2eCtx.AWSSession) |
| 60 | + |
| 61 | + ginkgo.By("should create a cluster from the nodeadm ClusterClass flavor") |
| 62 | + ManagedClusterSpec(ctx, func() ManagedClusterSpecInput { |
| 63 | + return ManagedClusterSpecInput{ |
| 64 | + E2EConfig: e2eCtx.E2EConfig, |
| 65 | + ConfigClusterFn: defaultConfigCluster, |
| 66 | + BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 67 | + AWSSession: e2eCtx.BootstrapUserAWSSession, |
| 68 | + Namespace: namespace, |
| 69 | + ClusterName: clusterName, |
| 70 | + Flavour: EKSNodeadmClusterClassFlavor, |
| 71 | + ControlPlaneMachineCount: 1, // required by clusterctl |
| 72 | + WorkerMachineCount: 1, |
| 73 | + } |
| 74 | + }) |
| 75 | + |
| 76 | + ginkgo.By("validating the MachineDeployment uses Nodeadm bootstrap and AWSMachineTemplate settings") |
| 77 | + cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{ |
| 78 | + Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 79 | + Namespace: namespace.Name, |
| 80 | + Name: clusterName, |
| 81 | + }) |
| 82 | + Expect(cluster).NotTo(BeNil(), "cluster should exist") |
| 83 | + |
| 84 | + mds := framework.DiscoveryAndWaitForMachineDeployments(ctx, framework.DiscoveryAndWaitForMachineDeploymentsInput{ |
| 85 | + Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 86 | + Cluster: cluster, |
| 87 | + }, e2eCtx.E2EConfig.GetIntervals("", "wait-worker-nodes")...) |
| 88 | + Expect(mds).ToNot(BeEmpty(), "expected at least one MachineDeployment") |
| 89 | + md := mds[0] |
| 90 | + |
| 91 | + Expect(md.Spec.Template.Spec.Bootstrap.ConfigRef).ToNot(BeNil(), "bootstrap config ref must be set") |
| 92 | + Expect(md.Spec.Template.Spec.Bootstrap.ConfigRef.Kind).To(Equal("NodeadmConfigTemplate"), "bootstrap config kind should be NodeadmConfigTemplate") |
| 93 | + |
| 94 | + Expect(md.Spec.Template.Spec.InfrastructureRef.Kind).To(Equal("AWSMachineTemplate"), "infrastructure ref should be AWSMachineTemplate") |
| 95 | + awsMT := &infrav1.AWSMachineTemplate{} |
| 96 | + Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Get(ctx, crclient.ObjectKey{ |
| 97 | + Namespace: namespace.Name, |
| 98 | + Name: md.Spec.Template.Spec.InfrastructureRef.Name, |
| 99 | + }, awsMT)).To(Succeed(), "expected to fetch AWSMachineTemplate") |
| 100 | + |
| 101 | + Expect(awsMT.Spec.Template.Spec.CloudInit.InsecureSkipSecretsManager).To(BeTrue(), "cloudInit.insecureSkipSecretsManager should be true") |
| 102 | + Expect(awsMT.Spec.Template.Spec.AMI.EKSOptimizedLookupType).ToNot(BeNil(), "AMI.EKSOptimizedLookupType should be set") |
| 103 | + Expect(*awsMT.Spec.Template.Spec.AMI.EKSOptimizedLookupType).To(Equal(infrav1.AmazonLinux2023), "AMI lookup type should be AmazonLinux2023") |
| 104 | + |
| 105 | + ginkgo.By("deleting the cluster") |
| 106 | + framework.DeleteCluster(ctx, framework.DeleteClusterInput{ |
| 107 | + Deleter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(), |
| 108 | + Cluster: cluster, |
| 109 | + }) |
| 110 | + framework.WaitForClusterDeleted(ctx, framework.WaitForClusterDeletedInput{ |
| 111 | + ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy, |
| 112 | + Cluster: cluster, |
| 113 | + ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath, |
| 114 | + ArtifactFolder: e2eCtx.Settings.ArtifactFolder, |
| 115 | + }, e2eCtx.E2EConfig.GetIntervals("", "wait-delete-cluster")...) |
| 116 | + }) |
| 117 | +}) |
0 commit comments