11#! /bin/sh
2+ # #!/usr/bin/env bash
3+ #  ======================================================================
4+ #  Linux/OSX startup script
5+ #  ======================================================================
26
37#  Copyright 2022, OpenSergo Authors
48# 
1721
1822#  Prepare Env
1923#  OPENSERGO_CONTROL_PLANE_HOME
20- OPENSERGO_CONTROL_PLANE_HOME=$HOME /opensergo/opensergo-control-plane
24+ OPENSERGO_CONTROL_PLANE_HOME=$HOME /. opensergo.install /opensergo-control-plane
2125mkdir -p $OPENSERGO_CONTROL_PLANE_HOME 
2226
27+ #  Exec Command Args
28+ VERSION=main
29+ IS_LOCAL=false
30+ IS_UNINSTALL=false
31+ IS_HELP=false
2332
24- #  Uninstall rbac.yaml
25- kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME /k8s/rbac/rbac.yaml
26- #  Uninstall Namespace
27- kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME /k8s/namespace.yaml
28- #  Uninstall CRDs
29- kubectl delete -f $OPENSERGO_CONTROL_PLANE_HOME /k8s/crd/bases
30- 
31- #  Download CRDs ./k8s/crd/bases
32- mkdir -p $OPENSERGO_CONTROL_PLANE_HOME /k8s/crd/bases
33- 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
34- 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
35- 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
36- 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
37- 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
38- 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
39- #  Install CRDs
40- kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME /k8s/crd/bases
41- 
42- 
43- #  Download Namespace
44- mkdir -p $OPENSERGO_CONTROL_PLANE_HOME /k8s
45- wget --no-check-certificate -O $OPENSERGO_CONTROL_PLANE_HOME /k8s/namespace.yaml  https://raw.githubusercontent.com/opensergo/opensergo-control-plane/main/k8s/namespace.yaml
46- #  Install Namespace
47- kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME /k8s/namespace.yaml
48- 
49- 
50- #  Download rbac.yaml
51- mkdir -p $OPENSERGO_CONTROL_PLANE_HOME /k8s/rbac
52- 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
53- #  Install rbac.yaml
54- kubectl apply -f $OPENSERGO_CONTROL_PLANE_HOME /k8s/rbac/rbac.yaml
33+ #  Init Var, which will change by parseArgs()
34+ DOWNLOAD_TARGET_URL_PREFIX=$OPENSERGO_CONTROL_PLANE_HOME /main
35+ DOWNLOAD_SOURCE_URL_PREFIX=$RESOURCE_URL_PREFIX /main
36+ 
37+ #  parse exec command args
38+ allArgs=($* )
39+ for  ((  i =  1 ; i <=  $# ; i++  )) ;  do 
40+   currArg=${allArgs[$i-1]} 
41+   case  $currArg  in 
42+       " -h" " -help" 
43+         IS_HELP=true
44+         ;;
45+       " -l" " -local" 
46+         IS_LOCAL=true
47+         ;;
48+       " -u" " -uninstall" 
49+         IS_LOCAL=true
50+         ;;
51+     esac 
52+ 
53+   if  [ $i  =  $#  ] ;  then 
54+     if  [ " -" !=  ${currArg: 0: 1}  ];  then 
55+       VERSION=$currArg 
56+     fi 
57+   fi 
58+ done 
59+ 
60+ 
61+ 
62+ function  parseVersion()  {
63+   #  RESOURCE_URL
64+   resource_url_prefix=https://raw.githubusercontent.com/opensergo/opensergo-control-plane
65+   resource_url_version=$VERSION 
66+ 
67+   #  parse VERSION_URL
68+   if  [ " main" !=  $VERSION  ] ;  then 
69+     resource_url_version=tree/$VERSION 
70+   fi 
71+ 
72+   DOWNLOAD_TARGET_URL_PREFIX=$OPENSERGO_CONTROL_PLANE_HOME /$VERSION 
73+   DOWNLOAD_SOURCE_URL_PREFIX=$resource_url_prefix /$resource_url_version 
74+ }
75+ 
76+ #  invoke parseArgs()
77+ parseVersion
78+ 
79+ #  Resources in k8s/crd/bases
80+ res_crd[0]=k8s/crd/bases/fault-tolerance.opensergo.io_circuitbreakerstrategies.yaml
81+ res_crd[1]=k8s/crd/bases/fault-tolerance.opensergo.io_concurrencylimitstrategies.yaml
82+ res_crd[2]=k8s/crd/bases/fault-tolerance.opensergo.io_faulttolerancerules.yaml
83+ res_crd[3]=k8s/crd/bases/fault-tolerance.opensergo.io_ratelimitstrategies.yaml
84+ res_crd[4]=k8s/crd/bases/fault-tolerance.opensergo.io_throttlingstrategies.yaml
85+ res_crd[5]=k8s/crd/bases/traffic.opensergo.io_trafficerouters.yaml
86+ 
87+ function  download_CRD()  {
88+   rm -rf $OPENSERGO_CONTROL_PLANE_HOME /$VERSION /k8s/crd/bases/* 
89+   mkdir -p $OPENSERGO_CONTROL_PLANE_HOME /$VERSION /k8s/crd/bases
90+ 
91+   for  crd  in  ${res_crd[*]} 
92+   do 
93+     wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX /$crd  $DOWNLOAD_SOURCE_URL_PREFIX /$crd 
94+   done 
95+ }
96+ 
97+ function  install_crd()  {
98+   for  crd  in  ${res_crd[*]} 
99+   do 
100+     kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX /$crd 
101+   done 
102+ }
103+ 
104+ function  uninstall_crd()  {
105+   for  crd  in  ${res_crd[*]} 
106+   do 
107+     kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX /$crd 
108+   done 
109+ }
110+ 
111+ #  Resources in k8s
112+ res_namespace[0]=k8s/namespace.yaml
113+ 
114+ function  download_Namespace()  {
115+   mkdir -p $OPENSERGO_CONTROL_PLANE_HOME /$VERSION /k8s
116+ 
117+   for  namespace  in  ${res_namespace[*]} 
118+   do 
119+     wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX /$namespace  $DOWNLOAD_SOURCE_URL_PREFIX /$namespace 
120+   done 
121+ }
122+ 
123+ function  install_namespace()  {
124+   for  namespace  in  ${res_namespace[*]} 
125+   do 
126+     kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX /$namespace 
127+   done 
128+ }
129+ 
130+ function  uninstall_namespace()  {
131+   for  namespace  in  ${res_namespace[*]} 
132+   do 
133+     kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX /$namespace 
134+   done 
135+ }
136+ 
137+ #  Resources in k8s/rbac
138+ res_rbac[0]=k8s/rbac/rbac.yaml
139+ 
140+ function  download_RBAC()  {
141+   rm -rf $OPENSERGO_CONTROL_PLANE_HOME /$VERSION /k8s/rbac/* 
142+   mkdir -p $OPENSERGO_CONTROL_PLANE_HOME /$VERSION /k8s/rbac
143+ 
144+   for  rbac  in  ${res_rbac[*]} 
145+   do 
146+     wget --no-check-certificate -O $DOWNLOAD_TARGET_URL_PREFIX /$rbac  $DOWNLOAD_SOURCE_URL_PREFIX /$rbac 
147+   done 
148+ }
149+ 
150+ function  install_rbac()  {
151+   for  rbac  in  ${res_rbac[*]} 
152+   do 
153+     kubectl apply -f $DOWNLOAD_TARGET_URL_PREFIX /$rbac 
154+   done 
155+ }
156+ 
157+ function  uninstall_rbac()  {
158+   for  rbac  in  ${res_rbac[*]} 
159+   do 
160+     kubectl delete -f $DOWNLOAD_TARGET_URL_PREFIX /$rbac 
161+   done 
162+ }
163+ 
164+ function  download()  {
165+     download_CRD
166+     download_Namespace
167+     download_RBAC
168+ }
169+ 
170+ function  uninstall()  {
171+     uninstall_rbac
172+     uninstall_namespace
173+     uninstall_crd
174+ }
175+ 
176+ function  install()  {
177+   #  invoke uninstall
178+   uninstall
179+   #  download or not
180+   if  [ true  !=  $IS_LOCAL  ];  then 
181+     download
182+   fi 
183+   #  invoke install
184+   install_crd
185+   install_namespace
186+   install_rbac
187+ }
188+ 
189+ 
190+ function  usage()  {
191+   echo  " Usage:  init.sh [-Option] [version]" 
192+   echo  " Resources will download in $OPENSERGO_CONTROL_PLANE_HOME " 
193+   echo  " " 
194+   echo  " Available Options:" 
195+   echo  "   -l, -local         : exec from local resources, which will not download resources" 
196+   echo  "   -u, -uninstall     : uninstall CRDs, Namespace, RBAC of opensergo control plane" 
197+   echo  "   -h, -help          : helps" 
198+   echo  " version:             : default version is main" 
199+ }
200+ 
201+ if  [ true  =  $IS_HELP  ] ;  then 
202+   usage
203+ elif  [ true  =  $IS_UNINSTALL  ] ;  then 
204+   uninstall
205+ else 
206+   install
207+ fi 
0 commit comments