Skip to content

Commit dafefd0

Browse files
galiachengedburns
authored andcommitted
create connect_aks as common function. (#3)
1 parent 1ab587c commit dafefd0

File tree

13 files changed

+506
-67
lines changed

13 files changed

+506
-67
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) 2024, Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
function get_cluster_uid(){
5+
local clusterUid=$(kubectl get clusters -n ${WLS_NAMESPACE} -o=jsonpath='{.items[].metadata.name}')
6+
utility_validate_status "Obtain cluster UID."
7+
export WLS_CLUSTER_UID=${clusterUid}
8+
}
9+
10+
function scaling_basedon_cpu(){
11+
kubectl autoscale cluster ${WLS_CLUSTER_UID} \
12+
--cpu-percent=${UTILIZATION_PERCENTAGE} \
13+
--min=1 \
14+
--max=${WLS_CLUSTER_SIZE} \
15+
-n ${WLS_NAMESPACE}
16+
utility_validate_status "Enable HPA based on CPU utilization."
17+
}
18+
19+
function scaling_basedon_memory(){
20+
cat <<EOF >scaler-memory.yaml
21+
apiVersion: autoscaling/v2
22+
kind: HorizontalPodAutoscaler
23+
metadata:
24+
name: ${WLS_CLUSTER_UID}
25+
namespace: ${WLS_NAMESPACE}
26+
spec:
27+
scaleTargetRef:
28+
apiVersion: weblogic.oracle/v1
29+
kind: Cluster
30+
name: ${WLS_CLUSTER_UID}
31+
minReplicas: 1
32+
maxReplicas: ${WLS_CLUSTER_SIZE}
33+
metrics:
34+
- type: Resource
35+
resource:
36+
name: memory
37+
target:
38+
averageUtilization: ${UTILIZATION_PERCENTAGE}
39+
type: Utilization
40+
EOF
41+
42+
kubectl apply -f scaler-memory.yaml
43+
utility_validate_status "Enable HPA based on memory utilization."
44+
}
45+
46+
function check_kubernetes_metrics_server(){
47+
# $?=1 if there is no running kms pod.
48+
kubectl get pod -l k8s-app=metrics-server -n kube-system | grep "Running"
49+
# exit if $?=1
50+
utility_validate_status "There should be at least one pod of kubernetes metrics server running."
51+
}
52+
53+
# Main script
54+
set -Eo pipefail
55+
56+
install_kubectl
57+
58+
connect_aks $AKS_CLUSTER_NAME $AKS_CLUSTER_RG_NAME
59+
60+
get_cluster_uid
61+
62+
check_kubernetes_metrics_server
63+
64+
if [ "$HPA_SCALE_TYPE" == "cpu" ]; then
65+
scaling_basedon_cpu
66+
elif [ "$HPA_SCALE_TYPE" == "memory" ]; then
67+
scaling_basedon_memory
68+
fi

0 commit comments

Comments
 (0)