Skip to content

Commit

Permalink
fix(scripts): modify labels for obproxy set up from the shell (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI authored Aug 28, 2024
1 parent 9b2ef03 commit aca7a79
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions scripts/setup-obproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ SVC_TYPE=ClusterIP
DISPLAY_INFO=false
LIST=false
LIST_ALL=false
ENV_VARS=()
CONFIG_MAP=""

function print_help {
echo "setup-obproxy.sh - Set up obproxy for an OBCluster in a Kubernetes cluster"
Expand All @@ -26,6 +28,8 @@ function print_help {
echo " -d, --deploy-name <Name> Name of the obproxy deployment. Default is obproxy-<OBCluster>."
echo " -r, --replicas <Number> Number of replicas of the obproxy deployment. Default is 2."
echo " --destroy Destroy the obproxy deployment."
echo " -e, --env <key=value> Environment variable of the obproxy deployment."
echo " --cm <ConfigMap> ConfigMap of the obproxy deployment."
echo " --cpu <CPU> CPU limit of the obproxy deployment. Default is 1."
echo " --memory <Memory> Memory limit of the obproxy deployment. Default is 2Gi."
echo " --svc-type <Type> Service type of the obproxy deployment. Default is ClusterIP. Valid values are ClusterIP, NodePort, LoadBalancer."
Expand Down Expand Up @@ -73,6 +77,28 @@ while [[ $# -gt 0 ]]; do
REPLICAS=$2
shift
;;
-e|--env)
if [[ $CONFIG_MAP != "" ]]; then
echo "Error: Environment variables and ConfigMap cannot be set at the same time."
exit 1
fi
echo "-e" "$2"
ENV_VARS+=("$2")
shift
;;
--cm)
if [[ $2 == "" ]]; then
echo "Error: ConfigMap name is empty."
exit 1
fi
# if length of ENV_VARS > 0
if [[ ${#ENV_VARS[@]} -gt 0 ]]; then
echo "Error: Environment variables and ConfigMap cannot be set at the same time."
exit 1
fi
CONFIG_MAP=$2
shift
;;
--svc-type)
SVC_TYPE=$2
if [[ $SVC_TYPE != "ClusterIP" && $SVC_TYPE != "NodePort" && $SVC_TYPE != "LoadBalancer" ]]; then
Expand Down Expand Up @@ -112,9 +138,9 @@ done
if [[ $LIST == true ]]; then
echo -e "\nOBProxy Deployments: \n"
if [[ $LIST_ALL == true ]]; then
kubectl get deployment -A -l obproxy.oceanbase.com/obproxy -L obproxy.oceanbase.com/for-obcluster -o wide
kubectl get deployment -A -l obproxy.oceanbase.com/obproxy-from-setup -L obproxy.oceanbase.com/for-obcluster -o wide
else
kubectl get deployment -n $NAMESPACE -l obproxy.oceanbase.com/obproxy -L obproxy.oceanbase.com/for-obcluster -o wide
kubectl get deployment -n $NAMESPACE -l obproxy.oceanbase.com/obproxy-from-setup -L obproxy.oceanbase.com/for-obcluster -o wide
fi
exit 0
fi
Expand Down Expand Up @@ -149,6 +175,17 @@ function check_requirements {

check_requirements

if [[ $CONFIG_MAP == "" ]]; then
# Create ConfigMap
CONFIG_MAP="cm-obproxy-$OB_CLUSTER"
# ENV_VARS is an key=value array
env_list="--from-literal=DEPLOYED_TIME=$(date +'%Y-%m-%d.%H:%M:%S')"
for env in "${ENV_VARS[@]}"; do
env_list="$env_list --from-literal=$env"
done
kubectl create configmap $CONFIG_MAP -n $NAMESPACE $env_list
fi

# Check whether the OBCluster exists
kubectl get obcluster $OB_CLUSTER -n $NAMESPACE &> /dev/null
if [[ $? -ne 0 ]]; then
Expand Down Expand Up @@ -204,9 +241,10 @@ metadata:
name: $DEPLOY_NAME
namespace: $NAMESPACE
labels:
obproxy.oceanbase.com/obproxy: "$DEPLOY_NAME"
obproxy.oceanbase.com/obproxy-from-setup: "$DEPLOY_NAME"
obproxy.oceanbase.com/for-obcluster: "$OB_CLUSTER"
obproxy.oceanbase.com/for-namespace: "$NAMESPACE"
obproxy.oceanbase.com/with-config-map: "$CONFIG_MAP"
spec:
selector:
matchLabels:
Expand All @@ -225,6 +263,9 @@ spec:
name: "sql"
- containerPort: 2884
name: "prometheus"
envFrom:
- configMapRef:
name: $CONFIG_MAP
env:
- name: APP_NAME
value: $DEPLOY_NAME
Expand Down

0 comments on commit aca7a79

Please sign in to comment.