-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- converted to ginkgo/v2 - added the following e2e config fields for ipam e2e test: - NODE_IPAM_POOL_SUBNET - NODE_IPAM_POOL_GATEWAY - NODE_IPAM_POOL_START - NODE_IPAM_POOL_END - NODE_IPAM_NAMESERVER Co-authored-by: Aidan Obley <[email protected]> Co-authored-by: Christian Ang <[email protected]> Co-authored-by: Tyler Schultz <[email protected]> Co-authored-by: Edwin Xie <[email protected]>
- Loading branch information
1 parent
86c1aee
commit f381890
Showing
8 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test/e2e/data/cluster-api-ipam-provider-in-cluster/metadata.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3 | ||
kind: Metadata | ||
releaseSeries: | ||
- major: 0 | ||
minor: 1 | ||
contract: v1beta1 |
34 changes: 34 additions & 0 deletions
34
test/e2e/data/infrastructure-vsphere/kustomization/ipam/ipam-template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 | ||
kind: VSphereMachineTemplate | ||
metadata: | ||
name: ${CLUSTER_NAME} | ||
namespace: ${NAMESPACE} | ||
spec: | ||
template: | ||
spec: | ||
network: | ||
devices: | ||
- nameservers: ["${NODE_IPAM_NAMESERVER}"] | ||
addressesFromPools: | ||
- name: inclusterippool | ||
apiGroup: ipam.cluster.x-k8s.io | ||
kind: InClusterIPPool | ||
networkName: '${VSPHERE_NETWORK}' | ||
--- | ||
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 | ||
kind: VSphereMachineTemplate | ||
metadata: | ||
name: ${CLUSTER_NAME}-worker | ||
namespace: ${NAMESPACE} | ||
spec: | ||
template: | ||
spec: | ||
network: | ||
devices: | ||
- nameservers: ["${NODE_IPAM_NAMESERVER}"] | ||
addressesFromPools: | ||
- name: inclusterippool | ||
apiGroup: ipam.cluster.x-k8s.io | ||
kind: InClusterIPPool | ||
networkName: '${VSPHERE_NETWORK}' |
7 changes: 7 additions & 0 deletions
7
test/e2e/data/infrastructure-vsphere/kustomization/ipam/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- ../base | ||
- pool.yaml | ||
patchesStrategicMerge: | ||
- ipam-template.yaml |
11 changes: 11 additions & 0 deletions
11
test/e2e/data/infrastructure-vsphere/kustomization/ipam/pool.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: ipam.cluster.x-k8s.io/v1alpha1 | ||
kind: InClusterIPPool | ||
metadata: | ||
name: inclusterippool | ||
namespace: ${NAMESPACE} | ||
spec: | ||
subnet: ${NODE_IPAM_POOL_SUBNET} | ||
gateway: ${NODE_IPAM_POOL_GATEWAY} | ||
start: ${NODE_IPAM_POOL_START} | ||
end: ${NODE_IPAM_POOL_END} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
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 e2e | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/utils/pointer" | ||
"sigs.k8s.io/cluster-api/test/framework/clusterctl" | ||
"sigs.k8s.io/cluster-api/util" | ||
) | ||
|
||
const ( | ||
NodeIPAMPoolSubnet = "NODE_IPAM_POOL_SUBNET" | ||
NodeIPAMPoolStart = "NODE_IPAM_POOL_START" | ||
NodeIPAMPoolEnd = "NODE_IPAM_POOL_END" | ||
) | ||
|
||
var _ = Describe("Clusters using FromPools get assigned addresses from IPAM", func() { | ||
var namespace *v1.Namespace | ||
var start, end string | ||
|
||
BeforeEach(func() { | ||
start = e2eConfig.GetVariable(NodeIPAMPoolStart) | ||
Expect(net.ParseIP(start)).NotTo(BeNil()) | ||
end = e2eConfig.GetVariable(NodeIPAMPoolEnd) | ||
Expect(net.ParseIP(end)).NotTo(BeNil()) | ||
Expect(bootstrapClusterProxy).NotTo(BeNil(), "BootstrapClusterProxy can't be nil") | ||
namespace = setupSpecNamespace("node-ipam") | ||
}) | ||
|
||
AfterEach(func() { | ||
cleanupSpecNamespace(namespace) | ||
}) | ||
|
||
It("should create a cluster successfully", func() { | ||
clusterName := fmt.Sprintf("cluster-%s", util.RandomString(6)) | ||
|
||
By("creating a workload cluster") | ||
configCluster := ipamConfigCluster(clusterName, namespace.Name, 1, 1) | ||
|
||
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ | ||
ClusterProxy: bootstrapClusterProxy, | ||
ConfigCluster: configCluster, | ||
WaitForClusterIntervals: e2eConfig.GetIntervals("", "wait-cluster"), | ||
WaitForControlPlaneIntervals: e2eConfig.GetIntervals("", "wait-control-plane"), | ||
WaitForMachineDeployments: e2eConfig.GetIntervals("", "wait-worker-nodes"), | ||
}, &clusterctl.ApplyClusterTemplateAndWaitResult{}) | ||
|
||
By("Verifying that the cluster is using IPAM provided IP addresses") | ||
list := getVSphereVMsForCluster(clusterName, namespace.Name) | ||
Expect(list.Items).NotTo(BeEmpty()) | ||
for _, vm := range list.Items { | ||
path := fmt.Sprintf("/%s/vm/%s/%s", vm.Spec.Datacenter, vm.Spec.Folder, vm.Name) | ||
vm, err := vsphereFinder.VirtualMachine(ctx, path) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
ip, err := vm.WaitForIP(ctx, true) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(IPIsInRange(ip, start, end)).To(BeTrue(), fmt.Sprintf("Expected IP %q to be between %q and %q", ip, start, end)) | ||
} | ||
}) | ||
}) | ||
|
||
func IPIsInRange(ip, rangeStart, rangeEnd string) bool { | ||
parsedIP := net.ParseIP(ip) | ||
Expect(parsedIP).NotTo(BeNil()) | ||
|
||
parsedStart := net.ParseIP(rangeStart) | ||
Expect(parsedStart).NotTo(BeNil()) | ||
|
||
parsedEnd := net.ParseIP(rangeEnd) | ||
Expect(parsedEnd).NotTo(BeNil()) | ||
|
||
return bytes.Compare(parsedIP, parsedStart) >= 0 && bytes.Compare(parsedIP, parsedEnd) <= 0 | ||
} | ||
|
||
func ipamConfigCluster(clusterName, namespace string, controlPlaneNodeCount, workerNodeCount int64) clusterctl.ConfigClusterInput { | ||
return clusterctl.ConfigClusterInput{ | ||
LogFolder: filepath.Join(artifactFolder, "clusters", bootstrapClusterProxy.GetName()), | ||
ClusterctlConfigPath: clusterctlConfigPath, | ||
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(), | ||
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider, | ||
Flavor: "ipam", | ||
Namespace: namespace, | ||
ClusterName: clusterName, | ||
KubernetesVersion: e2eConfig.GetVariable(KubernetesVersion), | ||
ControlPlaneMachineCount: pointer.Int64Ptr(controlPlaneNodeCount), | ||
WorkerMachineCount: pointer.Int64Ptr(workerNodeCount), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters