sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/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: /tmp/kubeadm-node.yaml
    23      owner: root:root
    24      permissions: '0640'
    25      content: |
    26        ---
    27  {{.JoinConfiguration | Indent 6}}
    28  runcmd:
    29  {{- template "commands" .PreKubeadmCommands }}
    30    - 'kubeadm join --config /tmp/kubeadm-node.yaml'
    31  {{- template "commands" .PostKubeadmCommands }}
    32  {{- template "ntp" .NTP }}
    33  {{- template "users" .Users }}
    34  `
    35  )
    36  
    37  // NodeInput defines the context to generate a node user data.
    38  type NodeInput struct {
    39  	BaseUserData
    40  
    41  	JoinConfiguration string
    42  }
    43  
    44  // NewNode returns the user data string to be used on a node instance.
    45  func NewNode(input *NodeInput) ([]byte, error) {
    46  	input.Header = cloudConfigHeader
    47  	input.WriteFiles = append(input.WriteFiles, input.AdditionalFiles...)
    48  	return generate("Node", nodeCloudInit, input)
    49  }