sigs.k8s.io/cluster-api@v1.6.3/bootstrap/kubeadm/api/v1alpha4/kubeadmconfig_types.go (about)

     1  /*
     2  Copyright 2020 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 v1alpha4
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  
    22  	clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
    23  )
    24  
    25  // Format specifies the output format of the bootstrap data
    26  // +kubebuilder:validation:Enum=cloud-config
    27  type Format string
    28  
    29  const (
    30  	// CloudConfig make the bootstrap data to be of cloud-config format.
    31  	CloudConfig Format = "cloud-config"
    32  )
    33  
    34  // KubeadmConfigSpec defines the desired state of KubeadmConfig.
    35  // Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined.
    36  type KubeadmConfigSpec struct {
    37  	// ClusterConfiguration along with InitConfiguration are the configurations necessary for the init command
    38  	// +optional
    39  	ClusterConfiguration *ClusterConfiguration `json:"clusterConfiguration,omitempty"`
    40  
    41  	// InitConfiguration along with ClusterConfiguration are the configurations necessary for the init command
    42  	// +optional
    43  	InitConfiguration *InitConfiguration `json:"initConfiguration,omitempty"`
    44  
    45  	// JoinConfiguration is the kubeadm configuration for the join command
    46  	// +optional
    47  	JoinConfiguration *JoinConfiguration `json:"joinConfiguration,omitempty"`
    48  
    49  	// Files specifies extra files to be passed to user_data upon creation.
    50  	// +optional
    51  	Files []File `json:"files,omitempty"`
    52  
    53  	// DiskSetup specifies options for the creation of partition tables and file systems on devices.
    54  	// +optional
    55  	DiskSetup *DiskSetup `json:"diskSetup,omitempty"`
    56  
    57  	// Mounts specifies a list of mount points to be setup.
    58  	// +optional
    59  	Mounts []MountPoints `json:"mounts,omitempty"`
    60  
    61  	// PreKubeadmCommands specifies extra commands to run before kubeadm runs
    62  	// +optional
    63  	PreKubeadmCommands []string `json:"preKubeadmCommands,omitempty"`
    64  
    65  	// PostKubeadmCommands specifies extra commands to run after kubeadm runs
    66  	// +optional
    67  	PostKubeadmCommands []string `json:"postKubeadmCommands,omitempty"`
    68  
    69  	// Users specifies extra users to add
    70  	// +optional
    71  	Users []User `json:"users,omitempty"`
    72  
    73  	// NTP specifies NTP configuration
    74  	// +optional
    75  	NTP *NTP `json:"ntp,omitempty"`
    76  
    77  	// Format specifies the output format of the bootstrap data
    78  	// +optional
    79  	Format Format `json:"format,omitempty"`
    80  
    81  	// Verbosity is the number for the kubeadm log level verbosity.
    82  	// It overrides the `--v` flag in kubeadm commands.
    83  	// +optional
    84  	Verbosity *int32 `json:"verbosity,omitempty"`
    85  
    86  	// UseExperimentalRetryJoin replaces a basic kubeadm command with a shell
    87  	// script with retries for joins.
    88  	//
    89  	// This is meant to be an experimental temporary workaround on some environments
    90  	// where joins fail due to timing (and other issues). The long term goal is to add retries to
    91  	// kubeadm proper and use that functionality.
    92  	//
    93  	// This will add about 40KB to userdata
    94  	//
    95  	// For more information, refer to https://github.com/kubernetes-sigs/cluster-api/pull/2763#discussion_r397306055.
    96  	// +optional
    97  	UseExperimentalRetryJoin bool `json:"useExperimentalRetryJoin,omitempty"`
    98  }
    99  
   100  // KubeadmConfigStatus defines the observed state of KubeadmConfig.
   101  type KubeadmConfigStatus struct {
   102  	// Ready indicates the BootstrapData field is ready to be consumed
   103  	Ready bool `json:"ready,omitempty"`
   104  
   105  	// DataSecretName is the name of the secret that stores the bootstrap data script.
   106  	// +optional
   107  	DataSecretName *string `json:"dataSecretName,omitempty"`
   108  
   109  	// FailureReason will be set on non-retryable errors
   110  	// +optional
   111  	FailureReason string `json:"failureReason,omitempty"`
   112  
   113  	// FailureMessage will be set on non-retryable errors
   114  	// +optional
   115  	FailureMessage string `json:"failureMessage,omitempty"`
   116  
   117  	// ObservedGeneration is the latest generation observed by the controller.
   118  	// +optional
   119  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
   120  
   121  	// Conditions defines current service state of the KubeadmConfig.
   122  	// +optional
   123  	Conditions clusterv1alpha4.Conditions `json:"conditions,omitempty"`
   124  }
   125  
   126  // +kubebuilder:object:root=true
   127  // +kubebuilder:unservedversion
   128  // +kubebuilder:deprecatedversion
   129  // +kubebuilder:resource:path=kubeadmconfigs,scope=Namespaced,categories=cluster-api
   130  // +kubebuilder:subresource:status
   131  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of KubeadmConfig"
   132  
   133  // KubeadmConfig is the Schema for the kubeadmconfigs API.
   134  //
   135  // Deprecated: This type will be removed in one of the next releases.
   136  type KubeadmConfig struct {
   137  	metav1.TypeMeta   `json:",inline"`
   138  	metav1.ObjectMeta `json:"metadata,omitempty"`
   139  
   140  	Spec   KubeadmConfigSpec   `json:"spec,omitempty"`
   141  	Status KubeadmConfigStatus `json:"status,omitempty"`
   142  }
   143  
   144  // GetConditions returns the set of conditions for this object.
   145  func (c *KubeadmConfig) GetConditions() clusterv1alpha4.Conditions {
   146  	return c.Status.Conditions
   147  }
   148  
   149  // SetConditions sets the conditions on this object.
   150  func (c *KubeadmConfig) SetConditions(conditions clusterv1alpha4.Conditions) {
   151  	c.Status.Conditions = conditions
   152  }
   153  
   154  // +kubebuilder:object:root=true
   155  
   156  // KubeadmConfigList contains a list of KubeadmConfig.
   157  //
   158  // Deprecated: This type will be removed in one of the next releases.
   159  type KubeadmConfigList struct {
   160  	metav1.TypeMeta `json:",inline"`
   161  	metav1.ListMeta `json:"metadata,omitempty"`
   162  	Items           []KubeadmConfig `json:"items"`
   163  }
   164  
   165  func init() {
   166  	objectTypes = append(objectTypes, &KubeadmConfig{}, &KubeadmConfigList{})
   167  }
   168  
   169  // Encoding specifies the cloud-init file encoding.
   170  // +kubebuilder:validation:Enum=base64;gzip;gzip+base64
   171  type Encoding string
   172  
   173  const (
   174  	// Base64 implies the contents of the file are encoded as base64.
   175  	Base64 Encoding = "base64"
   176  	// Gzip implies the contents of the file are encoded with gzip.
   177  	Gzip Encoding = "gzip"
   178  	// GzipBase64 implies the contents of the file are first base64 encoded and then gzip encoded.
   179  	GzipBase64 Encoding = "gzip+base64"
   180  )
   181  
   182  // File defines the input for generating write_files in cloud-init.
   183  type File struct {
   184  	// Path specifies the full path on disk where to store the file.
   185  	Path string `json:"path"`
   186  
   187  	// Owner specifies the ownership of the file, e.g. "root:root".
   188  	// +optional
   189  	Owner string `json:"owner,omitempty"`
   190  
   191  	// Permissions specifies the permissions to assign to the file, e.g. "0640".
   192  	// +optional
   193  	Permissions string `json:"permissions,omitempty"`
   194  
   195  	// Encoding specifies the encoding of the file contents.
   196  	// +optional
   197  	Encoding Encoding `json:"encoding,omitempty"`
   198  
   199  	// Content is the actual content of the file.
   200  	// +optional
   201  	Content string `json:"content,omitempty"`
   202  
   203  	// ContentFrom is a referenced source of content to populate the file.
   204  	// +optional
   205  	ContentFrom *FileSource `json:"contentFrom,omitempty"`
   206  }
   207  
   208  // FileSource is a union of all possible external source types for file data.
   209  // Only one field may be populated in any given instance. Developers adding new
   210  // sources of data for target systems should add them here.
   211  type FileSource struct {
   212  	// Secret represents a secret that should populate this file.
   213  	Secret SecretFileSource `json:"secret"`
   214  }
   215  
   216  // SecretFileSource adapts a Secret into a FileSource.
   217  //
   218  // The contents of the target Secret's Data field will be presented
   219  // as files using the keys in the Data field as the file names.
   220  type SecretFileSource struct {
   221  	// Name of the secret in the KubeadmBootstrapConfig's namespace to use.
   222  	Name string `json:"name"`
   223  
   224  	// Key is the key in the secret's data map for this value.
   225  	Key string `json:"key"`
   226  }
   227  
   228  // User defines the input for a generated user in cloud-init.
   229  type User struct {
   230  	// Name specifies the user name
   231  	Name string `json:"name"`
   232  
   233  	// Gecos specifies the gecos to use for the user
   234  	// +optional
   235  	Gecos *string `json:"gecos,omitempty"`
   236  
   237  	// Groups specifies the additional groups for the user
   238  	// +optional
   239  	Groups *string `json:"groups,omitempty"`
   240  
   241  	// HomeDir specifies the home directory to use for the user
   242  	// +optional
   243  	HomeDir *string `json:"homeDir,omitempty"`
   244  
   245  	// Inactive specifies whether to mark the user as inactive
   246  	// +optional
   247  	Inactive *bool `json:"inactive,omitempty"`
   248  
   249  	// Shell specifies the user's shell
   250  	// +optional
   251  	Shell *string `json:"shell,omitempty"`
   252  
   253  	// Passwd specifies a hashed password for the user
   254  	// +optional
   255  	Passwd *string `json:"passwd,omitempty"`
   256  
   257  	// PrimaryGroup specifies the primary group for the user
   258  	// +optional
   259  	PrimaryGroup *string `json:"primaryGroup,omitempty"`
   260  
   261  	// LockPassword specifies if password login should be disabled
   262  	// +optional
   263  	LockPassword *bool `json:"lockPassword,omitempty"`
   264  
   265  	// Sudo specifies a sudo role for the user
   266  	// +optional
   267  	Sudo *string `json:"sudo,omitempty"`
   268  
   269  	// SSHAuthorizedKeys specifies a list of ssh authorized keys for the user
   270  	// +optional
   271  	SSHAuthorizedKeys []string `json:"sshAuthorizedKeys,omitempty"`
   272  }
   273  
   274  // NTP defines input for generated ntp in cloud-init.
   275  type NTP struct {
   276  	// Servers specifies which NTP servers to use
   277  	// +optional
   278  	Servers []string `json:"servers,omitempty"`
   279  
   280  	// Enabled specifies whether NTP should be enabled
   281  	// +optional
   282  	Enabled *bool `json:"enabled,omitempty"`
   283  }
   284  
   285  // DiskSetup defines input for generated disk_setup and fs_setup in cloud-init.
   286  type DiskSetup struct {
   287  	// Partitions specifies the list of the partitions to setup.
   288  	Partitions []Partition `json:"partitions,omitempty"`
   289  	// Filesystems specifies the list of file systems to setup.
   290  	Filesystems []Filesystem `json:"filesystems,omitempty"`
   291  }
   292  
   293  // Partition defines how to create and layout a partition.
   294  type Partition struct {
   295  	// Device is the name of the device.
   296  	Device string `json:"device"`
   297  	// Layout specifies the device layout.
   298  	// If it is true, a single partition will be created for the entire device.
   299  	// When layout is false, it means don't partition or ignore existing partitioning.
   300  	Layout bool `json:"layout"`
   301  	// Overwrite describes whether to skip checks and create the partition if a partition or filesystem is found on the device.
   302  	// Use with caution. Default is 'false'.
   303  	// +optional
   304  	Overwrite *bool `json:"overwrite,omitempty"`
   305  	// TableType specifies the tupe of partition table. The following are supported:
   306  	// 'mbr': default and setups a MS-DOS partition table
   307  	// 'gpt': setups a GPT partition table
   308  	// +optional
   309  	TableType *string `json:"tableType,omitempty"`
   310  }
   311  
   312  // Filesystem defines the file systems to be created.
   313  type Filesystem struct {
   314  	// Device specifies the device name
   315  	Device string `json:"device"`
   316  	// Filesystem specifies the file system type.
   317  	Filesystem string `json:"filesystem"`
   318  	// Label specifies the file system label to be used. If set to None, no label is used.
   319  	Label string `json:"label"`
   320  	// Partition specifies the partition to use. The valid options are: "auto|any", "auto", "any", "none", and <NUM>, where NUM is the actual partition number.
   321  	// +optional
   322  	Partition *string `json:"partition,omitempty"`
   323  	// Overwrite defines whether or not to overwrite any existing filesystem.
   324  	// If true, any pre-existing file system will be destroyed. Use with Caution.
   325  	// +optional
   326  	Overwrite *bool `json:"overwrite,omitempty"`
   327  	// ReplaceFS is a special directive, used for Microsoft Azure that instructs cloud-init to replace a file system of <FS_TYPE>.
   328  	// NOTE: unless you define a label, this requires the use of the 'any' partition directive.
   329  	// +optional
   330  	ReplaceFS *string `json:"replaceFS,omitempty"`
   331  	// ExtraOpts defined extra options to add to the command for creating the file system.
   332  	// +optional
   333  	ExtraOpts []string `json:"extraOpts,omitempty"`
   334  }
   335  
   336  // MountPoints defines input for generated mounts in cloud-init.
   337  type MountPoints []string