#!/bin/bash # Copyright 2015 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. # deploy the add-on services after the cluster is available set -e global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/../.." source "config-default.sh" global KUBECTL := ""$(KUBE_ROOT)/cluster/kubectl.sh"" export KUBECTL_PATH="$(KUBE_ROOT)/cluster/centos/binaries/kubectl" export KUBE_CONFIG_FILE=$(KUBE_CONFIG_FILE:-${KUBE_ROOT}/cluster/centos/config-default.sh) proc deploy_dns { echo "Deploying DNS on Kubernetes" cp "$(KUBE_ROOT)/cluster/addons/dns/kube-dns.yaml.sed" kube-dns.yaml sed -i -e "s/\\\$DNS_DOMAIN/$(DNS_DOMAIN)/g" kube-dns.yaml sed -i -e "s/\\\$DNS_SERVER_IP/$(DNS_SERVER_IP)/g" kube-dns.yaml global KUBEDNS := $[eval "$(KUBECTL) get services --namespace=kube-system | grep kube-dns | cat] if test ! $KUBEDNS { # use kubectl to create kube-dns addon $(KUBECTL) --namespace=kube-system create -f kube-dns.yaml echo "Kube-dns addon is successfully deployed." } else { echo "Kube-dns addon is already deployed. Skipping." } echo } proc deploy_dashboard { if $(KUBECTL) get rc -l k8s-app=kubernetes-dashboard --namespace=kube-system | grep kubernetes-dashboard-v &> /dev/null; { echo "Kubernetes Dashboard replicationController already exists" } else { echo "Creating Kubernetes Dashboard replicationController" $(KUBECTL) create -f $(KUBE_ROOT)/cluster/addons/dashboard/dashboard-controller.yaml } if $(KUBECTL) get service/kubernetes-dashboard --namespace=kube-system &> /dev/null; { echo "Kubernetes Dashboard service already exists" } else { echo "Creating Kubernetes Dashboard service" $(KUBECTL) create -f $(KUBE_ROOT)/cluster/addons/dashboard/dashboard-service.yaml } echo } if test $(ENABLE_CLUSTER_DNS) == true { deploy_dns } if test $(ENABLE_CLUSTER_UI) == true { deploy_dashboard } (CommandList children: [ (C {(set)} {(-e)}) (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: [54 62] ) (/../..) } spids: [53] ) ] spids: [53] ) (C {(source)} {(DQ (config-default.sh))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBECTL) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/kubectl.sh))} spids: [71] ) ] spids: [71] ) (C {(export)} {(Lit_VarLike "KUBECTL_PATH=") (DQ (${ VSub_Name KUBE_ROOT) (/cluster/centos/binaries/kubectl))} ) (C {(export)} {(Lit_VarLike "KUBE_CONFIG_FILE=") (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {(${ VSub_Name KUBE_ROOT) (Lit_Slash /) (cluster) (Lit_Slash /) (centos) (Lit_Slash /) (config-default.sh) } ) spids: [92 104] ) } ) (FuncDef name: deploy_dns body: (BraceGroup children: [ (C {(echo)} {(DQ ("Deploying DNS on Kubernetes"))}) (C {(cp)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/addons/dns/kube-dns.yaml.sed))} {(kube-dns.yaml)} ) (C {(sed)} {(-i)} {(-e)} { (DQ (s/) (EscapedLiteralPart token:) (EscapedLiteralPart token:) (DNS_DOMAIN/) (${ VSub_Name DNS_DOMAIN) (/g) ) } {(kube-dns.yaml)} ) (C {(sed)} {(-i)} {(-e)} { (DQ (s/) (EscapedLiteralPart token:) (EscapedLiteralPart token:) (DNS_SERVER_IP/) (${ VSub_Name DNS_SERVER_IP) (/g) ) } {(kube-dns.yaml)} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBEDNS) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(eval)} { (DQ (${ VSub_Name KUBECTL) (" get services --namespace=kube-system | grep kube-dns | cat") ) } ) ] ) left_token: spids: [175 184] ) } spids: [174] ) ] spids: [174] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(DQ ($ VSub_Name "$KUBEDNS"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(${ VSub_Name KUBECTL)} {(--namespace) (Lit_Other "=") (kube-system)} {(create)} {(-f)} {(kube-dns.yaml)} ) (C {(echo)} {(DQ ("Kube-dns addon is successfully deployed."))}) ] spids: [-1 202] ) ] else_action: [(C {(echo)} {(DQ ("Kube-dns addon is already deployed. Skipping."))})] spids: [232 242] ) (C {(echo)}) ] spids: [111] ) spids: [107 110] ) (FuncDef name: deploy_dashboard body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(${ VSub_Name KUBECTL)} {(get)} {(rc)} {(-l)} {(k8s-app) (Lit_Other "=") (kubernetes-dashboard)} {(--namespace) (Lit_Other "=") (kube-system)} ) (C {(grep)} {(kubernetes-dashboard-v)}) ] negated: False ) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [285] ) ] ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Kubernetes Dashboard replicationController already exists"))}) ] spids: [-1 290] ) ] else_action: [ (C {(echo)} {(DQ ("Creating Kubernetes Dashboard replicationController"))}) (C {(${ VSub_Name KUBECTL)} {(create)} {(-f)} {(${ VSub_Name KUBE_ROOT) (/cluster/addons/dashboard/dashboard-controller.yaml)} ) ] spids: [300 324] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(${ VSub_Name KUBECTL)} {(get)} {(service/kubernetes-dashboard)} {(--namespace) (Lit_Other "=") (kube-system)} ) terminator: ) (Sentence child: (SimpleCommand redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [343] ) ] ) terminator: ) ] action: [(C {(echo)} {(DQ ("Kubernetes Dashboard service already exists"))})] spids: [-1 348] ) ] else_action: [ (C {(echo)} {(DQ ("Creating Kubernetes Dashboard service"))}) (C {(${ VSub_Name KUBECTL)} {(create)} {(-f)} {(${ VSub_Name KUBE_ROOT) (/cluster/addons/dashboard/dashboard-service.yaml)} ) ] spids: [358 382] ) (C {(echo)}) ] spids: [255] ) spids: [251 254] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ (${ VSub_Name ENABLE_CLUSTER_DNS))} {(Lit_Other "=") (Lit_Other "=")} {(true)} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(deploy_dns)})] spids: [-1 410] ) ] spids: [-1 415] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ (${ VSub_Name ENABLE_CLUSTER_UI))} {(Lit_Other "=") (Lit_Other "=")} {(true)} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(deploy_dashboard)})] spids: [-1 436] ) ] spids: [-1 441] ) ] )