sigs.k8s.io/cluster-api@v1.6.3/api/v1beta1/common_types.go (about) 1 /* 2 Copyright 2021 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 v1beta1 18 19 import ( 20 corev1 "k8s.io/api/core/v1" 21 apivalidation "k8s.io/apimachinery/pkg/api/validation" 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" 24 "k8s.io/apimachinery/pkg/util/validation/field" 25 ) 26 27 const ( 28 // ClusterNameLabel is the label set on machines linked to a cluster and 29 // external objects(bootstrap and infrastructure providers). 30 ClusterNameLabel = "cluster.x-k8s.io/cluster-name" 31 32 // ClusterTopologyOwnedLabel is the label set on all the object which are managed as part of a ClusterTopology. 33 ClusterTopologyOwnedLabel = "topology.cluster.x-k8s.io/owned" 34 35 // ClusterTopologyMachineDeploymentNameLabel is the label set on the generated MachineDeployment objects 36 // to track the name of the MachineDeployment topology it represents. 37 ClusterTopologyMachineDeploymentNameLabel = "topology.cluster.x-k8s.io/deployment-name" 38 39 // ClusterTopologyHoldUpgradeSequenceAnnotation can be used to hold the entire MachineDeployment upgrade sequence. 40 // If the annotation is set on a MachineDeployment topology in Cluster.spec.topology.workers, the Kubernetes upgrade 41 // for this MachineDeployment topology and all subsequent ones is deferred. 42 // Examples: 43 // - If you want to pause upgrade after CP upgrade, this annotation should be applied to the first MachineDeployment 44 // in the list of MachineDeployments in Cluster.spec.topology. The upgrade will not be completed until the annotation 45 // is removed and all MachineDeployments are upgraded. 46 // - If you want to pause upgrade after the 50th MachineDeployment, this annotation should be applied to the 51st 47 // MachineDeployment in the list. 48 ClusterTopologyHoldUpgradeSequenceAnnotation = "topology.cluster.x-k8s.io/hold-upgrade-sequence" 49 50 // ClusterTopologyDeferUpgradeAnnotation can be used to defer the Kubernetes upgrade of a single MachineDeployment topology. 51 // If the annotation is set on a MachineDeployment topology in Cluster.spec.topology.workers, the Kubernetes upgrade 52 // for this MachineDeployment topology is deferred. It doesn't affect other MachineDeployment topologies. 53 // Example: 54 // - If you want to defer the upgrades of the 3rd and 5th MachineDeployments of the list, set the annotation on them. 55 // The upgrade process will upgrade MachineDeployment in position 1,2, (skip 3), 4, (skip 5), 6 etc. The upgrade 56 // will not be completed until the annotation is removed and all MachineDeployments are upgraded. 57 ClusterTopologyDeferUpgradeAnnotation = "topology.cluster.x-k8s.io/defer-upgrade" 58 59 // ClusterTopologyUpgradeConcurrencyAnnotation can be set as top-level annotation on the Cluster object of 60 // a classy Cluster to define the maximum concurrency while upgrading MachineDeployments. 61 ClusterTopologyUpgradeConcurrencyAnnotation = "topology.cluster.x-k8s.io/upgrade-concurrency" 62 63 // ClusterTopologyMachinePoolNameLabel is the label set on the generated MachinePool objects 64 // to track the name of the MachinePool topology it represents. 65 ClusterTopologyMachinePoolNameLabel = "topology.cluster.x-k8s.io/pool-name" 66 67 // ClusterTopologyUnsafeUpdateClassNameAnnotation can be used to disable the webhook check on 68 // update that disallows a pre-existing Cluster to be populated with Topology information and Class. 69 ClusterTopologyUnsafeUpdateClassNameAnnotation = "unsafe.topology.cluster.x-k8s.io/disable-update-class-name-check" 70 71 // ProviderNameLabel is the label set on components in the provider manifest. 72 // This label allows to easily identify all the components belonging to a provider; the clusterctl 73 // tool uses this label for implementing provider's lifecycle operations. 74 ProviderNameLabel = "cluster.x-k8s.io/provider" 75 76 // ClusterNameAnnotation is the annotation set on nodes identifying the name of the cluster the node belongs to. 77 ClusterNameAnnotation = "cluster.x-k8s.io/cluster-name" 78 79 // ClusterNamespaceAnnotation is the annotation set on nodes identifying the namespace of the cluster the node belongs to. 80 ClusterNamespaceAnnotation = "cluster.x-k8s.io/cluster-namespace" 81 82 // MachineAnnotation is the annotation set on nodes identifying the machine the node belongs to. 83 MachineAnnotation = "cluster.x-k8s.io/machine" 84 85 // OwnerKindAnnotation is the annotation set on nodes identifying the owner kind. 86 OwnerKindAnnotation = "cluster.x-k8s.io/owner-kind" 87 88 // LabelsFromMachineAnnotation is the annotation set on nodes to track the labels originated from machines. 89 LabelsFromMachineAnnotation = "cluster.x-k8s.io/labels-from-machine" 90 91 // OwnerNameAnnotation is the annotation set on nodes identifying the owner name. 92 OwnerNameAnnotation = "cluster.x-k8s.io/owner-name" 93 94 // PausedAnnotation is an annotation that can be applied to any Cluster API 95 // object to prevent a controller from processing a resource. 96 // 97 // Controllers working with Cluster API objects must check the existence of this annotation 98 // on the reconciled object. 99 PausedAnnotation = "cluster.x-k8s.io/paused" 100 101 // DisableMachineCreateAnnotation is an annotation that can be used to signal a MachineSet to stop creating new machines. 102 // It is utilized in the OnDelete MachineDeploymentStrategy to allow the MachineDeployment controller to scale down 103 // older MachineSets when Machines are deleted and add the new replicas to the latest MachineSet. 104 DisableMachineCreateAnnotation = "cluster.x-k8s.io/disable-machine-create" 105 106 // WatchLabel is a label othat can be applied to any Cluster API object. 107 // 108 // Controllers which allow for selective reconciliation may check this label and proceed 109 // with reconciliation of the object only if this label and a configured value is present. 110 WatchLabel = "cluster.x-k8s.io/watch-filter" 111 112 // DeleteMachineAnnotation marks control plane and worker nodes that will be given priority for deletion 113 // when KCP or a machineset scales down. This annotation is given top priority on all delete policies. 114 DeleteMachineAnnotation = "cluster.x-k8s.io/delete-machine" 115 116 // TemplateClonedFromNameAnnotation is the infrastructure machine annotation that stores the name of the infrastructure template resource 117 // that was cloned for the machine. This annotation is set only during cloning a template. Older/adopted machines will not have this annotation. 118 TemplateClonedFromNameAnnotation = "cluster.x-k8s.io/cloned-from-name" 119 120 // TemplateClonedFromGroupKindAnnotation is the infrastructure machine annotation that stores the group-kind of the infrastructure template resource 121 // that was cloned for the machine. This annotation is set only during cloning a template. Older/adopted machines will not have this annotation. 122 TemplateClonedFromGroupKindAnnotation = "cluster.x-k8s.io/cloned-from-groupkind" 123 124 // MachineSkipRemediationAnnotation is the annotation used to mark the machines that should not be considered for remediation by MachineHealthCheck reconciler. 125 MachineSkipRemediationAnnotation = "cluster.x-k8s.io/skip-remediation" 126 127 // MachineSetSkipPreflightChecksAnnotation is the annotation used to provide a comma-separated list of 128 // preflight checks that should be skipped during the MachineSet reconciliation. 129 // Supported items are: 130 // - KubeadmVersion (skips the kubeadm version skew preflight check) 131 // - KubernetesVersion (skips the kubernetes version skew preflight check) 132 // - ControlPlaneStable (skips checking that the control plane is neither provisioning nor upgrading) 133 // - All (skips all preflight checks) 134 // Example: "machineset.cluster.x-k8s.io/skip-preflight-checks": "ControlPlaneStable,KubernetesVersion". 135 // Note: The annotation can also be set on a MachineDeployment as MachineDeployment annotations are synced to 136 // the MachineSet. 137 MachineSetSkipPreflightChecksAnnotation = "machineset.cluster.x-k8s.io/skip-preflight-checks" 138 139 // ClusterSecretType defines the type of secret created by core components. 140 // Note: This is used by core CAPI, CAPBK, and KCP to determine whether a secret is created by the controllers 141 // themselves or supplied by the user (e.g. bring your own certificates). 142 ClusterSecretType corev1.SecretType = "cluster.x-k8s.io/secret" //nolint:gosec 143 144 // InterruptibleLabel is the label used to mark the nodes that run on interruptible instances. 145 InterruptibleLabel = "cluster.x-k8s.io/interruptible" 146 147 // ManagedByAnnotation is an annotation that can be applied to InfraCluster resources to signify that 148 // some external system is managing the cluster infrastructure. 149 // 150 // Provider InfraCluster controllers will ignore resources with this annotation. 151 // An external controller must fulfill the contract of the InfraCluster resource. 152 // External infrastructure providers should ensure that the annotation, once set, cannot be removed. 153 ManagedByAnnotation = "cluster.x-k8s.io/managed-by" 154 155 // TopologyDryRunAnnotation is an annotation that gets set on objects by the topology controller 156 // only during a server side dry run apply operation. It is used for validating 157 // update webhooks for objects which get updated by template rotation (e.g. InfrastructureMachineTemplate). 158 // When the annotation is set and the admission request is a dry run, the webhook should 159 // deny validation due to immutability. By that the request will succeed (without 160 // any changes to the actual object because it is a dry run) and the topology controller 161 // will receive the resulting object. 162 TopologyDryRunAnnotation = "topology.cluster.x-k8s.io/dry-run" 163 164 // ReplicasManagedByAnnotation is an annotation that indicates external (non-Cluster API) management of infra scaling. 165 // The practical effect of this is that the capi "replica" count should be passively derived from the number of observed infra machines, 166 // instead of being a source of truth for eventual consistency. 167 // This annotation can be used to inform MachinePool status during in-progress scaling scenarios. 168 ReplicasManagedByAnnotation = "cluster.x-k8s.io/replicas-managed-by" 169 170 // AutoscalerMinSizeAnnotation defines the minimum node group size. 171 // The annotation is used by autoscaler. 172 // The annotation is copied from kubernetes/autoscaler. 173 // Ref:https://github.com/kubernetes/autoscaler/blob/d8336cca37dbfa5d1cb7b7e453bd511172d6e5e7/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_utils.go#L256-L259 174 // Note: With the Kubernetes autoscaler it is possible to use different annotations by configuring a different 175 // "Cluster API group" than "cluster.x-k8s.io" via the "CAPI_GROUP" environment variable. 176 // We only handle the default group in our implementation. 177 // Note: It can be used by setting as top level annotation on MachineDeployment and MachineSets. 178 AutoscalerMinSizeAnnotation = "cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size" 179 180 // AutoscalerMaxSizeAnnotation defines the maximum node group size. 181 // The annotations is used by the autoscaler. 182 // The annotation definition is copied from kubernetes/autoscaler. 183 // Ref:https://github.com/kubernetes/autoscaler/blob/d8336cca37dbfa5d1cb7b7e453bd511172d6e5e7/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_utils.go#L264-L267 184 // Note: With the Kubernetes autoscaler it is possible to use different annotations by configuring a different 185 // "Cluster API group" than "cluster.x-k8s.io" via the "CAPI_GROUP" environment variable. 186 // We only handle the default group in our implementation. 187 // Note: It can be used by setting as top level annotation on MachineDeployment and MachineSets. 188 AutoscalerMaxSizeAnnotation = "cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size" 189 190 // VariableDefinitionFromInline indicates a patch or variable was defined in the `.spec` of a ClusterClass 191 // rather than from an external patch extension. 192 VariableDefinitionFromInline = "inline" 193 ) 194 195 // MachineSetPreflightCheck defines a valid MachineSet preflight check. 196 type MachineSetPreflightCheck string 197 198 const ( 199 // MachineSetPreflightCheckAll can be used to represent all the MachineSet preflight checks. 200 MachineSetPreflightCheckAll MachineSetPreflightCheck = "All" 201 202 // MachineSetPreflightCheckKubeadmVersionSkew is the name of the preflight check 203 // that verifies if the machine being created or remediated for the MachineSet conforms to the kubeadm version 204 // skew policy that requires the machine to be at the same version as the control plane. 205 // Note: This is a stopgap while the root cause of the problem is fixed in kubeadm; this check will become 206 // a no-op when this check will be available in kubeadm, and then eventually be dropped when all the 207 // supported Kuberenetes/kubeadm versions have implemented the fix. 208 // The preflight check is only run if a ControlPlane is used (controlPlaneRef must exist in the Cluster), 209 // the ControlPlane has a version, the MachineSet has a version and the MachineSet uses the Kubeadm bootstrap 210 // provider. 211 MachineSetPreflightCheckKubeadmVersionSkew MachineSetPreflightCheck = "KubeadmVersionSkew" 212 213 // MachineSetPreflightCheckKubernetesVersionSkew is the name of the preflight check that verifies 214 // if the machines being created or remediated for the MachineSet conform to the Kubernetes version skew policy 215 // that requires the machines to be at a version that is not more than 2 minor lower than the ControlPlane version. 216 // The preflight check is only run if a ControlPlane is used (controlPlaneRef must exist in the Cluster), 217 // the ControlPlane has a version and the MachineSet has a version. 218 MachineSetPreflightCheckKubernetesVersionSkew MachineSetPreflightCheck = "KubernetesVersionSkew" 219 220 // MachineSetPreflightCheckControlPlaneIsStable is the name of the preflight check 221 // that verifies if the control plane is not provisioning and not upgrading. 222 // The preflight check is only run if a ControlPlane is used (controlPlaneRef must exist in the Cluster) 223 // and the ControlPlane has a version. 224 MachineSetPreflightCheckControlPlaneIsStable MachineSetPreflightCheck = "ControlPlaneIsStable" 225 ) 226 227 // NodeUninitializedTaint can be added to Nodes at creation by the bootstrap provider, e.g. the 228 // KubeadmBootstrap provider will add the taint. 229 // This taint is used to prevent workloads to be scheduled on Nodes before the node is initialized by Cluster API. 230 // As of today the Node initialization consists of syncing labels from Machines to Nodes. Once the labels 231 // have been initially synced the taint is removed from the Node. 232 var NodeUninitializedTaint = corev1.Taint{ 233 Key: "node.cluster.x-k8s.io/uninitialized", 234 Effect: corev1.TaintEffectNoSchedule, 235 } 236 237 const ( 238 // TemplateSuffix is the object kind suffix used by template types. 239 TemplateSuffix = "Template" 240 ) 241 242 var ( 243 // ZeroDuration is a zero value of the metav1.Duration type. 244 ZeroDuration = metav1.Duration{} 245 ) 246 247 // MachineAddressType describes a valid MachineAddress type. 248 type MachineAddressType string 249 250 // Define the MachineAddressType constants. 251 const ( 252 MachineHostName MachineAddressType = "Hostname" 253 MachineExternalIP MachineAddressType = "ExternalIP" 254 MachineInternalIP MachineAddressType = "InternalIP" 255 MachineExternalDNS MachineAddressType = "ExternalDNS" 256 MachineInternalDNS MachineAddressType = "InternalDNS" 257 ) 258 259 // MachineAddress contains information for the node's address. 260 type MachineAddress struct { 261 // Machine address type, one of Hostname, ExternalIP, InternalIP, ExternalDNS or InternalDNS. 262 Type MachineAddressType `json:"type"` 263 264 // The machine address. 265 Address string `json:"address"` 266 } 267 268 // MachineAddresses is a slice of MachineAddress items to be used by infrastructure providers. 269 type MachineAddresses []MachineAddress 270 271 // ObjectMeta is metadata that all persisted resources must have, which includes all objects 272 // users must create. This is a copy of customizable fields from metav1.ObjectMeta. 273 // 274 // ObjectMeta is embedded in `Machine.Spec`, `MachineDeployment.Template` and `MachineSet.Template`, 275 // which are not top-level Kubernetes objects. Given that metav1.ObjectMeta has lots of special cases 276 // and read-only fields which end up in the generated CRD validation, having it as a subset simplifies 277 // the API and some issues that can impact user experience. 278 // 279 // During the [upgrade to controller-tools@v2](https://github.com/kubernetes-sigs/cluster-api/pull/1054) 280 // for v1alpha2, we noticed a failure would occur running Cluster API test suite against the new CRDs, 281 // specifically `spec.metadata.creationTimestamp in body must be of type string: "null"`. 282 // The investigation showed that `controller-tools@v2` behaves differently than its previous version 283 // when handling types from [metav1](k8s.io/apimachinery/pkg/apis/meta/v1) package. 284 // 285 // In more details, we found that embedded (non-top level) types that embedded `metav1.ObjectMeta` 286 // had validation properties, including for `creationTimestamp` (metav1.Time). 287 // The `metav1.Time` type specifies a custom json marshaller that, when IsZero() is true, returns `null` 288 // which breaks validation because the field isn't marked as nullable. 289 // 290 // In future versions, controller-tools@v2 might allow overriding the type and validation for embedded 291 // types. When that happens, this hack should be revisited. 292 type ObjectMeta struct { 293 // Map of string keys and values that can be used to organize and categorize 294 // (scope and select) objects. May match selectors of replication controllers 295 // and services. 296 // More info: http://kubernetes.io/docs/user-guide/labels 297 // +optional 298 Labels map[string]string `json:"labels,omitempty"` 299 300 // Annotations is an unstructured key value map stored with a resource that may be 301 // set by external tools to store and retrieve arbitrary metadata. They are not 302 // queryable and should be preserved when modifying objects. 303 // More info: http://kubernetes.io/docs/user-guide/annotations 304 // +optional 305 Annotations map[string]string `json:"annotations,omitempty"` 306 } 307 308 // Validate validates the labels and annotations in ObjectMeta. 309 func (metadata *ObjectMeta) Validate(parent *field.Path) field.ErrorList { 310 allErrs := metav1validation.ValidateLabels( 311 metadata.Labels, 312 parent.Child("labels"), 313 ) 314 allErrs = append(allErrs, apivalidation.ValidateAnnotations( 315 metadata.Annotations, 316 parent.Child("annotations"), 317 )...) 318 return allErrs 319 }