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