|
| 1 | +/* |
| 2 | +
|
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + "k8s.io/apimachinery/pkg/selection" |
| 23 | +) |
| 24 | + |
| 25 | +const ( |
| 26 | + // Finalizer for HostClaims that are handled by the hostclaim_controller. |
| 27 | + HostFinalizer = "metal3.io/hostclaim" |
| 28 | + |
| 29 | + // AssociateCondition documents the status of the association of HostClaim with a BareMetalHost. |
| 30 | + AssociationCondition = "Association" |
| 31 | + |
| 32 | + // BareMetalHostAssociatedReason is the reason used when the Metal3Machine is successfully associated with a BareMetalHost. |
| 33 | + BareMetalHostAssociatedReason = "BareMetalHostAssociated" |
| 34 | + // MissingBareMetalHostReason is a reason used when the associated BareMetalHost is no more found. |
| 35 | + MissingBareMetalHostReason = "MissingBareMetalHost" |
| 36 | + // NoBareMetalHostReason is a reason used when no BareMetalHost matching the constraints is found. |
| 37 | + NoBareMetalHostReason = "NoBareMetalHost" |
| 38 | + // BadBareMetalHostStatusReason is a reason used when the status of the associated BareMetalHost cannot be marshalled. |
| 39 | + BadBareMetalHostStatusReason = "BadBareMetalHostStatus" |
| 40 | + // HostClaimAnnotationNotSetReason is a reason used when the annotation on the hostclaim cannot be set. |
| 41 | + HostClaimAnnotationNotSetReason = "HostClaimAnnotationNotSet" |
| 42 | + // PauseAnnotationSetFailedReason is a reason used when propagating the pause annotation fails. |
| 43 | + PauseAnnotationSetFailedReason = "PauseAnnotationSetFailed" |
| 44 | + // PauseAnnotationRemoveFailedReason is a reason used when the removal of the pause annotation fails. |
| 45 | + PauseAnnotationRemoveFailedReason = "PauseAnnotationRemoveFailed" |
| 46 | + // HostPausedReason is a reason used when Host or Cluster is paused. |
| 47 | + HostPausedReason = "HostPaused" |
| 48 | + // HostClaimDeletingReason is used while the hostclaim is being deleted. |
| 49 | + HostClaimDeletingReason = "HostClaimDeleting" |
| 50 | + // HostClaimDeletionFailedReason is used when the deletion of hostclaim encountered an unexpected error. |
| 51 | + HostClaimDeletionFailedReason = "HostClaimDeletionFailed" |
| 52 | + |
| 53 | + // SynchronizationCondition documents the status of the transfer of information from the |
| 54 | + // HostClaim to the BareMetalHost. |
| 55 | + SynchronizationCondition = "Synchronization" |
| 56 | + |
| 57 | + // ConfigurationSyncedReason is the reason used when the synchronization of secrets is successful. |
| 58 | + ConfigurationSyncedReason = "ConfigurationSynced" |
| 59 | + // BadUserDataSecretReason is a reason used when the secret for user data cannot be synchronized. |
| 60 | + BadUserDataSecretReason = "UserDataSecretSyncFailure" |
| 61 | + // BadMetaDataSecretReason is a reason used when the secret for meta data cannot be synchronized. |
| 62 | + BadMetaDataSecretReason = "MetaDataSecretSyncFailure" |
| 63 | + // BadNetworkDataSecretReason is a reason used when the secret for meta data cannot be synchronized. |
| 64 | + BadNetworkDataSecretReason = "NetworkDataSecretSyncFailure" |
| 65 | + // BareMetalHostNotSynchronizedReason is the reason used when the synchronization of BareMetalHost state |
| 66 | + // is not successful. |
| 67 | + BareMetalHostNotSynchronizedReason = "BareMetalHostNotSynchronized" |
| 68 | + |
| 69 | + // ProvisionedCondition documents the provisioning state of the associated BareMetalHost toward the Provisioned goal |
| 70 | + // Reasons are values of ProvisioningState type. |
| 71 | + ProvisionedCondition = "Provisioned" |
| 72 | +) |
| 73 | + |
| 74 | +// HostClaimSpec defines the desired state of HostClaim. |
| 75 | +type HostClaimSpec struct { |
| 76 | + // Should the compute resource be powered on? Changing this value will trigger |
| 77 | + // a change in power state of the targeted host. |
| 78 | + Online bool `json:"online"` |
| 79 | + |
| 80 | + // Image holds the details of the image to be provisioned. Populating |
| 81 | + // the image will cause the target host to start provisioning. |
| 82 | + Image *Image `json:"image,omitempty"` |
| 83 | + |
| 84 | + // UserData holds the reference to the Secret containing the user data |
| 85 | + // which is passed to the Config Drive and interpreted by the |
| 86 | + // first-boot software such as cloud-init. The format of user data is |
| 87 | + // specific to the first-boot software. |
| 88 | + UserData *corev1.SecretReference `json:"userData,omitempty"` |
| 89 | + |
| 90 | + // NetworkData holds the reference to the Secret containing network |
| 91 | + // configuration which is passed to the Config Drive and interpreted |
| 92 | + // by the first boot software such as cloud-init. |
| 93 | + NetworkData *corev1.SecretReference `json:"networkData,omitempty"` |
| 94 | + |
| 95 | + // MetaData holds the reference to the Secret containing host metadata |
| 96 | + // (e.g. meta_data.json) which is passed to the Config Drive. |
| 97 | + MetaData *corev1.SecretReference `json:"metaData,omitempty"` |
| 98 | + |
| 99 | + // A custom deploy procedure. This is an advanced feature that allows |
| 100 | + // using a custom deploy step provided by a site-specific deployment |
| 101 | + // ramdisk. Most users will want to use "image" instead. Setting this |
| 102 | + // field triggers provisioning. |
| 103 | + // +optional |
| 104 | + CustomDeploy *CustomDeploy `json:"customDeploy,omitempty"` |
| 105 | + |
| 106 | + // When set to disabled, automated cleaning of host disks will be skipped |
| 107 | + // during provisioning and deprovisioning. |
| 108 | + // +kubebuilder:validation:Enum:=metadata;disabled |
| 109 | + // +optional |
| 110 | + AutomatedCleaningMode *AutomatedCleaningMode `json:"automatedCleaningMode,omitempty"` |
| 111 | + |
| 112 | + // HostSelector specifies matching criteria for labels on BareMetalHosts. |
| 113 | + // This is used to limit the set of BareMetalHost objects considered for |
| 114 | + // claiming for a metal3machine. |
| 115 | + // +optional |
| 116 | + HostSelector HostSelector `json:"hostSelector,omitempty"` |
| 117 | + |
| 118 | + // ConsumerRef can be used to store information about something |
| 119 | + // that is using a host. When it is not empty, the host is |
| 120 | + // considered "in use". The common use case is a link to a Machine |
| 121 | + // resource when the host is used by Cluster API. |
| 122 | + ConsumerRef *corev1.ObjectReference `json:"consumerRef,omitempty"` |
| 123 | +} |
| 124 | + |
| 125 | +// HostSelector specifies matching criteria for labels on BareMetalHosts. |
| 126 | +// This is used to limit the set of BareMetalHost objects considered for |
| 127 | +// claiming for a Machine. |
| 128 | +type HostSelector struct { |
| 129 | + // Key/value pairs of labels that must exist on a chosen BareMetalHost |
| 130 | + // +optional |
| 131 | + MatchLabels map[string]string `json:"matchLabels,omitempty"` |
| 132 | + |
| 133 | + // Label match expressions that must be true on a chosen BareMetalHost |
| 134 | + // +optional |
| 135 | + MatchExpressions []HostSelectorRequirement `json:"matchExpressions,omitempty"` |
| 136 | + |
| 137 | + // InNamespace specifies a single namespace where the BareMetalHost should |
| 138 | + // reside. If not specified, the selection will be done over all available |
| 139 | + // namespaces with a compliant policy. |
| 140 | + // +optional |
| 141 | + InNamespace string `json:"inNamespace,omitempty"` |
| 142 | +} |
| 143 | + |
| 144 | +type HostSelectorRequirement struct { |
| 145 | + Key string `json:"key"` |
| 146 | + Operator selection.Operator `json:"operator"` |
| 147 | + Values []string `json:"values"` |
| 148 | +} |
| 149 | + |
| 150 | +// HostClaimStatus defines the observed state of HostClaim. |
| 151 | +type HostClaimStatus struct { |
| 152 | + // LastUpdated identifies when this status was last observed. |
| 153 | + // +optional |
| 154 | + LastUpdated *metav1.Time `json:"lastUpdated,omitempty"` |
| 155 | + // Conditions defines current service state of the HostClaim. |
| 156 | + // +optional |
| 157 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 158 | + // HardwareData is a pointer to the name of the bound HardwareData |
| 159 | + // structure. |
| 160 | + // +optional |
| 161 | + HardwareData *HardwareReference `json:"hardwareData,omitempty"` |
| 162 | + // HostUID is the UID of the underlying compute. It is used |
| 163 | + // as ID by the capm3 controller. |
| 164 | + // +optional |
| 165 | + HostUID string `json:"hostUID,omitempty"` |
| 166 | + // The currently detected power state of the host. This field may get |
| 167 | + // briefly out of sync with the actual state of the hardware while |
| 168 | + // provisioning processes are running. |
| 169 | + PoweredOn bool `json:"poweredOn,omitempty"` |
| 170 | +} |
| 171 | + |
| 172 | +// GetConditions returns the set of conditions for this object. |
| 173 | +func (h *HostClaim) GetConditions() []metav1.Condition { |
| 174 | + return h.Status.Conditions |
| 175 | +} |
| 176 | + |
| 177 | +// SetConditions sets conditions for an API object. |
| 178 | +func (h *HostClaim) SetConditions(conditions []metav1.Condition) { |
| 179 | + h.Status.Conditions = conditions |
| 180 | +} |
| 181 | + |
| 182 | +type HardwareReference struct { |
| 183 | + // `namespace` is the namespace of the HardwareDetail bound |
| 184 | + Namespace string `json:"namespace"` |
| 185 | + // `name` is the name of the HardwareDetail bound |
| 186 | + Name string `json:"name"` |
| 187 | +} |
| 188 | + |
| 189 | +//+kubebuilder:object:root=true |
| 190 | +//+kubebuilder:subresource:status |
| 191 | + |
| 192 | +// HostClaim is the Schema for the hostclaims API. |
| 193 | +type HostClaim struct { |
| 194 | + metav1.TypeMeta `json:",inline"` |
| 195 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 196 | + |
| 197 | + Spec HostClaimSpec `json:"spec,omitempty"` |
| 198 | + Status HostClaimStatus `json:"status,omitempty"` |
| 199 | +} |
| 200 | + |
| 201 | +//+kubebuilder:object:root=true |
| 202 | + |
| 203 | +// HostClaimList contains a list of HostClaim. |
| 204 | +type HostClaimList struct { |
| 205 | + metav1.TypeMeta `json:",inline"` |
| 206 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 207 | + Items []HostClaim `json:"items"` |
| 208 | +} |
| 209 | + |
| 210 | +func init() { |
| 211 | + SchemeBuilder.Register(&HostClaim{}, &HostClaimList{}) |
| 212 | +} |
0 commit comments