Skip to content

Commit 2cbe03b

Browse files
authoredJan 20, 2025··
Merge pull request #16943 from justinsb/e2e_validate_cluster
e2e: add `kops validate` step to metal test
2 parents 9757678 + 8538891 commit 2cbe03b

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed
 

‎tests/e2e/scenarios/bare-metal/run-test

+14-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ function cleanup() {
3434
echo "running dump-artifacts"
3535
${REPO_ROOT}/tests/e2e/scenarios/bare-metal/dump-artifacts || true
3636

37-
echo "running cleanup"
38-
${REPO_ROOT}/tests/e2e/scenarios/bare-metal/cleanup || true
37+
if [[ -z "${SKIP_CLEANUP:-}" ]]; then
38+
echo "running cleanup"
39+
${REPO_ROOT}/tests/e2e/scenarios/bare-metal/cleanup || true
40+
fi
3941
}
4042

4143
if [[ -z "${SKIP_CLEANUP:-}" ]]; then
@@ -136,8 +138,14 @@ ssh -o StrictHostKeyChecking=accept-new -i ${REPO_ROOT}/.build/.ssh/id_ed25519 r
136138
ssh -o StrictHostKeyChecking=accept-new -i ${REPO_ROOT}/.build/.ssh/id_ed25519 root@10.123.45.10 touch /mnt/disks/metal.k8s.local--events--0/mnt/please-create-new-cluster
137139

138140

139-
echo "Waiting 300 seconds for kube to start"
140-
sleep 300
141+
echo "Waiting for kube to start"
142+
# Wait for kube-apiserver to be ready, timeout after 10 minutes
143+
for i in {1..60}; do
144+
if kubectl get nodes; then
145+
break
146+
fi
147+
sleep 10
148+
done
141149

142150
kubectl get nodes
143151
kubectl get pods -A
@@ -215,5 +223,7 @@ sleep 30
215223
kubectl get nodes
216224
kubectl get pods -A
217225

226+
# Ensure the cluster passes validation
227+
${KOPS} validate cluster metal.k8s.local --wait=10m
218228

219229
echo "Test successful"

‎upup/pkg/fi/cloudup/metal/cloud.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,45 @@ func (c *Cloud) DetachInstance(instance *cloudinstances.CloudInstance) error {
7575
// GetCloudGroups returns a map of cloud instances that back a kops cluster.
7676
// Detached instances must be returned in the NeedUpdate slice.
7777
func (c *Cloud) GetCloudGroups(cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) {
78-
return nil, fmt.Errorf("method metal.Cloud::GetCloudGroups not implemented")
78+
groups := make(map[string]*cloudinstances.CloudInstanceGroup)
79+
for _, ig := range instancegroups {
80+
cloudInstanceGroup := &cloudinstances.CloudInstanceGroup{
81+
InstanceGroup: ig,
82+
}
83+
groups[ig.ObjectMeta.Name] = cloudInstanceGroup
84+
for _, node := range nodes {
85+
isControlPlaneNode := false
86+
for k := range node.Labels {
87+
if k == "node-role.kubernetes.io/control-plane" {
88+
isControlPlaneNode = true
89+
}
90+
91+
}
92+
93+
match := true
94+
switch ig.Spec.Role {
95+
case kops.InstanceGroupRoleControlPlane:
96+
if !isControlPlaneNode {
97+
match = false
98+
}
99+
100+
case kops.InstanceGroupRoleNode:
101+
if isControlPlaneNode {
102+
match = false
103+
}
104+
}
105+
106+
if match {
107+
cloudInstanceGroup.Ready = append(cloudInstanceGroup.Ready, &cloudinstances.CloudInstance{
108+
ID: node.Name,
109+
Node: &node,
110+
CloudInstanceGroup: cloudInstanceGroup,
111+
})
112+
}
113+
}
114+
}
115+
116+
return groups, nil
79117
}
80118

81119
// Region returns the cloud region bound to the cloud instance.

0 commit comments

Comments
 (0)
Please sign in to comment.