Skip to content

Commit fd775a8

Browse files
sebrandon1rdavid
andauthored
Adjust replicas if cluster has a single node (#226)
* Adjust replicas if cluster has a single node * Add new line to the end --------- Co-authored-by: David Rabkin <[email protected]>
1 parent 0b024f6 commit fd775a8

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
install-prometheus
88

99
# Deploys the partner and test pods and the operator
10-
install:
10+
install: clean
1111
./scripts/fix-node-labels.sh
1212
./scripts/deploy-multus-network.sh
1313
./scripts/deploy-resource-quota.sh

scripts/clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ source "$SCRIPT_DIR"/init-env.sh
1818
./"$SCRIPT_DIR"/delete-limit-range.sh
1919
./"$SCRIPT_DIR"/delete-resource-quota.sh
2020
./"$SCRIPT_DIR"/delete-pod-disruption-budget.sh
21+
./"$SCRIPT_DIR"/delete-operator-crd-scaling.sh
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$(dirname "$0")"
4+
5+
# shellcheck disable=SC1091 # Not following.
6+
source "$SCRIPT_DIR"/init-env.sh
7+
REPO_NAME=crd-operator-scaling
8+
CRD_SCALING_URL=https://github.com/test-network-function/$REPO_NAME.git
9+
rm -rf $REPO_NAME
10+
git clone $CRD_SCALING_URL
11+
## install the operator
12+
cd $REPO_NAME || exit 1
13+
## uninstall the crd
14+
make uninstall
15+
make undeploy ignore-not-found=true
16+
rm -rf $REPO_NAME

scripts/deploy-statefulset-test-pods.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,30 @@ source "$SCRIPT_DIR"/init-env.sh
88

99
mkdir -p ./temp
1010

11+
REPLICAS=2
12+
# adjust replicas for possible SNO clusters
13+
NUM_NODES=$(oc get nodes --no-headers | wc -l)
14+
if [[ $NUM_NODES == 1 ]]; then
15+
REPLICAS=1
16+
fi
17+
1118
# shellcheck disable=SC2002 # Useless cat.
12-
cat ./test-target/local-pod-under-test.yaml | APP="testss" RESOURCE_TYPE="StatefulSet" MULTUS_ANNOTATION=$MULTUS_ANNOTATION "$SCRIPT_DIR"/mo > ./temp/rendered-local-statefulset-pod-under-test-template.yaml
19+
cat ./test-target/local-pod-under-test.yaml | APP="testss" RESOURCE_TYPE="StatefulSet" MULTUS_ANNOTATION=$MULTUS_ANNOTATION REPLICAS=$REPLICAS "$SCRIPT_DIR"/mo > ./temp/rendered-local-statefulset-pod-under-test-template.yaml
1320
oc apply --filename ./temp/rendered-local-statefulset-pod-under-test-template.yaml
1421
rm ./temp/rendered-local-statefulset-pod-under-test-template.yaml
1522
sleep 3
1623

1724
oc wait -l statefulset.kubernetes.io/pod-name=test-0 -n "$TNF_EXAMPLE_CNF_NAMESPACE" --for=condition=ready pod --timeout="$TNF_DEPLOYMENT_TIMEOUT"
18-
oc wait -l statefulset.kubernetes.io/pod-name=test-1 -n "$TNF_EXAMPLE_CNF_NAMESPACE" --for=condition=ready pod --timeout="$TNF_DEPLOYMENT_TIMEOUT"
1925

20-
# Check for existing HPA first
21-
if ! oc get hpa test -n "$TNF_EXAMPLE_CNF_NAMESPACE"; then
22-
oc autoscale statefulset test -n "$TNF_EXAMPLE_CNF_NAMESPACE" --cpu-percent=50 --min=2 --max=3
26+
# Wait if there is more than one replica
27+
if [[ $REPLICAS -gt 1 ]]; then
28+
oc wait -l statefulset.kubernetes.io/pod-name=test-1 -n "$TNF_EXAMPLE_CNF_NAMESPACE" --for=condition=ready pod --timeout="$TNF_DEPLOYMENT_TIMEOUT"
29+
fi
30+
31+
# Only autoscale if there is more than one replica
32+
if [[ $REPLICAS -gt 1 ]]; then
33+
# Check for existing HPA first
34+
if ! oc get hpa test -n "$TNF_EXAMPLE_CNF_NAMESPACE"; then
35+
oc autoscale statefulset test -n "$TNF_EXAMPLE_CNF_NAMESPACE" --cpu-percent=50 --min=2 --max=3
36+
fi
2337
fi

scripts/deploy-test-pods.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ source "$SCRIPT_DIR"/init-env.sh
88

99
mkdir -p ./temp
1010

11+
REPLICAS=2
12+
# adjust replicas for possible SNO clusters
13+
NUM_NODES=$(oc get nodes --no-headers | wc -l)
14+
if [[ $NUM_NODES == 1 ]]; then
15+
REPLICAS=1
16+
fi
17+
1118
# shellcheck disable=SC2002 # Useless cat.
12-
cat ./test-target/local-pod-under-test.yaml | APP="testdp" RESOURCE_TYPE="Deployment" MULTUS_ANNOTATION=$MULTUS_ANNOTATION "$SCRIPT_DIR"/mo > ./temp/rendered-local-pod-under-test-template.yaml
19+
cat ./test-target/local-pod-under-test.yaml | APP="testdp" RESOURCE_TYPE="Deployment" MULTUS_ANNOTATION=$MULTUS_ANNOTATION REPLICAS=$REPLICAS "$SCRIPT_DIR"/mo > ./temp/rendered-local-pod-under-test-template.yaml
1320
oc apply --filename ./temp/rendered-local-pod-under-test-template.yaml
1421
rm ./temp/rendered-local-pod-under-test-template.yaml
1522

test-target/local-pod-under-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
name: test
88
namespace: {{ TNF_EXAMPLE_CNF_NAMESPACE }}
99
spec:
10-
replicas: 2
10+
replicas: {{ REPLICAS }}
1111
selector:
1212
matchLabels:
1313
app: {{ APP }}

0 commit comments

Comments
 (0)