sigs.k8s.io/cluster-api@v1.7.1/bootstrap/kubeadm/internal/cloudinit/controlplane_join.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 "github.com/pkg/errors" 21 22 "sigs.k8s.io/cluster-api/util/secret" 23 ) 24 25 const ( 26 controlPlaneJoinCloudInit = `{{.Header}} 27 {{template "files" .WriteFiles}} 28 - path: /run/kubeadm/kubeadm-join-config.yaml 29 owner: root:root 30 permissions: '0640' 31 content: | 32 {{.JoinConfiguration | Indent 6}} 33 - path: /run/cluster-api/placeholder 34 owner: root:root 35 permissions: '0640' 36 content: "This placeholder file is used to create the /run/cluster-api sub directory in a way that is compatible with both Linux and Windows (mkdir -p /run/cluster-api does not work with Windows)" 37 runcmd: 38 {{- template "commands" .PreKubeadmCommands }} 39 - {{ .KubeadmCommand }} && {{ .SentinelFileCommand }} 40 {{- template "commands" .PostKubeadmCommands }} 41 {{- template "ntp" .NTP }} 42 {{- template "users" .Users }} 43 {{- template "disk_setup" .DiskSetup}} 44 {{- template "fs_setup" .DiskSetup}} 45 {{- template "mounts" .Mounts}} 46 ` 47 ) 48 49 // ControlPlaneJoinInput defines context to generate controlplane instance user data for control plane node join. 50 type ControlPlaneJoinInput struct { 51 BaseUserData 52 secret.Certificates 53 BootstrapToken string 54 JoinConfiguration string 55 } 56 57 // NewJoinControlPlane returns the user data string to be used on a new control plane instance. 58 func NewJoinControlPlane(input *ControlPlaneJoinInput) ([]byte, error) { 59 // TODO: Consider validating that the correct certificates exist. It is different for external/stacked etcd 60 input.WriteFiles = input.Certificates.AsFiles() 61 input.ControlPlane = true 62 if err := input.prepare(); err != nil { 63 return nil, err 64 } 65 userData, err := generate("JoinControlplane", controlPlaneJoinCloudInit, input) 66 if err != nil { 67 return nil, errors.Wrapf(err, "failed to generate user data for machine joining control plane") 68 } 69 70 return userData, err 71 }