sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/cloudinit/controlplane_init.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cloudinit 18 19 import ( 20 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/internal/cluster" 21 ) 22 23 const ( 24 controlPlaneCloudInit = `{{.Header}} 25 {{template "files" .WriteFiles}} 26 - path: /tmp/kubeadm.yaml 27 owner: root:root 28 permissions: '0640' 29 content: | 30 --- 31 {{.ClusterConfiguration | Indent 6}} 32 --- 33 {{.InitConfiguration | Indent 6}} 34 runcmd: 35 {{- template "commands" .PreKubeadmCommands }} 36 - 'kubeadm init --config /tmp/kubeadm.yaml' 37 {{- template "commands" .PostKubeadmCommands }} 38 {{- template "ntp" .NTP }} 39 {{- template "users" .Users }} 40 ` 41 ) 42 43 // ControlPlaneInput defines the context to generate a controlplane instance user data. 44 type ControlPlaneInput struct { 45 BaseUserData 46 cluster.Certificates 47 48 ClusterConfiguration string 49 InitConfiguration string 50 } 51 52 // NewInitControlPlane returns the user data string to be used on a controlplane instance. 53 func NewInitControlPlane(input *ControlPlaneInput) ([]byte, error) { 54 input.Header = cloudConfigHeader 55 input.WriteFiles = input.Certificates.AsFiles() 56 input.WriteFiles = append(input.WriteFiles, input.AdditionalFiles...) 57 userData, err := generate("InitControlplane", controlPlaneCloudInit, input) 58 if err != nil { 59 return nil, err 60 } 61 62 return userData, nil 63 }