sigs.k8s.io/cluster-api@v1.7.1/bootstrap/kubeadm/internal/cloudinit/node.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  const (
    20  	nodeCloudInit = `{{.Header}}
    21  {{template "files" .WriteFiles}}
    22  -   path: /run/kubeadm/kubeadm-join-config.yaml
    23      owner: root:root
    24      permissions: '0640'
    25      content: |
    26        ---
    27  {{.JoinConfiguration | Indent 6}}
    28  -   path: /run/cluster-api/placeholder
    29      owner: root:root
    30      permissions: '0640'
    31      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)"
    32  runcmd:
    33  {{- template "commands" .PreKubeadmCommands }}
    34    - {{ .KubeadmCommand }} && {{ .SentinelFileCommand }}
    35  {{- template "commands" .PostKubeadmCommands }}
    36  {{- template "ntp" .NTP }}
    37  {{- template "users" .Users }}
    38  {{- template "disk_setup" .DiskSetup}}
    39  {{- template "fs_setup" .DiskSetup}}
    40  {{- template "mounts" .Mounts}}
    41  `
    42  )
    43  
    44  // NodeInput defines the context to generate a node user data.
    45  type NodeInput struct {
    46  	BaseUserData
    47  	JoinConfiguration string
    48  }
    49  
    50  // NewNode returns the user data string to be used on a node instance.
    51  func NewNode(input *NodeInput) ([]byte, error) {
    52  	if err := input.prepare(); err != nil {
    53  		return nil, err
    54  	}
    55  	input.Header = cloudConfigHeader
    56  	return generate("Node", nodeCloudInit, input)
    57  }