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