Skip to content

Commit

Permalink
Add FailureDomain to M3Cluster and Machine
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Fitzpatrick <[email protected]>
  • Loading branch information
sf1tzp committed Nov 30, 2022
1 parent 496bfb4 commit a1c0cfa
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 7 deletions.
31 changes: 24 additions & 7 deletions api/v1alpha5/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1beta1/metal3cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type Metal3ClusterStatus struct {
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`

// FailureDomains specifies the failure domains available in the cluster.
// This will be used by Cluster API to try and spread the machines across failure domains
// +optional
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`

// Ready denotes that the Metal3 cluster (infrastructure) is ready. In
// Baremetal case, it does not mean anything for now as no infrastructure
// steps need to be performed. Required by Cluster API. Set to True by the
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/metal3machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ type Metal3MachineSpec struct {
// +kubebuilder:validation:Enum:=metadata;disabled
// +optional
AutomatedCleaningMode *string `json:"automatedCleaningMode,omitempty"`

// FailureDomain is the failure domain the machine will be created in.
// +optional
FailureDomain *string `json:"failureDomain,omitempty"`
}

// Metal3MachineStatus defines the observed state of Metal3Machine.
Expand Down
12 changes: 12 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions baremetal/metal3machine_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const (
ProviderIDPrefix = "metal3://"
// ProviderLabelPrefix is a label prefix for ProviderID.
ProviderLabelPrefix = "metal3.io/uuid"
// FailureDomainLabelPrefix is a label prefix for FailureDomains
// TODO: Should this be customizable by an operator?
FailureDomainLabelPrefix = "infrastructure.cluster.x-k8s.io/failure-domain"
)

var (
Expand Down Expand Up @@ -889,6 +892,14 @@ func (m *MachineManager) chooseHost(ctx context.Context) (*bmov1alpha1.BareMetal
}
reqs = append(reqs, *r)
}
if m.Metal3Machine.Spec.FailureDomain != nil {
r, err := labels.NewRequirement(FailureDomainLabelPrefix, selection.Equals, []string{*m.Metal3Machine.Spec.FailureDomain})
if err != nil {
m.Log.Error(err, "Failed to create FailureDomain MatchLabel requirement, not choosing host")
return nil, nil, err
}
reqs = append(reqs, *r)
}
labelSelector = labelSelector.Add(reqs...)

availableHosts := []*bmov1alpha1.BareMetalHost{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ spec:
- type
type: object
type: array
failureDomains:
additionalProperties:
description: FailureDomainSpec is the Schema for Cluster API failure
domains. It allows controllers to understand how many failure
domains a cluster can optionally span across.
properties:
attributes:
additionalProperties:
type: string
description: Attributes is a free form map of attributes an
infrastructure provider might use or require.
type: object
controlPlane:
description: ControlPlane determines if this failure domain
is suitable for use by control plane machines.
type: boolean
type: object
description: FailureDomains specifies the list of unique failure domains
available in the cluster. The list will be used by Cluster API to
try and spread the machines across failure domains
type: object
failureMessage:
description: FailureMessage indicates that there is a fatal problem
reconciling the state, and will be set to a descriptive error message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
failureDomain:
description: FailureDomain is the failure domain the machine will
be created in.
type: string
hostSelector:
description: HostSelector specifies matching criteria for labels on
BareMetalHosts. This is used to limit the set of BareMetalHost objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
failureDomain:
description: FailureDomain is the failure domain the machine
will be created in.
type: string
hostSelector:
description: HostSelector specifies matching criteria for
labels on BareMetalHosts. This is used to limit the set
Expand Down

0 comments on commit a1c0cfa

Please sign in to comment.