k8s_cluster_api/v1beta1/bootstrap/kubeadm/
kubeadmconfig.rs

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