14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
- cd $( dirname ${BASH_SOURCE} )
18
- . ./udemo.sh
19
- . ../scripts/util.sh
17
+ # Resolve the absolute path to this script directory.
18
+ cd $( dirname " ${BASH_SOURCE[0]} " )
19
+ demo_dir=$( realpath " $( pwd) " )
20
+ scripts_dir=$( realpath " $( pwd) /../scripts" )
21
+
22
+ . " ${demo_dir} /udemo.sh"
23
+ . " ${scripts_dir} /util.sh"
20
24
21
25
DEMO_AUTO_RUN=true
22
26
23
- kubeconfig1=${KUBECONFIG1:- .. / scripts / c1.kubeconfig}
24
- kubeconfig2=${KUBECONFIG2:- .. / scripts / c2.kubeconfig}
27
+ kubeconfig1=" ${KUBECONFIG1:- ${scripts_dir} / c1.kubeconfig} "
28
+ kubeconfig2=" ${KUBECONFIG2:- ${scripts_dir} / c2.kubeconfig} "
25
29
26
30
k1=" kubectl --kubeconfig ${kubeconfig1} "
27
31
k2=" kubectl --kubeconfig ${kubeconfig2} "
@@ -30,33 +34,33 @@ desc "Setup our demo namespace"
30
34
run " ${k1} create ns demo"
31
35
run " ${k2} create ns demo"
32
36
33
- c1_pane=` tmux split-window -h -d -P`
37
+ c1_pane=$( tmux split-window -h -d -P)
34
38
35
39
function cleanup() {
36
- tmux kill-pane -t $c1_pane
40
+ tmux kill-pane -t " $c1_pane "
37
41
}
38
42
trap cleanup EXIT
39
43
40
- tmux send -t $c1_pane " ${k1} logs -f mcs-api-controller" Enter
44
+ tmux send -t " $c1_pane " " ${k1} logs -f mcs-api-controller" Enter
41
45
42
46
desc " Create our service in each cluster"
43
- run " ${k1} apply -f yaml/dep1.yaml -f yaml/svc.yaml"
44
- run " ${k2} apply -f yaml/dep2.yaml -f yaml/svc.yaml"
47
+ run " ${k1} apply -f ${script_dir} / yaml/dep1.yaml -f ${script_dir} / yaml/svc.yaml"
48
+ run " ${k2} apply -f ${script_dir} / yaml/dep2.yaml -f ${script_dir} / yaml/svc.yaml"
45
49
run " ${k1} get endpointslice -n demo"
46
50
47
-
48
51
desc " Lets look at some requests to the service in cluster 1"
49
52
run " ${k1} -n demo run -i --rm --restart=Never --image=jeremyot/request:0a40de8 request -- --duration=5s --address=serve.demo.svc.cluster.local"
50
53
51
54
desc " Ok, looks normal. Let's import the service from our other cluster"
52
55
ep_1=$( ${k1} get endpointslice -n demo -l ' kubernetes.io/service-name=serve' --template=" {{(index .items 0).metadata.name}}" )
53
56
ep_2=$( ${k2} get endpointslice -n demo -l ' kubernetes.io/service-name=serve' --template=" {{(index .items 0).metadata.name}}" )
54
- run " ${k1} get endpointslice -n demo ${ep_1} -o yaml | ./edit-meta --metadata '{name: imported-${ep_1} , namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > yaml/slice-1.tmp"
55
- run " ${k2} get endpointslice -n demo ${ep_2} -o yaml | ./edit-meta --metadata '{name: imported-${ep_2} , namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > yaml/slice-2.tmp"
56
- run " ${k1} apply -f yaml/serviceimport.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
57
- run " ${k2} apply -f yaml/serviceimport.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
58
- run " ${k1} apply -f yaml/serviceimport-with-vip.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
59
- run " ${k2} apply -f yaml/serviceimport-with-vip.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
57
+
58
+ run " ${k1} get endpointslice -n demo ${ep_1} -o yaml | ${script_dir} /edit-meta --metadata '{name: imported-${ep_1} , namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > ${script_dir} /yaml/slice-1.tmp"
59
+ run " ${k2} get endpointslice -n demo ${ep_2} -o yaml | ${script_dir} /edit-meta --metadata '{name: imported-${ep_2} , namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > ${script_dir} /yaml/slice-2.tmp"
60
+ run " ${k1} apply -f ${script_dir} /yaml/serviceimport.yaml -f ${script_dir} /yaml/slice-1.tmp -f ${script_dir} /yaml/slice-2.tmp"
61
+ run " ${k2} apply -f ${script_dir} /yaml/serviceimport.yaml -f ${script_dir} /yaml/slice-1.tmp -f ${script_dir} /yaml/slice-2.tmp"
62
+ run " ${k1} apply -f ${script_dir} /yaml/serviceimport-with-vip.yaml -f ${script_dir} /yaml/slice-1.tmp -f ${script_dir} /yaml/slice-2.tmp"
63
+ run " ${k2} apply -f ${script_dir} /yaml/serviceimport-with-vip.yaml -f ${script_dir} /yaml/slice-1.tmp -f ${script_dir} /yaml/slice-2.tmp"
60
64
61
65
desc " See what we've created..."
62
66
run " ${k1} get -n demo serviceimports"
@@ -70,7 +74,7 @@ function import_ip() {
70
74
waitfor import_ip
71
75
72
76
vip=$( ${k1} get serviceimport -n demo -o go-template --template=' {{index (index .items 0).spec.ips 0}}' )
73
- desc " Now grap the multi-cluster VIP from the serviceimport..."
77
+ desc " Now grab the multi-cluster VIP from the serviceimport..."
74
78
run " ${k1} get serviceimport -n demo -o go-template --template='{{index (index .items 0).spec.ips 0}}{{\" \n\" }}'"
75
79
desc " ...and connect to it"
76
80
run " ${k1} -n demo run -i --rm --restart=Never --image=jeremyot/request:0a40de8 request -- --duration=10s --address=${vip} "
0 commit comments