#!/bin/bash # Copyright 2014 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. proc echoOK { global TC := ''\e['' global RegB := ""$(TC)0m"" if test $1 -eq "0" { global Green := ""$(TC)32m"" echo -e "[$(Green)OK$(RegB)]" } else { global Red := ""$(TC)31m"" echo -e "[$(Red)FAIL$(RegB)]" echo "Check log file." exit 1 } } proc usage { echo "Usage options: [--logfile ]" } global logfile := '/dev/null' while [[ $# > 0 ]] { global key := $1 shift matchstr $key { -l|--logfile { global logfile := $1 if test $logfile == "" { usage exit 1 } shift } * { # unknown option usage exit 1 } } } global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/../.." cd $(KUBE_ROOT) echo All verbose output will be redirected to $logfile, use --logfile option to change. printf "Start the cluster with 2 nodes .. " export NUM_NODES=2 export KUBERNETES_PROVIDER=vagrant shell {cluster/kube-up.sh >>$logfile !2 > !1} || true echoOK $Status printf "Check if node-1 can reach kubernetes master .. " vagrant ssh node-1 -- ping -c 10 kubernetes-master >>$logfile !2 > !1 echoOK $Status printf "Check if node-2 can reach kubernetes master .. " vagrant ssh node-2 -- ping -c 10 kubernetes-master >>$logfile !2 > !1 echoOK $Status printf "Pull an image that runs a web server on node-1 .. " vagrant ssh node-1 -- 'sudo docker pull kubernetes/serve_hostname' >>$logfile !2 > !1 echoOK $Status printf "Pull an image that runs a web server on node-2 .. " vagrant ssh node-2 -- 'sudo docker pull kubernetes/serve_hostname' >>$logfile !2 > !1 echoOK $Status printf "Run the server on node-1 .. " vagrant ssh node-1 -- sudo docker run -d kubernetes/serve_hostname >>$logfile !2 > !1 echoOK $Status printf "Run the server on node-2 .. " vagrant ssh node-2 -- sudo docker run -d kubernetes/serve_hostname >>$logfile !2 > !1 echoOK $Status printf "Run ping from node-1 to docker bridges and to the containers on both nodes .. " vagrant ssh node-1 -- 'ping -c 20 10.246.0.1 && ping -c 20 10.246.1.1 && ping -c 20 10.246.0.2 && ping -c 20 10.246.1.2' >>$logfile !2 > !1 echoOK $Status printf "Same pinch from node-2 .. " vagrant ssh node-2 -- 'ping -c 20 10.246.0.1 && ping -c 20 10.246.1.1 && ping -c 20 10.246.0.2 && ping -c 20 10.246.1.2' >>$logfile !2 > !1 echoOK $Status printf "tcp check, curl to both the running webservers from node-1 .. " vagrant ssh node-1 -- 'curl -sS 10.246.0.2:9376 && curl -sS 10.246.1.2:9376' >>$logfile !2 > !1 echoOK $Status printf "tcp check, curl to both the running webservers from node-2 .. " vagrant ssh node-2 -- 'curl -sS 10.246.0.2:9376 && curl -sS 10.246.1.2:9376' >>$logfile !2 > !1 echoOK $Status printf "All good, destroy the cluster .. " vagrant destroy -f >>$logfile !2 > !1 echoOK $Status (CommandList children: [ (FuncDef name: echoOK body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:TC) op:Equal rhs:{(SQ <"\\e[">)} spids:[51])] spids: [51] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:RegB) op: Equal rhs: {(DQ (${ VSub_Name TC) (0m))} spids: [57] ) ] spids: [57] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Number "$1"))} {(-eq)} {(DQ (0))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Green) op: Equal rhs: {(DQ (${ VSub_Name TC) (32m))} spids: [86] ) ] spids: [86] ) (C {(echo)} {(-e)} {(DQ ("[") (${ VSub_Name Green) (OK) (${ VSub_Name RegB) ("]"))}) ] spids: [-1 83] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Red) op: Equal rhs: {(DQ (${ VSub_Name TC) (31m))} spids: [115] ) ] spids: [115] ) (C {(echo)} {(-e)} {(DQ ("[") (${ VSub_Name Red) (FAIL) (${ VSub_Name RegB) ("]"))}) (C {(echo)} {(DQ ("Check log file."))}) (C {(exit)} {(1)}) ] spids: [112 153] ) ] spids: [48] ) spids: [44 47] ) (FuncDef name: usage body: (BraceGroup children: [(C {(echo)} {(DQ ("Usage options: [--logfile ]"))})] spids: [162] ) spids: [158 161] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:logfile) op:Equal rhs:{(/dev/null)} spids:[174])] spids: [174] ) (While cond: [ (Sentence child: (DBracket expr:(BoolBinary op_id:Redir_Great left:{($ VSub_Pound "$#")} right:{(0)})) terminator: ) ] body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:key) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [193] ) ] spids: [193] ) (C {(shift)}) (Case to_match: {($ VSub_Name "$key")} arms: [ (case_arm pat_list: [{(-l)} {(--logfile)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:logfile) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [215] ) ] spids: [215] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$logfile"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ )} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(usage)}) (C {(exit)} {(1)})] spids: [-1 238] ) ] spids: [-1 249] ) (C {(shift)}) ] spids: [209 212 255 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(C {(usage)}) (C {(exit)} {(1)})] spids: [258 259 274 -1] ) ] spids: [202 206 277] ) ] spids: [190 279] ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [283 291] ) (/../..) } spids: [282] ) ] spids: [282] ) (C {(cd)} {(DQ (${ VSub_Name KUBE_ROOT))}) (C {(echo)} {(All)} {(verbose)} {(output)} {(will)} {(be)} {(redirected)} {(to)} {($ VSub_Name "$logfile") (Lit_Comma ",")} {(use)} {(--logfile)} {(option)} {(to)} {(change.)} ) (C {(printf)} {(DQ ("Start the cluster with 2 nodes .. "))}) (C {(export)} {(Lit_VarLike "NUM_NODES=") (2)}) (C {(export)} {(Lit_VarLike "KUBERNETES_PROVIDER=") (vagrant)}) (AndOr children: [ (Subshell child: (SimpleCommand words: [{(cluster/kube-up.sh)}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(DQ ($ VSub_Name "$logfile"))} spids: [353] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[358]) ] ) spids: [350 360] ) (C {(true)}) ] op_id: Op_DPipe ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Check if node-1 can reach kubernetes master .. "))}) (SimpleCommand words: [{(vagrant)} {(ssh)} {(node-1)} {(--)} {(ping)} {(-c)} {(10)} {(kubernetes-master)}] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[393]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[398]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Check if node-2 can reach kubernetes master .. "))}) (SimpleCommand words: [{(vagrant)} {(ssh)} {(node-2)} {(--)} {(ping)} {(-c)} {(10)} {(kubernetes-master)}] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[427]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[432]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Pull an image that runs a web server on node-1 .. "))}) (SimpleCommand words: [{(vagrant)} {(ssh)} {(node-1)} {(--)} {(SQ <"sudo docker pull kubernetes/serve_hostname">)}] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[458]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[463]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Pull an image that runs a web server on node-2 .. "))}) (SimpleCommand words: [{(vagrant)} {(ssh)} {(node-2)} {(--)} {(SQ <"sudo docker pull kubernetes/serve_hostname">)}] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[488]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[493]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Run the server on node-1 .. "))}) (SimpleCommand words: [ {(vagrant)} {(ssh)} {(node-1)} {(--)} {(sudo)} {(docker)} {(run)} {(-d)} {(kubernetes/serve_hostname)} ] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[525]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[530]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Run the server on node-2 .. "))}) (SimpleCommand words: [ {(vagrant)} {(ssh)} {(node-2)} {(--)} {(sudo)} {(docker)} {(run)} {(-d)} {(kubernetes/serve_hostname)} ] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[561]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[566]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Run ping from node-1 to docker bridges and to the containers on both nodes .. "))} ) (SimpleCommand words: [ {(vagrant)} {(ssh)} {(node-1)} {(--)} { (SQ < "ping -c 20 10.246.0.1 && ping -c 20 10.246.1.1 && ping -c 20 10.246.0.2 && ping -c 20 10.246.1.2" > ) } ] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[592]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[597]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("Same pinch from node-2 .. "))}) (SimpleCommand words: [ {(vagrant)} {(ssh)} {(node-2)} {(--)} { (SQ < "ping -c 20 10.246.0.1 && ping -c 20 10.246.1.1 && ping -c 20 10.246.0.2 && ping -c 20 10.246.1.2" > ) } ] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[622]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[627]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("tcp check, curl to both the running webservers from node-1 .. "))}) (SimpleCommand words: [ {(vagrant)} {(ssh)} {(node-1)} {(--)} {(SQ <"curl -sS 10.246.0.2:9376 && curl -sS 10.246.1.2:9376">)} ] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[653]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[658]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("tcp check, curl to both the running webservers from node-2 .. "))}) (SimpleCommand words: [ {(vagrant)} {(ssh)} {(node-2)} {(--)} {(SQ <"curl -sS 10.246.0.2:9376 && curl -sS 10.246.1.2:9376">)} ] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[683]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[688]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) (C {(printf)} {(DQ ("All good, destroy the cluster .. "))}) (SimpleCommand words: [{(vagrant)} {(destroy)} {(-f)}] redirects: [ (Redir op_id:Redir_DGreat fd:-1 arg_word:{(DQ ($ VSub_Name "$logfile"))} spids:[708]) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[713]) ] ) (C {(echoOK)} {($ VSub_QMark "$?")}) ] )