sigs.k8s.io/cluster-api@v1.7.1/bootstrap/kubeadm/internal/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/util/secret"
    21  )
    22  
    23  const (
    24  	controlPlaneCloudInit = `{{.Header}}
    25  {{template "files" .WriteFiles}}
    26  -   path: /run/kubeadm/kubeadm.yaml
    27      owner: root:root
    28      permissions: '0640'
    29      content: |
    30        ---
    31  {{.ClusterConfiguration | Indent 6}}
    32        ---
    33  {{.InitConfiguration | Indent 6}}
    34  -   path: /run/cluster-api/placeholder
    35      owner: root:root
    36      permissions: '0640'
    37      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)"
    38  runcmd:
    39  {{- template "commands" .PreKubeadmCommands }}
    40    - 'kubeadm init --config /run/kubeadm/kubeadm.yaml {{.KubeadmVerbosity}} && {{ .SentinelFileCommand }}'
    41  {{- template "commands" .PostKubeadmCommands }}
    42  {{- template "ntp" .NTP }}
    43  {{- template "users" .Users }}
    44  {{- template "disk_setup" .DiskSetup}}
    45  {{- template "fs_setup" .DiskSetup}}
    46  {{- template "mounts" .Mounts}}
    47  `
    48  )
    49  
    50  // ControlPlaneInput defines the context to generate a controlplane instance user data.
    51  type ControlPlaneInput struct {
    52  	BaseUserData
    53  	secret.Certificates
    54  
    55  	ClusterConfiguration string
    56  	InitConfiguration    string
    57  }
    58  
    59  // NewInitControlPlane returns the user data string to be used on a controlplane instance.
    60  func NewInitControlPlane(input *ControlPlaneInput) ([]byte, error) {
    61  	input.Header = cloudConfigHeader
    62  	input.WriteFiles = input.Certificates.AsFiles()
    63  	input.WriteFiles = append(input.WriteFiles, input.AdditionalFiles...)
    64  	input.SentinelFileCommand = sentinelFileCommand
    65  	userData, err := generate("InitControlplane", controlPlaneCloudInit, input)
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  
    70  	return userData, nil
    71  }