Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts support args #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 185 additions & 32 deletions cmd/init/init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/sh
##!/usr/bin/env bash
# ======================================================================
# Linux/OSX startup script
# ======================================================================

# Copyright 2022, OpenSergo Authors
#
Expand All @@ -17,38 +21,187 @@

# Prepare Env
# OPENSERGO_CONTROL_PLANE_HOME
OPENSERGO_CONTROL_PLANE_HOME=$HOME/opensergo/opensergo-control-plane
OPENSERGO_CONTROL_PLANE_HOME=$HOME/.opensergo.install/opensergo-control-plane
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME

# Exec Command Args
VERSION=main
IS_LOCAL=false
IS_UNINSTALL=false
IS_HELP=false

# Uninstall rbac.yaml
kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/rbac/rbac.yaml
# Uninstall Namespace
kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/namespace.yaml
# Uninstall CRDs
kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases

# Download CRDs ./k8s/crd/bases
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases/fault-tolerance.opensergo.io_circuitbreakerstrategies.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/crd/bases/fault-tolerance.opensergo.io_circuitbreakerstrategies.yaml
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases/fault-tolerance.opensergo.io_concurrencylimitstrategies.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/crd/bases/fault-tolerance.opensergo.io_concurrencylimitstrategies.yaml
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases/fault-tolerance.opensergo.io_faulttolerancerules.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/crd/bases/fault-tolerance.opensergo.io_faulttolerancerules.yaml
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases/fault-tolerance.opensergo.io_ratelimitstrategies.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/crd/bases/fault-tolerance.opensergo.io_ratelimitstrategies.yaml
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases/fault-tolerance.opensergo.io_throttlingstrategies.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/crd/bases/fault-tolerance.opensergo.io_throttlingstrategies.yaml
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases/traffic.opensergo.io_trafficerouters.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/crd/bases/traffic.opensergo.io_trafficerouters.yaml
# Install CRDs
kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/crd/bases


# Download Namespace
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/k8s
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/namespace.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/namespace.yaml
# Install Namespace
kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/namespace.yaml


# Download rbac.yaml
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/k8s/rbac
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/rbac/rbac.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/rbac/rbac.yaml
# Install rbac.yaml
kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/rbac/rbac.yaml
# Init Var, which will change by parseArgs()
DOWNLOAD_TARGET_URL_PREFIX=$OPENSERGO_CONTROL_PLANE_HOME/main
DOWNLOAD_SOURCE_URL_PREFIX=$RESOURCE_URL_PREFIX/main

# parse exec command args
allArgs=($*)
for (( i = 1; i <= $#; i++ )); do
currArg=${allArgs[$i-1]}
case $currArg in
"-h" | "-help")
IS_HELP=true
;;
"-l" | "-local")
IS_LOCAL=true
;;
"-u" | "-uninstall")
IS_LOCAL=true
;;
esac

if [ $i = $# ] ; then
if [ "-" != ${currArg:0:1} ]; then
VERSION=$currArg
fi
fi
done



function parseVersion() {
# RESOURCE_URL
resource_url_prefix=https://raw.githubusercontent.com/opensergo/opensergo-control-plane
resource_url_version=$VERSION

# parse VERSION_URL
if [ "main" != $VERSION ] ; then
resource_url_version=tree/$VERSION
fi

DOWNLOAD_TARGET_URL_PREFIX=$OPENSERGO_CONTROL_PLANE_HOME/$VERSION
DOWNLOAD_SOURCE_URL_PREFIX=$resource_url_prefix/$resource_url_version
}

# invoke parseArgs()
parseVersion

# Resources in k8s/crd/bases
res_crd[0]=k8s/crd/bases/fault-tolerance.opensergo.io_circuitbreakerstrategies.yaml
res_crd[1]=k8s/crd/bases/fault-tolerance.opensergo.io_concurrencylimitstrategies.yaml
res_crd[2]=k8s/crd/bases/fault-tolerance.opensergo.io_faulttolerancerules.yaml
res_crd[3]=k8s/crd/bases/fault-tolerance.opensergo.io_ratelimitstrategies.yaml
res_crd[4]=k8s/crd/bases/fault-tolerance.opensergo.io_throttlingstrategies.yaml
res_crd[5]=k8s/crd/bases/traffic.opensergo.io_trafficerouters.yaml

function download_CRD() {
rm -rf $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s/crd/bases/*
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s/crd/bases

for crd in ${res_crd[*]}
do
wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX/$crd $DOWNLOAD_SOURCE_URL_PREFIX/$crd
done
}

function install_crd() {
for crd in ${res_crd[*]}
do
kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX/$crd
done
}

function uninstall_crd() {
for crd in ${res_crd[*]}
do
kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX/$crd
done
}

# Resources in k8s
res_namespace[0]=k8s/namespace.yaml

function download_Namespace() {
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s

for namespace in ${res_namespace[*]}
do
wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX/$namespace $DOWNLOAD_SOURCE_URL_PREFIX/$namespace
done
}

function install_namespace() {
for namespace in ${res_namespace[*]}
do
kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX/$namespace
done
}

function uninstall_namespace() {
for namespace in ${res_namespace[*]}
do
kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX/$namespace
done
}

# Resources in k8s/rbac
res_rbac[0]=k8s/rbac/rbac.yaml

function download_RBAC() {
rm -rf $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s/rbac/*
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s/rbac

for rbac in ${res_rbac[*]}
do
wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX/$rbac $DOWNLOAD_SOURCE_URL_PREFIX/$rbac
done
}

function install_rbac() {
for rbac in ${res_rbac[*]}
do
kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX/$rbac
done
}

function uninstall_rbac() {
for rbac in ${res_rbac[*]}
do
kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX/$rbac
done
}

function download() {
download_CRD
download_Namespace
download_RBAC
}

function uninstall() {
uninstall_rbac
uninstall_namespace
uninstall_crd
}

function install() {
# invoke uninstall
uninstall
# download or not
if [ true != $IS_LOCAL ]; then
download
fi
# invoke install
install_crd
install_namespace
install_rbac
}


function usage() {
echo "Usage: init.sh [-Option] [version]"
echo "Resources will download in $OPENSERGO_CONTROL_PLANE_HOME"
echo ""
echo "Available Options:"
echo " -l, -local : exec from local resources, which will not download resources"
echo " -u, -uninstall : uninstall CRDs, Namespace, RBAC of opensergo control plane"
echo " -h, -help : helps"
echo "version: : default version is main"
}

if [ true = $IS_HELP ] ; then
usage
elif [ true = $IS_UNINSTALL ] ; then
uninstall
else
install
fi
120 changes: 112 additions & 8 deletions cmd/install/k8s/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/sh
##!/usr/bin/env bash
# ======================================================================
# Linux/OSX startup script
# ======================================================================

# Copyright 2022, OpenSergo Authors
#
Expand All @@ -17,15 +21,115 @@

# Prepare Env
# OPENSERGO_CONTROL_PLANE_HOME
OPENSERGO_CONTROL_PLANE_HOME=$HOME/opensergo/opensergo-control-plane
OPENSERGO_CONTROL_PLANE_HOME=$HOME/.opensergo.install/opensergo-control-plane
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME

# Exec Command Args
VERSION=main
IS_LOCAL=false
IS_UNINSTALL=false
IS_HELP=false

# Uninstall opensergo-control-plane.yaml
kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/workload/opensergo-control-plane.yaml
# Init Var, which will change by parseArgs()
DOWNLOAD_TARGET_URL_PREFIX=$OPENSERGO_CONTROL_PLANE_HOME/main
DOWNLOAD_SOURCE_URL_PREFIX=$RESOURCE_URL_PREFIX/main

# Download opensergo-control-plane.yaml
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/k8s/workload
wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME/k8s/workload/opensergo-control-plane.yaml https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/workload/opensergo-control-plane.yaml
# Install opensergo-control-plane.yaml
kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME/k8s/workload/opensergo-control-plane.yaml
# parse exec command args
allArgs=($*)
for (( i = 1; i <= $#; i++ )); do
currArg=${allArgs[$i-1]}
case $currArg in
"-h" | "-help")
IS_HELP=true
;;
"-l" | "-local")
IS_LOCAL=true
;;
"-u" | "-uninstall")
IS_LOCAL=true
;;
esac

if [ $i = $# ] ; then
if [ "-" != ${currArg:0:1} ]; then
VERSION=$currArg
fi
fi
done



function parseVersion() {
# RESOURCE_URL
resource_url_prefix=https://raw.githubusercontent.com/opensergo/opensergo-control-plane
resource_url_version=$VERSION

# parse VERSION_URL
if [ "main" != $VERSION ] ; then
resource_url_version=tree/$VERSION
fi

DOWNLOAD_TARGET_URL_PREFIX=$OPENSERGO_CONTROL_PLANE_HOME/$VERSION
DOWNLOAD_SOURCE_URL_PREFIX=$resource_url_prefix/$resource_url_version
}

# invoke parseArgs()
parseVersion

# Resources in k8s/workload
res_deploy[0]=k8s/workload/opensergo-control-plane.yaml

function download_workload() {
rm -rf $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s/workload/*
mkdir -p $OPENSERGO_CONTROL_PLANE_HOME/$VERSION/k8s/workload

for crd in ${res_deploy[*]}
do
wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX/$crd $DOWNLOAD_SOURCE_URL_PREFIX/$crd
done
}

function install_workload() {
for crd in ${res_deploy[*]}
do
kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX/$crd
done
}

function uninstall_workload() {
for crd in ${res_deploy[*]}
do
kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX/$crd
done
}

function install() {
# invoke uninstall
uninstall_workload
# download or not
if [ true != $IS_LOCAL ]; then
download_workload
fi
# invoke install
install_workload
}


function usage() {
echo "Usage: deploy.sh [-Option] [version]"
echo "Resources will download in $OPENSERGO_CONTROL_PLANE_HOME"
echo ""
echo "Available Options:"
echo " -l, -local : exec from local resources, which will not download resources"
echo " -u, -uninstall : uninstall Workload of opensergo control plane"
echo " -h, -help : helps"
echo "version: : default version is main"
}

if [ true = $IS_HELP ] ; then
usage
elif [ true = $IS_UNINSTALL ] ; then
uninstall
else
install
fi