Skip to content

Commit 46e7a14

Browse files
committed
Ability to set up additional, bigger nodes during tests
1 parent 514ea6f commit 46e7a14

File tree

5 files changed

+76
-21
lines changed

5 files changed

+76
-21
lines changed

cluster/gce/config-default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ ENABLE_METADATA_AGENT="${KUBE_ENABLE_METADATA_AGENT:-none}"
180180
# Useful for scheduling heapster in large clusters with nodes of small size.
181181
HEAPSTER_MACHINE_TYPE="${HEAPSTER_MACHINE_TYPE:-}"
182182

183+
# Optional: Additional nodes would be created if their type and number is specified.
184+
# NUM_NODES would be lowered respectively.
185+
# Useful for running cluster-level addons that needs more resources than would fit
186+
# on small nodes, like network plugins.
187+
NUM_ADDITIONAL_NODES="${NUM_ADDITIONAL_NODES:-}"
188+
ADDITIONAL_MACHINE_TYPE="${ADDITIONAL_MACHINE_TYPE:-}"
189+
183190
MASTER_NODE_LABELS="${KUBE_MASTER_NODE_LABELS:-}"
184191
# NON_MASTER_NODE_LABELS are labels will only be applied on non-master nodes.
185192
NON_MASTER_NODE_LABELS="${KUBE_NON_MASTER_NODE_LABELS:-}"

cluster/gce/config-test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ ENABLE_METADATA_AGENT="${KUBE_ENABLE_METADATA_AGENT:-none}"
192192
# Useful for scheduling heapster in large clusters with nodes of small size.
193193
HEAPSTER_MACHINE_TYPE="${HEAPSTER_MACHINE_TYPE:-}"
194194

195+
# Optional: Additional nodes would be created if their type and number is specified.
196+
# NUM_NODES would be lowered respectively.
197+
# Useful for running cluster-level addons that needs more resources than would fit
198+
# on small nodes, like network plugins.
199+
NUM_ADDITIONAL_NODES="${NUM_ADDITIONAL_NODES:-}"
200+
ADDITIONAL_MACHINE_TYPE="${ADDITIONAL_MACHINE_TYPE:-}"
201+
195202
# Set etcd image (e.g. k8s.gcr.io/etcd) and version (e.g. 3.3.15-0) if you need
196203
# non-default version.
197204
ETCD_IMAGE="${TEST_ETCD_IMAGE:-}"

cluster/gce/gci/node-helper.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function get-node-instance-metadata-from-file {
3939
# $1: template name (required).
4040
function create-linux-node-instance-template {
4141
local template_name="$1"
42+
local machine_type="${2:-$NODE_SIZE}"
43+
4244
ensure-gci-metadata-files
4345
# shellcheck disable=2154 # 'scope_flags' is assigned by upstream
44-
create-node-template "${template_name}" "${scope_flags[*]}" "$(get-node-instance-metadata-from-file)" "" "linux"
46+
create-node-template "${template_name}" "${scope_flags[*]}" "$(get-node-instance-metadata-from-file)" "" "linux" "${machine_type}"
4547
}

cluster/gce/util.sh

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ function create-node-template() {
21302130
local template_name="$1"
21312131
local metadata_values="$4"
21322132
local os="$5"
2133+
local machine_type="$6"
21332134

21342135
# First, ensure the template doesn't exist.
21352136
# TODO(zmerlynn): To make this really robust, we need to parse the output and
@@ -2216,7 +2217,7 @@ function create-node-template() {
22162217
if ! ${gcloud} compute instance-templates create \
22172218
"${template_name}" \
22182219
--project "${PROJECT}" \
2219-
--machine-type "${NODE_SIZE}" \
2220+
--machine-type "${machine_type}" \
22202221
--boot-disk-type "${NODE_DISK_TYPE}" \
22212222
--boot-disk-size "${NODE_DISK_SIZE}" \
22222223
${node_image_flags} \
@@ -3068,6 +3069,10 @@ function create-nodes-template() {
30683069
local windows_template_name="${WINDOWS_NODE_INSTANCE_PREFIX}-template"
30693070
create-linux-node-instance-template $linux_template_name
30703071
create-windows-node-instance-template $windows_template_name "${scope_flags[*]}"
3072+
if [[ -n "${ADDITIONAL_MACHINE_TYPE:-}" ]]; then
3073+
local linux_extra_template_name="${NODE_INSTANCE_PREFIX}-extra-template"
3074+
create-linux-node-instance-template $linux_extra_template_name "${ADDITIONAL_MACHINE_TYPE}"
3075+
fi
30713076
}
30723077

30733078
# Assumes:
@@ -3096,13 +3101,38 @@ function set_num_migs() {
30963101
# - ZONE
30973102
function create-linux-nodes() {
30983103
local template_name="${NODE_INSTANCE_PREFIX}-template"
3104+
local extra_template_name="${NODE_INSTANCE_PREFIX}-extra-template"
30993105

3100-
if [[ -z "${HEAPSTER_MACHINE_TYPE:-}" ]]; then
3101-
local -r nodes="${NUM_NODES}"
3102-
else
3106+
local nodes="${NUM_NODES}"
3107+
if [[ ! -z "${HEAPSTER_MACHINE_TYPE:-}" ]]; then
31033108
echo "Creating a special node for heapster with machine-type ${HEAPSTER_MACHINE_TYPE}"
31043109
create-heapster-node
3105-
local -r nodes=$(( NUM_NODES - 1 ))
3110+
nodes=$(( nodes - 1 ))
3111+
fi
3112+
3113+
if [[ -n "${ADDITIONAL_MACHINE_TYPE:-}" && "${NUM_ADDITIONAL_NODES:-}" -gt 0 ]]; then
3114+
local num_additional="${NUM_ADDITIONAL_NODES}"
3115+
if [[ "${NUM_ADDITIONAL_NODES:-}" -gt "${nodes}" ]]; then
3116+
echo "Capping NUM_ADDITIONAL_NODES to ${nodes}"
3117+
num_additional="${nodes}"
3118+
fi
3119+
if [[ "${num_additional:-}" -gt 0 ]]; then
3120+
echo "Creating ${num_additional} special nodes with machine-type ${ADDITIONAL_MACHINE_TYPE}"
3121+
local extra_group_name="${NODE_INSTANCE_PREFIX}-extra"
3122+
gcloud compute instance-groups managed \
3123+
create "${extra_group_name}" \
3124+
--project "${PROJECT}" \
3125+
--zone "${ZONE}" \
3126+
--base-instance-name "${extra_group_name}" \
3127+
--size "${num_additional}" \
3128+
--template "${extra_template_name}" || true;
3129+
gcloud compute instance-groups managed wait-until-stable \
3130+
"${extra_group_name}" \
3131+
--zone "${ZONE}" \
3132+
--project "${PROJECT}" \
3133+
--timeout "${MIG_WAIT_UNTIL_STABLE_TIMEOUT}" || true
3134+
nodes=$(( nodes - $num_additional ))
3135+
fi
31063136
fi
31073137

31083138
local instances_left=${nodes}
@@ -3414,13 +3444,15 @@ function kube-down() {
34143444

34153445
local all_instance_groups=(${INSTANCE_GROUPS[@]:-} ${WINDOWS_INSTANCE_GROUPS[@]:-})
34163446
for group in ${all_instance_groups[@]:-}; do
3417-
if gcloud compute instance-groups managed describe "${group}" --project "${PROJECT}" --zone "${ZONE}" &>/dev/null; then
3418-
gcloud compute instance-groups managed delete \
3419-
--project "${PROJECT}" \
3420-
--quiet \
3421-
--zone "${ZONE}" \
3422-
"${group}" &
3423-
fi
3447+
{
3448+
if gcloud compute instance-groups managed describe "${group}" --project "${PROJECT}" --zone "${ZONE}" &>/dev/null; then
3449+
gcloud compute instance-groups managed delete \
3450+
--project "${PROJECT}" \
3451+
--quiet \
3452+
--zone "${ZONE}" \
3453+
"${group}"
3454+
fi
3455+
} &
34243456
done
34253457

34263458
# Wait for last batch of jobs
@@ -3429,14 +3461,21 @@ function kube-down() {
34293461
}
34303462

34313463
for template in ${templates[@]:-}; do
3432-
if gcloud compute instance-templates describe --project "${PROJECT}" "${template}" &>/dev/null; then
3433-
gcloud compute instance-templates delete \
3434-
--project "${PROJECT}" \
3435-
--quiet \
3436-
"${template}"
3437-
fi
3464+
{
3465+
if gcloud compute instance-templates describe --project "${PROJECT}" "${template}" &>/dev/null; then
3466+
gcloud compute instance-templates delete \
3467+
--project "${PROJECT}" \
3468+
--quiet \
3469+
"${template}"
3470+
fi
3471+
} &
34383472
done
34393473

3474+
# Wait for last batch of jobs
3475+
kube::util::wait-for-jobs || {
3476+
echo -e "Failed to delete instance template(s)." >&2
3477+
}
3478+
34403479
# Delete the special heapster node (if it exists).
34413480
if [[ -n "${HEAPSTER_MACHINE_TYPE:-}" ]]; then
34423481
local -r heapster_machine_name="${NODE_INSTANCE_PREFIX}-heapster"
@@ -3717,7 +3756,7 @@ function set-replica-name() {
37173756
#
37183757
# $1: project
37193758
function get-template() {
3720-
local linux_filter="${NODE_INSTANCE_PREFIX}-template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?"
3759+
local linux_filter="${NODE_INSTANCE_PREFIX}-(extra-)?template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?"
37213760
local windows_filter="${WINDOWS_NODE_INSTANCE_PREFIX}-template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?"
37223761

37233762
gcloud compute instance-templates list \

cluster/gce/windows/node-helper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ function get-windows-node-instance-metadata {
5454
function create-windows-node-instance-template {
5555
local template_name="$1"
5656
local scopes_flag="$2"
57-
create-node-template "${template_name}" "${scopes_flag}" "$(get-windows-node-instance-metadata-from-file)" "$(get-windows-node-instance-metadata)" "windows"
57+
create-node-template "${template_name}" "${scopes_flag}" "$(get-windows-node-instance-metadata-from-file)" "$(get-windows-node-instance-metadata)" "windows" "${NODE_SIZE}"
5858
}

0 commit comments

Comments
 (0)