Skip to content

Commit 234d39f

Browse files
committed
Add test scenario for Karpenter
1 parent c9ca2e3 commit 234d39f

File tree

2 files changed

+132
-4
lines changed

2 files changed

+132
-4
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
REPO_ROOT=$(git rev-parse --show-toplevel);
18+
source "${REPO_ROOT}"/tests/e2e/scenarios/lib/common.sh
19+
20+
kops-acquire-latest
21+
22+
NETWORKING=cilium
23+
OVERRIDES="${OVERRIDES-} --instance-manager=karpenter"
24+
OVERRIDES="${OVERRIDES} --control-plane-size=c6g.large"
25+
26+
kops-up
27+
28+
# Get the node instance group user data script from the kOps state store
29+
USER_DATA=$(aws s3 cp "${KOPS_STATE_STORE-}/${CLUSTER_NAME}/igconfig/node/nodes/nodeupscript.sh" -)
30+
# Indent the user data script for embedding in the EC2NodeClass
31+
USER_DATA=${USER_DATA//$'\n'/$'\n '}
32+
33+
# Create a EC2NodeClass for Karpenter
34+
kubectl apply -f - <<YAML
35+
apiVersion: karpenter.k8s.aws/v1
36+
kind: EC2NodeClass
37+
metadata:
38+
name: default
39+
spec:
40+
amiFamily: Custom
41+
amiSelectorTerms:
42+
- ssmParameter: /aws/service/canonical/ubuntu/server/24.04/stable/current/arm64/hvm/ebs-gp3/ami-id
43+
associatePublicIPAddress: true
44+
tags:
45+
KubernetesCluster: ${CLUSTER_NAME}
46+
kops.k8s.io/instancegroup: nodes
47+
k8s.io/role/node: "1"
48+
subnetSelectorTerms:
49+
- tags:
50+
KubernetesCluster: ${CLUSTER_NAME}
51+
securityGroupSelectorTerms:
52+
- tags:
53+
KubernetesCluster: ${CLUSTER_NAME}
54+
Name: nodes.${CLUSTER_NAME}
55+
instanceProfile: nodes.${CLUSTER_NAME}
56+
userData: |
57+
${USER_DATA}
58+
YAML
59+
60+
# Create a NodePool for Karpenter
61+
# Effectively disable consolidation for 30 minutes to avoid flakes in the tests
62+
kubectl apply -f - <<YAML
63+
apiVersion: karpenter.sh/v1
64+
kind: NodePool
65+
metadata:
66+
name: default
67+
spec:
68+
template:
69+
spec:
70+
requirements:
71+
- key: node.kubernetes.io/instance-type
72+
operator: In
73+
values: ["m6g.large"]
74+
- key: karpenter.sh/capacity-type
75+
operator: In
76+
values: ["on-demand"]
77+
nodeClassRef:
78+
group: karpenter.k8s.aws
79+
kind: EC2NodeClass
80+
name: default
81+
limits:
82+
cpu: 10
83+
disruption:
84+
consolidationPolicy: WhenEmpty
85+
consolidateAfter: 30m
86+
YAML
87+
88+
# Create a deployment that will force nodes to be created
89+
kubectl apply -f - <<YAML
90+
apiVersion: apps/v1
91+
kind: Deployment
92+
metadata:
93+
name: node-hold
94+
spec:
95+
replicas: 2
96+
selector:
97+
matchLabels:
98+
app: node-hold
99+
template:
100+
metadata:
101+
labels:
102+
app: node-hold
103+
spec:
104+
topologySpreadConstraints:
105+
- maxSkew: 1
106+
topologyKey: kubernetes.io/hostname
107+
whenUnsatisfiable: DoNotSchedule
108+
labelSelector:
109+
matchLabels:
110+
app: node-hold
111+
containers:
112+
- name: pause
113+
image: registry.k8s.io/pause:3.10.1
114+
YAML
115+
116+
# Wait for the nodes to be provisioned
117+
sleep 30
118+
# Wait for the nodes to be ready
119+
"${KOPS}" validate cluster --wait=10m
120+
121+
# Run the tests
122+
cp "${KOPS}" "${WORKSPACE}/kops"
123+
${KUBETEST2} \
124+
--test=kops \
125+
--kops-binary-path="${KOPS}" \
126+
-- \
127+
--test-package-version="${K8S_VERSION}" \
128+
--focus-regex="\[Conformance\]" \
129+
--parallel 20

tests/e2e/scenarios/lib/common.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ if [[ -z "${DISCOVERY_STORE-}" ]]; then
4545
DISCOVERY_STORE="${KOPS_STATE_STORE-}"
4646
fi
4747

48-
export GO111MODULE=on
49-
5048
if [[ -z "${AWS_SSH_PRIVATE_KEY_FILE-}" ]]; then
5149
export AWS_SSH_PRIVATE_KEY_FILE="${HOME}/.ssh/id_rsa"
5250
fi
@@ -55,8 +53,9 @@ if [[ -z "${AWS_SSH_PUBLIC_KEY_FILE-}" ]]; then
5553
fi
5654

5755
KUBETEST2="kubetest2 kops -v=2 --cloud-provider=${CLOUD_PROVIDER} --cluster-name=${CLUSTER_NAME:-} --kops-root=${REPO_ROOT}"
58-
KUBETEST2="${KUBETEST2} --admin-access=${ADMIN_ACCESS:-}"
59-
56+
if [[ -n "${ADMIN_ACCESS-}" ]]; then
57+
KUBETEST2="${KUBETEST2} --admin-access=${ADMIN_ACCESS}"
58+
fi
6059
if [[ -n "${GCP_PROJECT-}" ]]; then
6160
KUBETEST2="${KUBETEST2} --gcp-project=${GCP_PROJECT}"
6261
fi

0 commit comments

Comments
 (0)