Skip to content

Commit a16ce85

Browse files
committed
HostClaim custom resources
Adds declarations for HostClaims and HostDeployPolicy custom resources. Placeholder for a HostClaim controller. HostDeployPolicy are mostly declarations guiding the selection process of the HostClaim controller. Co-authored-by: Pierre Crégut <[email protected]> Co-authored-by: Laurent Roussarie <[email protected]> Signed-off-by: Pierre Crégut <[email protected]>
1 parent 98bcf92 commit a16ce85

21 files changed

+1813
-0
lines changed

PROJECT

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: metal3.io
26
layout:
37
- go.kubebuilder.io/v3
@@ -96,4 +100,22 @@ resources:
96100
kind: HostUpdatePolicy
97101
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
98102
version: v1alpha1
103+
- api:
104+
crdVersion: v1
105+
namespaced: true
106+
controller: true
107+
domain: metal3.io
108+
group: metal3.io
109+
kind: HostClaim
110+
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
111+
version: v1alpha1
112+
- api:
113+
crdVersion: v1
114+
namespaced: true
115+
controller: true
116+
domain: metal3.io
117+
group: metal3.io
118+
kind: HostDeployPolicy
119+
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
120+
version: v1alpha1
99121
version: "3"
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
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+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// HostDeployPolicySpec defines the desired state of HostDeployPolicy.
24+
type HostDeployPolicySpec struct {
25+
HostclaimNamespaces *HostclaimNamespaces `json:"hostclaimNamespaces,omitempty"`
26+
}
27+
28+
type HostclaimNamespaces struct {
29+
// Namespaces is a list of namespace names where the hostClaim is authorized to reside in.
30+
Names []string `json:"names,omitempty"`
31+
// NameMatches is a string interpreted as a regular expression that must be matched by the
32+
// namespace of the HostClaim.
33+
NameMatches string `json:"nameMatches,omitempty"`
34+
// HasLabels is a list of label names and their associated value.
35+
// The namespace should have all of those labels. If the value
36+
// is specified, it must also match.
37+
HasLabels []NameValuePair `json:"hasLabels,omitempty"`
38+
}
39+
40+
type NameValuePair struct {
41+
// Name of the expected label.
42+
Name string `json:"name"`
43+
// If specified, expected value of the label.
44+
Value string `json:"value,omitempty"`
45+
}
46+
47+
// HostDeployPolicyStatus defines the observed state of HostDeployPolicy.
48+
type HostDeployPolicyStatus struct {
49+
}
50+
51+
//+kubebuilder:object:root=true
52+
//+kubebuilder:subresource:status
53+
54+
// HostDeployPolicy is the Schema for the hostdeploypolicies API.
55+
type HostDeployPolicy struct {
56+
metav1.TypeMeta `json:",inline"`
57+
metav1.ObjectMeta `json:"metadata,omitempty"`
58+
59+
Spec HostDeployPolicySpec `json:"spec,omitempty"`
60+
Status HostDeployPolicyStatus `json:"status,omitempty"`
61+
}
62+
63+
//+kubebuilder:object:root=true
64+
65+
// HostDeployPolicyList contains a list of HostDeployPolicy.
66+
type HostDeployPolicyList struct {
67+
metav1.TypeMeta `json:",inline"`
68+
metav1.ListMeta `json:"metadata,omitempty"`
69+
Items []HostDeployPolicy `json:"items"`
70+
}
71+
72+
func init() {
73+
SchemeBuilder.Register(&HostDeployPolicy{}, &HostDeployPolicyList{})
74+
}

0 commit comments

Comments
 (0)