k8s_cluster_api/v1beta1/controlplane/
kubeadm.rs

1use super::*;
2
3mod impls;
4
5/// KubeadmControlPlaneSpec defines the desired state of KubeadmControlPlane.
6#[skip_serializing_none]
7#[derive(Clone, Debug, Default, Serialize, Deserialize, CustomResource)]
8#[serde(rename_all = "camelCase")]
9#[kube(
10    group = "controlplane.cluster.x-k8s.io",
11    version = "v1beta1",
12    kind = "KubeadmControlPlane",
13    plural = "kubeadmcontrolplanes",
14    shortname = "kcp",
15    status = "KubeadmControlPlaneStatus"
16)]
17#[kube(namespaced)]
18#[kube(schema = "disabled")]
19pub struct KubeadmControlPlaneSpec {
20    /// Number of desired machines. Defaults to 1. When stacked etcd is used only
21    /// odd numbers are permitted, as per [etcd best practice](https://etcd.io/docs/v3.3.12/faq/#why-an-odd-number-of-cluster-members).
22    /// This is a pointer to distinguish between explicit zero and not specified.
23    // +optional
24    pub replicas: Option<i32>, // `json:"replicas,omitempty"`
25
26    /// Version defines the desired Kubernetes version.
27    pub version: String, // `json:"version"`
28
29    /// MachineTemplate contains information about how machines
30    /// should be shaped when creating or updating a control plane.
31    pub machine_template: KubeadmControlPlaneMachineTemplate, // `json:"machineTemplate"`
32
33    /// KubeadmConfigSpec is a KubeadmConfigSpec
34    /// to use for initializing and joining machines to the control plane.
35    pub kubeadm_config_spec: cabpkv1::KubeadmConfigSpec, //`json:"kubeadmConfigSpec"`
36
37    /// RolloutAfter is a field to indicate a rollout should be performed
38    /// after the specified time even if no changes have been made to the
39    /// KubeadmControlPlane.
40    //
41    // +optional
42    pub rollout_after: Option<metav1::Time>, // `json:"rolloutAfter,omitempty"`
43
44    /// The RolloutStrategy to use to replace control plane machines with
45    /// new ones.
46    // +optional
47    // +kubebuilder:default={type: "RollingUpdate", rollingUpdate: {maxSurge: 1}}
48    pub rollout_strategy: Option<RolloutStrategy>, // `json:"rolloutStrategy,omitempty"`
49}
50
51#[derive(Clone, Debug, Default, Serialize, Deserialize)]
52/// KubeadmControlPlaneStatus defines the observed state of KubeadmControlPlane.
53pub struct KubeadmControlPlaneStatus {
54    // Selector is the label selector in string format to avoid introspection
55    // by clients, and is used to provide the CRD-based integration for the
56    // scale subresource and additional integrations for things like kubectl
57    // describe.. The string will be in the same format as the query-param syntax.
58    // More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors
59    // +optional
60    pub selector: Option<String>, // `json:"selector,omitempty"`
61
62    // Total number of non-terminated machines targeted by this control plane
63    // (their labels match the selector).
64    // +optional
65    pub replicas: Option<i32>, // `json:"replicas"`
66
67    // Version represents the minimum Kubernetes version for the control plane machines
68    // in the cluster.
69    // +optional
70    pub version: Option<String>, // `json:"version,omitempty"`
71
72    // Total number of non-terminated machines targeted by this control plane
73    // that have the desired template spec.
74    // +optional
75    pub updated_replicas: Option<i32>, // `json:"updatedReplicas"`
76
77    // Total number of fully running and ready control plane machines.
78    // +optional
79    pub ready_replicas: Option<i32>, // `json:"readyReplicas"`
80
81    // Total number of unavailable machines targeted by this control plane.
82    // This is the total number of machines that are still required for
83    // the deployment to have 100% available capacity. They may either
84    // be machines that are running but not yet ready or machines
85    // that still have not been created.
86    // +optional
87    pub unavailable_replicas: Option<i32>, // `json:"unavailableReplicas"`
88
89    // Initialized denotes whether or not the control plane has the
90    // uploaded kubeadm-config configmap.
91    // +optional
92    pub initialized: Option<bool>, // `json:"initialized"`
93
94    // Ready denotes that the KubeadmControlPlane API Server is ready to
95    // receive requests.
96    // +optional
97    pub ready: Option<bool>, // `json:"ready"`
98
99    // FailureReason indicates that there is a terminal problem reconciling the
100    // state, and will be set to a token value suitable for
101    // programmatic interpretation.
102    // +optional
103    pub failure_reason: Option<errors::KubeadmControlPlaneStatusError>, // `json:"failureReason,omitempty"`
104
105    // ErrorMessage indicates that there is a terminal problem reconciling the
106    // state, and will be set to a descriptive error message.
107    // +optional
108    pub failure_message: Option<String>, // `json:"failureMessage,omitempty"`
109
110    // ObservedGeneration is the latest generation observed by the controller.
111    // +optional
112    pub observed_generation: Option<i64>, // `json:"observedGeneration,omitempty"`
113
114    // Conditions defines current service state of the KubeadmControlPlane.
115    // +optional
116    pub conditions: Option<clusterv1::Conditions>, // `json:"conditions,omitempty"`
117}
118
119/// KubeadmControlPlaneMachineTemplate defines the template for Machines
120/// in a KubeadmControlPlane object.
121#[serde_as]
122#[skip_serializing_none]
123#[derive(Clone, Debug, Default, Serialize, Deserialize)]
124#[serde(rename_all = "camelCase")]
125pub struct KubeadmControlPlaneMachineTemplate {
126    /// Standard object's metadata.
127    /// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
128    // +optional
129    pub metadata: Option<clusterv1::ObjectMeta>, // `json:"metadata,omitempty"`
130
131    /// InfrastructureRef is a required reference to a custom resource
132    /// offered by an infrastructure provider.
133    pub infrastructure_ref: corev1::ObjectReference, // `json:"infrastructureRef"`
134
135    /// NodeDrainTimeout is the total amount of time that the controller will spend on draining a controlplane node
136    /// The default value is 0, meaning that the node can be drained without any time limitations.
137    /// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
138    // +optional
139    // #[serde_as(as = "serde_with::DurationSeconds<i64>")]
140    // pub node_drain_timeout: Option<chrono::Duration>, // `json:"nodeDrainTimeout,omitempty"`
141    pub node_drain_timeout: Option<i64>, // `json:"nodeDrainTimeout,omitempty"`
142}
143
144/// RolloutStrategy describes how to replace existing machines
145/// with new ones.
146#[skip_serializing_none]
147#[derive(Clone, Debug, Default, Serialize, Deserialize)]
148#[serde(rename_all = "camelCase")]
149pub struct RolloutStrategy {
150    /// Type of rollout. Currently the only supported strategy is
151    /// "RollingUpdate".
152    /// Default is RollingUpdate.
153    // +optional
154    pub r#type: Option<RolloutStrategyType>, // `json:"type,omitempty"`
155
156    /// Rolling update config params. Present only if
157    /// RolloutStrategyType = RollingUpdate.
158    // +optional
159    pub rolling_update: Option<RollingUpdate>, // `json:"rollingUpdate,omitempty"`
160}
161
162/// RolloutStrategyType defines the rollout strategies for a KubeadmControlPlane.
163#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
164pub enum RolloutStrategyType {
165    /// RollingUpdateStrategyType replaces the old control planes by new one using rolling update
166    /// i.e. gradually scale up or down the old control planes and scale up or down the new one.
167    RollingUpdate,
168}
169
170/// RollingUpdate is used to control the desired behavior of rolling update.
171#[skip_serializing_none]
172#[derive(Clone, Debug, Default, Serialize, Deserialize)]
173#[serde(rename_all = "camelCase")]
174pub struct RollingUpdate {
175    /// The maximum number of control planes that can be scheduled above or under the
176    /// desired number of control planes.
177    /// Value can be an absolute number 1 or 0.
178    /// Defaults to 1.
179    /// Example: when this is set to 1, the control plane can be scaled
180    /// up immediately when the rolling update starts.
181    // +optional
182    pub max_surge: Option<intstr::IntOrString>, // `json:"maxSurge,omitempty"`
183}
184
185#[cfg(test)]
186mod tests;
187
188/* ======
189
190package v1beta1
191
192import (
193    corev1 "k8s.io/api/core/v1"
194    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
195    "k8s.io/apimachinery/pkg/util/intstr"
196    clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
197    cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
198    "sigs.k8s.io/cluster-api/errors"
199)
200
201
202const (
203    // RollingUpdateStrategyType replaces the old control planes by new one using rolling update
204    // i.e. gradually scale up or down the old control planes and scale up or down the new one.
205    RollingUpdateStrategyType RolloutStrategyType = "RollingUpdate"
206)
207
208const (
209    // KubeadmControlPlaneFinalizer is the finalizer applied to KubeadmControlPlane resources
210    // by its managing controller.
211    KubeadmControlPlaneFinalizer = "kubeadm.controlplane.cluster.x-k8s.io"
212
213    // SkipCoreDNSAnnotation annotation explicitly skips reconciling CoreDNS if set.
214    SkipCoreDNSAnnotation = "controlplane.cluster.x-k8s.io/skip-coredns"
215
216    // SkipKubeProxyAnnotation annotation explicitly skips reconciling kube-proxy if set.
217    SkipKubeProxyAnnotation = "controlplane.cluster.x-k8s.io/skip-kube-proxy"
218
219    // KubeadmClusterConfigurationAnnotation is a machine annotation that stores the json-marshalled string of KCP ClusterConfiguration.
220    // This annotation is used to detect any changes in ClusterConfiguration and trigger machine rollout in KCP.
221    KubeadmClusterConfigurationAnnotation = "controlplane.cluster.x-k8s.io/kubeadm-cluster-configuration"
222)
223
224
225// +kubebuilder:object:root=true
226// +kubebuilder:resource:path=kubeadmcontrolplanes,shortName=kcp,scope=Namespaced,categories=cluster-api
227// +kubebuilder:storageversion
228// +kubebuilder:subresource:status
229// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
230// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels['cluster\\.x-k8s\\.io/cluster-name']",description="Cluster"
231// +kubebuilder:printcolumn:name="Initialized",type=boolean,JSONPath=".status.initialized",description="This denotes whether or not the control plane has the uploaded kubeadm-config configmap"
232// +kubebuilder:printcolumn:name="API Server Available",type=boolean,JSONPath=".status.ready",description="KubeadmControlPlane API Server is ready to receive requests"
233// +kubebuilder:printcolumn:name="Replicas",type=integer,JSONPath=".status.replicas",description="Total number of non-terminated machines targeted by this control plane"
234// +kubebuilder:printcolumn:name="Ready",type=integer,JSONPath=".status.readyReplicas",description="Total number of fully running and ready control plane machines"
235// +kubebuilder:printcolumn:name="Updated",type=integer,JSONPath=".status.updatedReplicas",description="Total number of non-terminated machines targeted by this control plane that have the desired template spec"
236// +kubebuilder:printcolumn:name="Unavailable",type=integer,JSONPath=".status.unavailableReplicas",description="Total number of unavailable machines targeted by this control plane"
237// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of KubeadmControlPlane"
238// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=".spec.version",description="Kubernetes version associated with this control plane"
239
240// KubeadmControlPlane is the Schema for the KubeadmControlPlane API.
241type KubeadmControlPlane struct {
242    metav1.TypeMeta   `json:",inline"`
243    metav1.ObjectMeta `json:"metadata,omitempty"`
244
245    Spec   KubeadmControlPlaneSpec   `json:"spec,omitempty"`
246    Status KubeadmControlPlaneStatus `json:"status,omitempty"`
247}
248
249// GetConditions returns the set of conditions for this object.
250func (in *KubeadmControlPlane) GetConditions() clusterv1.Conditions {
251    return in.Status.Conditions
252}
253
254// SetConditions sets the conditions on this object.
255func (in *KubeadmControlPlane) SetConditions(conditions clusterv1.Conditions) {
256    in.Status.Conditions = conditions
257}
258
259// +kubebuilder:object:root=true
260
261// KubeadmControlPlaneList contains a list of KubeadmControlPlane.
262type KubeadmControlPlaneList struct {
263    metav1.TypeMeta `json:",inline"`
264    metav1.ListMeta `json:"metadata,omitempty"`
265    Items           []KubeadmControlPlane `json:"items"`
266}
267
268func init() {
269    SchemeBuilder.Register(&KubeadmControlPlane{}, &KubeadmControlPlaneList{})
270}
271
272
273======= */