1 package v1beta1 2 3 import ( 4 corev1 "k8s.io/api/core/v1" 5 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 6 "k8s.io/apimachinery/pkg/runtime" 7 ) 8 9 // ProviderSpec defines the configuration to use during node creation. 10 type ProviderSpec struct { 11 12 // No more than one of the following may be specified. 13 14 // Value is an inlined, serialized representation of the resource 15 // configuration. It is recommended that providers maintain their own 16 // versioned API types that should be serialized/deserialized from this 17 // field, akin to component config. 18 // +optional 19 // +kubebuilder:validation:XPreserveUnknownFields 20 Value *runtime.RawExtension `json:"value,omitempty"` 21 } 22 23 // ObjectMeta is metadata that all persisted resources must have, which includes all objects 24 // users must create. This is a copy of customizable fields from metav1.ObjectMeta. 25 // 26 // ObjectMeta is embedded in `Machine.Spec`, `MachineDeployment.Template` and `MachineSet.Template`, 27 // which are not top-level Kubernetes objects. Given that metav1.ObjectMeta has lots of special cases 28 // and read-only fields which end up in the generated CRD validation, having it as a subset simplifies 29 // the API and some issues that can impact user experience. 30 // 31 // During the [upgrade to controller-tools@v2](https://github.com/kubernetes-sigs/cluster-api/pull/1054) 32 // for v1alpha2, we noticed a failure would occur running Cluster API test suite against the new CRDs, 33 // specifically `spec.metadata.creationTimestamp in body must be of type string: "null"`. 34 // The investigation showed that `controller-tools@v2` behaves differently than its previous version 35 // when handling types from [metav1](k8s.io/apimachinery/pkg/apis/meta/v1) package. 36 // 37 // In more details, we found that embedded (non-top level) types that embedded `metav1.ObjectMeta` 38 // had validation properties, including for `creationTimestamp` (metav1.Time). 39 // The `metav1.Time` type specifies a custom json marshaller that, when IsZero() is true, returns `null` 40 // which breaks validation because the field isn't marked as nullable. 41 // 42 // In future versions, controller-tools@v2 might allow overriding the type and validation for embedded 43 // types. When that happens, this hack should be revisited. 44 type ObjectMeta struct { 45 // Name must be unique within a namespace. Is required when creating resources, although 46 // some resources may allow a client to request the generation of an appropriate name 47 // automatically. Name is primarily intended for creation idempotence and configuration 48 // definition. 49 // Cannot be updated. 50 // More info: http://kubernetes.io/docs/user-guide/identifiers#names 51 // +optional 52 Name string `json:"name,omitempty"` 53 54 // GenerateName is an optional prefix, used by the server, to generate a unique 55 // name ONLY IF the Name field has not been provided. 56 // If this field is used, the name returned to the client will be different 57 // than the name passed. This value will also be combined with a unique suffix. 58 // The provided value has the same validation rules as the Name field, 59 // and may be truncated by the length of the suffix required to make the value 60 // unique on the server. 61 // 62 // If this field is specified and the generated name exists, the server will 63 // NOT return a 409 - instead, it will either return 201 Created or 500 with Reason 64 // ServerTimeout indicating a unique name could not be found in the time allotted, and the client 65 // should retry (optionally after the time indicated in the Retry-After header). 66 // 67 // Applied only if Name is not specified. 68 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency 69 // +optional 70 GenerateName string `json:"generateName,omitempty"` 71 72 // Namespace defines the space within each name must be unique. An empty namespace is 73 // equivalent to the "default" namespace, but "default" is the canonical representation. 74 // Not all objects are required to be scoped to a namespace - the value of this field for 75 // those objects will be empty. 76 // 77 // Must be a DNS_LABEL. 78 // Cannot be updated. 79 // More info: http://kubernetes.io/docs/user-guide/namespaces 80 // +optional 81 Namespace string `json:"namespace,omitempty"` 82 83 // Map of string keys and values that can be used to organize and categorize 84 // (scope and select) objects. May match selectors of replication controllers 85 // and services. 86 // More info: http://kubernetes.io/docs/user-guide/labels 87 // +optional 88 Labels map[string]string `json:"labels,omitempty"` 89 90 // Annotations is an unstructured key value map stored with a resource that may be 91 // set by external tools to store and retrieve arbitrary metadata. They are not 92 // queryable and should be preserved when modifying objects. 93 // More info: http://kubernetes.io/docs/user-guide/annotations 94 // +optional 95 Annotations map[string]string `json:"annotations,omitempty"` 96 97 // List of objects depended by this object. If ALL objects in the list have 98 // been deleted, this object will be garbage collected. If this object is managed by a controller, 99 // then an entry in this list will point to this controller, with the controller field set to true. 100 // There cannot be more than one managing controller. 101 // +optional 102 // +patchMergeKey=uid 103 // +patchStrategy=merge 104 OwnerReferences []metav1.OwnerReference `json:"ownerReferences,omitempty" patchStrategy:"merge" patchMergeKey:"uid"` 105 } 106 107 // ConditionSeverity expresses the severity of a Condition Type failing. 108 type ConditionSeverity string 109 110 const ( 111 // ConditionSeverityError specifies that a condition with `Status=False` is an error. 112 ConditionSeverityError ConditionSeverity = "Error" 113 114 // ConditionSeverityWarning specifies that a condition with `Status=False` is a warning. 115 ConditionSeverityWarning ConditionSeverity = "Warning" 116 117 // ConditionSeverityInfo specifies that a condition with `Status=False` is informative. 118 ConditionSeverityInfo ConditionSeverity = "Info" 119 120 // ConditionSeverityNone should apply only to conditions with `Status=True`. 121 ConditionSeverityNone ConditionSeverity = "" 122 ) 123 124 // ConditionType is a valid value for Condition.Type. 125 type ConditionType string 126 127 // Valid conditions for a machine. 128 const ( 129 // MachineCreated indicates whether the machine has been created or not. If not, 130 // it should include a reason and message for the failure. 131 // NOTE: MachineCreation is here for historical reasons, MachineCreated should be used instead 132 MachineCreation ConditionType = "MachineCreation" 133 // MachineCreated indicates whether the machine has been created or not. If not, 134 // it should include a reason and message for the failure. 135 MachineCreated ConditionType = "MachineCreated" 136 // InstanceExistsCondition is set on the Machine to show whether a virtual mahcine has been created by the cloud provider. 137 InstanceExistsCondition ConditionType = "InstanceExists" 138 // RemediationAllowedCondition is set on MachineHealthChecks to show the status of whether the MachineHealthCheck is 139 // allowed to remediate any Machines or whether it is blocked from remediating any further. 140 RemediationAllowedCondition ConditionType = "RemediationAllowed" 141 // ExternalRemediationTemplateAvailable is set on machinehealthchecks when MachineHealthCheck controller uses external remediation. 142 // ExternalRemediationTemplateAvailable is set to false if external remediation template is not found. 143 ExternalRemediationTemplateAvailable ConditionType = "ExternalRemediationTemplateAvailable" 144 // ExternalRemediationRequestAvailable is set on machinehealthchecks when MachineHealthCheck controller uses external remediation. 145 // ExternalRemediationRequestAvailable is set to false if creating external remediation request fails. 146 ExternalRemediationRequestAvailable ConditionType = "ExternalRemediationRequestAvailable" 147 // MachineDrained is set on a machine to indicate that the machine has been drained. When an error occurs during 148 // the drain process, the condition will be added with a false status and details of the error. 149 MachineDrained ConditionType = "Drained" 150 // MachineDrainable is set on a machine to indicate whether or not the machine can be drained, or, whether some 151 // deletion hook is blocking the drain operation. 152 MachineDrainable ConditionType = "Drainable" 153 // MachineTerminable is set on a machine to indicate whether or not the machine can be terminated, or, whether some 154 // deletion hook is blocking the termination operation. 155 MachineTerminable ConditionType = "Terminable" 156 ) 157 158 const ( 159 // MachineCreationSucceeded indicates machine creation success. 160 MachineCreationSucceededConditionReason string = "MachineCreationSucceeded" 161 // MachineCreationFailed indicates machine creation failure. 162 MachineCreationFailedConditionReason string = "MachineCreationFailed" 163 // ErrorCheckingProviderReason is the reason used when the exist operation fails. 164 // This would normally be because we cannot contact the provider. 165 ErrorCheckingProviderReason = "ErrorCheckingProvider" 166 // InstanceMissingReason is the reason used when the machine was provisioned, but the instance has gone missing. 167 InstanceMissingReason = "InstanceMissing" 168 // InstanceNotCreatedReason is the reason used when the machine has not yet been provisioned. 169 InstanceNotCreatedReason = "InstanceNotCreated" 170 // TooManyUnhealthy is the reason used when too many Machines are unhealthy and the MachineHealthCheck is blocked 171 // from making any further remediations. 172 TooManyUnhealthyReason = "TooManyUnhealthy" 173 // ExternalRemediationTemplateNotFound is the reason used when a machine health check fails to find external remediation template. 174 ExternalRemediationTemplateNotFound = "ExternalRemediationTemplateNotFound" 175 // ExternalRemediationRequestCreationFailed is the reason used when a machine health check fails to create external remediation request. 176 ExternalRemediationRequestCreationFailed = "ExternalRemediationRequestCreationFailed" 177 // MachineHookPresent indicates that a machine lifecycle hook is blocking part of the lifecycle of the machine. 178 // This should be used with the `Drainable` and `Terminable` machine condition types. 179 MachineHookPresent = "HookPresent" 180 // MachineDrainError indicates an error occurred when draining the machine. 181 // This should be used with the `Drained` condition type. 182 MachineDrainError = "DrainError" 183 ) 184 185 // Condition defines an observation of a Machine API resource operational state. 186 type Condition struct { 187 // Type of condition in CamelCase or in foo.example.com/CamelCase. 188 // Many .condition.type values are consistent across resources like Available, but because arbitrary conditions 189 // can be useful (see .node.status.conditions), the ability to deconflict is important. 190 // +required 191 Type ConditionType `json:"type"` 192 193 // Status of the condition, one of True, False, Unknown. 194 // +required 195 Status corev1.ConditionStatus `json:"status"` 196 197 // Severity provides an explicit classification of Reason code, so the users or machines can immediately 198 // understand the current situation and act accordingly. 199 // The Severity field MUST be set only when Status=False. 200 // +optional 201 Severity ConditionSeverity `json:"severity,omitempty"` 202 203 // Last time the condition transitioned from one status to another. 204 // This should be when the underlying condition changed. If that is not known, then using the time when 205 // the API field changed is acceptable. 206 // +required 207 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` 208 209 // The reason for the condition's last transition in CamelCase. 210 // The specific API may choose whether or not this field is considered a guaranteed API. 211 // This field may not be empty. 212 // +optional 213 Reason string `json:"reason,omitempty"` 214 215 // A human readable message indicating details about the transition. 216 // This field may be empty. 217 // +optional 218 Message string `json:"message,omitempty"` 219 } 220 221 // Conditions provide observations of the operational state of a Machine API resource. 222 type Conditions []Condition 223