k8s_cluster_api/v1beta1/cluster/common.rs
1use super::*;
2
3/// ClusterLabelName is the label set on machines linked to a cluster and
4/// external objects(bootstrap and infrastructure providers).
5pub const CLUSTER_LABEL_NAME: &str = "cluster.x-k8s.io/cluster-name";
6
7// ClusterTopologyOwnedLabel is the label set on all the object which are managed as part of a ClusterTopology.
8pub const CLUSTER_TOPOLOGY_OWNED_LABEL: &str = "topology.cluster.x-k8s.io/owned";
9
10// ClusterTopologyMachineDeploymentLabelName is the label set on the generated MachineDeployment objects
11// to track the name of the MachineDeployment topology it represents.
12pub const CLUSTER_TOPOLOGY_MACHINE_DEPLOYMENT_LABEL_NAME: &str =
13 "topology.cluster.x-k8s.io/deployment-name";
14
15// ProviderLabelName is the label set on components in the provider manifest.
16// This label allows to easily identify all the components belonging to a provider; the clusterctl
17// tool uses this label for implementing provider's lifecycle operations.
18pub const PROVIDER_LABEL_NAME: &str = "cluster.x-k8s.io/provider";
19
20// ClusterNameAnnotation is the annotation set on nodes identifying the name of the cluster the node belongs to.
21pub const CLUSTER_NAME_ANNOTATION: &str = "cluster.x-k8s.io/cluster-name";
22
23// ClusterNamespaceAnnotation is the annotation set on nodes identifying the namespace of the cluster the node belongs to.
24pub const CLUSTER_NAMESPACE_ANNOTATION: &str = "cluster.x-k8s.io/cluster-namespace";
25
26// MachineAnnotation is the annotation set on nodes identifying the machine the node belongs to.
27pub const MACHINE_ANNOTATION: &str = "cluster.x-k8s.io/machine";
28
29// OwnerKindAnnotation is the annotation set on nodes identifying the owner kind.
30pub const OWNER_KIND_ANNOTATION: &str = "cluster.x-k8s.io/owner-kind";
31
32// OwnerNameAnnotation is the annotation set on nodes identifying the owner name.
33pub const OWNER_NAME_ANNOTATION: &str = "cluster.x-k8s.io/owner-name";
34
35// PausedAnnotation is an annotation that can be applied to any Cluster API
36// object to prevent a controller from processing a resource.
37//
38// Controllers working with Cluster API objects must check the existence of this annotation
39// on the reconciled object.
40pub const PAUSED_ANNOTATION: &str = "cluster.x-k8s.io/paused";
41
42// DisableMachineCreate is an annotation that can be used to signal a MachineSet to stop creating new machines.
43// It is utilized in the OnDelete MachineDeploymentStrategy to allow the MachineDeployment controller to scale down
44// older MachineSets when Machines are deleted and add the new replicas to the latest MachineSet.
45pub const DISABLE_MACHINE_CREATE: &str = "cluster.x-k8s.io/disable-machine-create";
46
47// WatchLabel is a label othat can be applied to any Cluster API object.
48//
49// Controllers which allow for selective reconciliation may check this label and proceed
50// with reconciliation of the object only if this label and a configured value is present.
51pub const WATCH_LABEL: &str = "cluster.x-k8s.io/watch-filter";
52
53// DeleteMachineAnnotation marks control plane and worker nodes that will be given priority for deletion
54// when KCP or a machineset scales down. This annotation is given top priority on all delete policies.
55pub const DELETE_MACHINE_ANNOTATION: &str = "cluster.x-k8s.io/delete-machine";
56
57// TemplateClonedFromNameAnnotation is the infrastructure machine annotation that stores the name of the infrastructure template resource
58// that was cloned for the machine. This annotation is set only during cloning a template. Older/adopted machines will not have this annotation.
59pub const TEMPLATE_CLONED_FROM_NAME_ANNOTATION: &str = "cluster.x-k8s.io/cloned-from-name";
60
61// TemplateClonedFromGroupKindAnnotation is the infrastructure machine annotation that stores the group-kind of the infrastructure template resource
62// that was cloned for the machine. This annotation is set only during cloning a template. Older/adopted machines will not have this annotation.
63pub const TEMPLATE_CLONED_FROM_GROUP_KIND_ANNOTATION: &str =
64 "cluster.x-k8s.io/cloned-from-groupkind";
65
66// MachineSkipRemediationAnnotation is the annotation used to mark the machines that should not be considered for remediation by MachineHealthCheck reconciler.
67pub const MACHINE_SKIP_REMEDIATION_ANNOTATION: &str = "cluster.x-k8s.io/skip-remediation";
68
69// ClusterSecretType defines the type of secret created by core components.
70pub const CLUSTER_SECRET_TYPE: &str = "cluster.x-k8s.io/secret"; //nolint:gosec
71
72// InterruptibleLabel is the label used to mark the nodes that run on interruptible instances.
73pub const INTERRUPTIBLE_LABEL: &str = "cluster.x-k8s.io/interruptible";
74
75// ManagedByAnnotation is an annotation that can be applied to InfraCluster resources to signify that
76// some external system is managing the cluster infrastructure.
77//
78// Provider InfraCluster controllers will ignore resources with this annotation.
79// An external controller must fulfill the contract of the InfraCluster resource.
80// External infrastructure providers should ensure that the annotation, once set, cannot be removed.
81pub const MANAGED_BY_ANNOTATION: &str = "cluster.x-k8s.io/managed-by";
82
83// TemplateSuffix is the object kind suffix used by template types.
84pub const TEMPLATE_SUFFIX: &str = "Template";
85
86// var (
87// // ZeroDuration is a zero value of the metav1.Duration type.
88// ZeroDuration = metav1.Duration{}
89// )
90
91// MachineAddressType describes a valid MachineAddress type.
92#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
93pub enum MachineAddressType {
94 #[serde(rename = "Hostname")]
95 MachineHostName,
96 #[serde(rename = "ExternalIP")]
97 MachineExternalIP,
98 #[serde(rename = "InternalIP")]
99 MachineInternalIP,
100 #[serde(rename = "ExternalDNS")]
101 MachineExternalDNS,
102 #[serde(rename = "InternalDNS")]
103 MachineInternalDNS,
104}
105
106/// MachineAddress contains information for the node's address.
107#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
108pub struct MachineAddress {
109 // Machine address type, one of Hostname, ExternalIP or InternalIP.
110 pub r#type: MachineAddressType,
111
112 // The machine address.
113 pub address: String,
114}
115
116/// MachineAddresses is a slice of MachineAddress items to be used by infrastructure providers.
117pub type MachineAddresses = Vec<MachineAddress>;
118
119// ObjectMeta is metadata that all persisted resources must have, which includes all objects
120// users must create. This is a copy of customizable fields from metav1.ObjectMeta.
121//
122// ObjectMeta is embedded in `Machine.Spec`, `MachineDeployment.Template` and `MachineSet.Template`,
123// which are not top-level Kubernetes objects. Given that metav1.ObjectMeta has lots of special cases
124// and read-only fields which end up in the generated CRD validation, having it as a subset simplifies
125// the API and some issues that can impact user experience.
126//
127// During the [upgrade to controller-tools@v2](https://github.com/kubernetes-sigs/cluster-api/pull/1054)
128// for v1alpha2, we noticed a failure would occur running Cluster API test suite against the new CRDs,
129// specifically `spec.metadata.creationTimestamp in body must be of type string: "null"`.
130// The investigation showed that `controller-tools@v2` behaves differently than its previous version
131// when handling types from [metav1](k8s.io/apimachinery/pkg/apis/meta/v1) package.
132//
133// In more details, we found that embedded (non-top level) types that embedded `metav1.ObjectMeta`
134// had validation properties, including for `creationTimestamp` (metav1.Time).
135// The `metav1.Time` type specifies a custom json marshaller that, when IsZero() is true, returns `null`
136// which breaks validation because the field isn't marked as nullable.
137//
138// In future versions, controller-tools@v2 might allow overriding the type and validation for embedded
139// types. When that happens, this hack should be revisited.
140#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
141pub struct ObjectMeta {
142 // Map of string keys and values that can be used to organize and categorize
143 // (scope and select) objects. May match selectors of replication controllers
144 // and services.
145 // More info: http://kubernetes.io/docs/user-guide/labels
146 // +optional
147 pub labels: Option<BTreeMap<String, String>>,
148
149 // Annotations is an unstructured key value map stored with a resource that may be
150 // set by external tools to store and retrieve arbitrary metadata. They are not
151 // queryable and should be preserved when modifying objects.
152 // More info: http://kubernetes.io/docs/user-guide/annotations
153 // +optional
154 pub annotations: Option<BTreeMap<String, String>>,
155}