#!/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. set -o errexit set -o nounset set -o pipefail # Set the host name explicitly # See: https://github.com/mitchellh/vagrant/issues/2430 hostnamectl set-hostname $(NODE_NAME) global if_to_edit := ''"" if [[ "$(grep 'VERSION_ID' /etc/os-release)" =~ ^VERSION_ID=23 ]] { # Disable network interface being managed by Network Manager (needed for Fedora 21+) global NETWORK_CONF_PATH := '/etc/sysconfig/network-scripts/' global if_to_edit := $[ find $(NETWORK_CONF_PATH)ifcfg-* | xargs grep -l VAGRANT-BEGIN] for if_conf in [$(if_to_edit)] { grep -q ^NM_CONTROLLED= $(if_conf) || echo 'NM_CONTROLLED=no' >> $(if_conf) sed -i 's/#^NM_CONTROLLED=.*/NM_CONTROLLED=no/' $(if_conf) }; systemctl restart network } # needed for vsphere support # handle the case when no 'VAGRANT-BEGIN' comment was defined in network-scripts # set the NETWORK_IF_NAME to have a default value in such case global NETWORK_IF_NAME := $[echo $(if_to_edit) | awk -F- '{ print $3 }] if [[ -z "$NETWORK_IF_NAME" ]] { global NETWORK_IF_NAME := $(DEFAULT_NETWORK_IF_NAME) } # Setup hosts file to support ping by hostname to master if test ! $[cat /etc/hosts | grep $MASTER_NAME] { echo "Adding $MASTER_NAME to hosts file" echo "$MASTER_IP $MASTER_NAME" >> /etc/hosts } echo "$NODE_IP $NODE_NAME" >> /etc/hosts # Setup hosts file to support ping by hostname to each node in the cluster for (( i=0; i<${#NODE_NAMES[@]}; i++)); do node=${NODE_NAMES[$i]} ip=${NODE_IPS[$i]} if [ ! "$(cat /etc/hosts | grep $node)" ]; then echo "Adding $node to hosts file" echo "$ip $node" >> /etc/hosts fi done enable-accounting prepare-package-manager # Configure network if test $(NETWORK_PROVIDER) != "kubenet" { provision-network-node } write-salt-config kubernetes-pool # Generate kubelet and kube-proxy auth file(kubeconfig) if there is not an existing one global known_kubeconfig_file := '"/srv/salt-overlay/salt/kubelet/kubeconfig'" if [[ ! -f "${known_kubeconfig_file}" ]] { create-salt-kubelet-auth create-salt-kubeproxy-auth } else { # stop kubelet, let salt start it later systemctl stop kubelet } install-salt add-volume-support run-salt dnf install -y socat ethtool dnf update -y docker (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (C {(hostnamectl)} {(set-hostname)} {(${ VSub_Name NODE_NAME)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:if_to_edit) op:Equal rhs:{(DQ )} spids:[77])] spids: [77] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_EqualTilde left: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(grep)} {(SQ )} {(/etc/os-release)})] ) left_token: spids: [87 95] ) ) } right: {(Lit_Other "^") (Lit_VarLike "VERSION_ID=") (23)} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NETWORK_CONF_PATH) op: Equal rhs: {(/etc/sysconfig/network-scripts/)} spids: [114] ) ] spids: [114] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:if_to_edit) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(find)} {(${ VSub_Name NETWORK_CONF_PATH) (ifcfg-) (Lit_Other "*")} ) (C {(xargs)} {(grep)} {(-l)} {(VAGRANT-BEGIN)}) ] negated: False ) ] ) left_token: spids: [119 139] ) } spids: [118] ) ] spids: [118] ) (Sentence child: (ForEach iter_name: if_conf iter_words: [{(${ VSub_Name if_to_edit)}] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (C {(grep)} {(-q)} {(Lit_Other "^") (Lit_VarLike "NM_CONTROLLED=")} {(${ VSub_Name if_conf)} ) (SimpleCommand words: [{(echo)} {(SQ <"NM_CONTROLLED=no">)}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(${ VSub_Name if_conf)} spids: [175] ) ] ) ] op_id: Op_DPipe ) (C {(sed)} {(-i)} {(SQ <"s/#^NM_CONTROLLED=.*/NM_CONTROLLED=no/">)} {(${ VSub_Name if_conf)} ) ] spids: [153 195] ) spids: [147 151] ) terminator: ) (C {(systemctl)} {(restart)} {(network)}) ] spids: [-1 107] ) ] spids: [-1 205] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NETWORK_IF_NAME) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(${ VSub_Name if_to_edit)}) (C {(awk)} {(-F-)} {(SQ <"{ print $3 }">)}) ] negated: False ) ] ) left_token: spids: [218 234] ) } spids: [217] ) ] spids: [217] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{(DQ ($ VSub_Name "$NETWORK_IF_NAME"))}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NETWORK_IF_NAME) op: Equal rhs: {(${ VSub_Name DEFAULT_NETWORK_IF_NAME)} spids: [252] ) ] spids: [252] ) ] spids: [-1 249] ) ] spids: [-1 257] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(cat)} {(/etc/hosts)}) (C {(grep)} {($ VSub_Name "$MASTER_NAME")}) ] negated: False ) ] ) left_token: spids: [270 280] ) ) } {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Adding ") ($ VSub_Name "$MASTER_NAME") (" to hosts file"))}) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$MASTER_IP") (" ") ($ VSub_Name "$MASTER_NAME"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(/etc/hosts)} spids:[306])] ) ] spids: [-1 286] ) ] spids: [-1 310] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$NODE_IP") (" ") ($ VSub_Name "$NODE_NAME"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(/etc/hosts)} spids:[320])] ) (ForExpr init: (BinaryAssign op_id:Arith_Equal left:(LhsName name:i) right:(ArithWord w:{(Lit_Digits 0)})) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:i) right: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound bracket_op: (WholeArray op_id:Lit_At) spids: [339 345] ) } ) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:i)) body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:node) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [358 363] ) } spids: [357] ) ] spids: [357] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ip) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [367 372] ) } spids: [366] ) ] spids: [366] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(cat)} {(/etc/hosts)}) (C {(grep)} {($ VSub_Name "$node")}) ] negated: False ) ] ) left_token: spids: [382 392] ) ) } {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Adding ") ($ VSub_Name "$node") (" to hosts file"))}) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$ip") (" ") ($ VSub_Name "$node"))}] redirects: [ (Redir op_id: Redir_DGreat fd: -1 arg_word: {(/etc/hosts)} spids: [418] ) ] ) ] spids: [-1 398] ) ] spids: [-1 423] ) ] spids: [354 425] ) ) (C {(enable-accounting)}) (C {(prepare-package-manager)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ (${ VSub_Name NETWORK_PROVIDER))} {(KW_Bang "!") (Lit_Other "=")} {(DQ (kubenet))} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(provision-network-node)})] spids: [-1 456] ) ] spids: [-1 461] ) (C {(write-salt-config)} {(kubernetes-pool)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:known_kubeconfig_file) op: Equal rhs: {(DQ (/srv/salt-overlay/salt/kubelet/kubeconfig))} spids: [472] ) ] spids: [472] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_f child: {(DQ (${ VSub_Name known_kubeconfig_file))} ) ) ) terminator: ) ] action: [(C {(create-salt-kubelet-auth)}) (C {(create-salt-kubeproxy-auth)})] spids: [-1 494] ) ] else_action: [(C {(systemctl)} {(stop)} {(kubelet)})] spids: [502 515] ) (C {(install-salt)}) (C {(add-volume-support)}) (C {(run-salt)}) (C {(dnf)} {(install)} {(-y)} {(socat)} {(ethtool)}) (C {(dnf)} {(update)} {(-y)} {(docker)}) ] )