Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion pkg/maas/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (s *Service) DeployMachine(userDataB64 string) (_ *infrav1beta1.Machine, re
}

// For HCP clusters, control-plane must be bare metal: exclude pod-backed VM hosts
s.scope.Info("Allocating bare metal machine for CP under HCP", "machine", mm.Name)
if s.scope.IsControlPlane() && s.scope.ClusterScope.IsLXDHostEnabled() {
allocator.WithNotPod(true)
allocator.WithNotPodType("lxd")
Expand All @@ -162,6 +161,35 @@ func (s *Service) DeployMachine(userDataB64 string) (_ *infrav1beta1.Machine, re
return nil, errors.Wrapf(err, "Unable to allocate machine")
}

// Validate that allocated machine matches requested constraints
allocatedZone := m.ZoneName()
allocatedPool := m.ResourcePoolName()

// Check zone constraint
if failureDomain != nil && *failureDomain != "" && allocatedZone != *failureDomain {
// Release the machine since it doesn't match requirements
if _, releaseErr := m.Releaser().Release(ctx); releaseErr != nil {
s.scope.Error(releaseErr, "Failed to release machine that doesn't match zone requirement",
"system-id", m.SystemID(), "required-zone", *failureDomain, "allocated-zone", allocatedZone)
}
return nil, errors.Errorf("Machine allocated in zone '%s' (required: '%s'); machine %s released because it does not meet zone requirement.",
allocatedZone, *failureDomain, m.SystemID())
}

// Check resource pool constraint
if mm.Spec.ResourcePool != nil && *mm.Spec.ResourcePool != "" && allocatedPool != *mm.Spec.ResourcePool {
// Release the machine since it doesn't match requirements
if _, releaseErr := m.Releaser().Release(ctx); releaseErr != nil {
s.scope.Error(releaseErr, "Failed to release machine that doesn't match resource pool requirement",
"system-id", m.SystemID(), "required-pool", *mm.Spec.ResourcePool, "allocated-pool", allocatedPool)
}
return nil, errors.Errorf("Machine allocated in pool '%s' (required: '%s'); machine %s released because it does not meet resource pool requirement.",
allocatedPool, *mm.Spec.ResourcePool, m.SystemID())
}

s.scope.Info("Machine allocation validated successfully",
"system-id", m.SystemID(), "zone", allocatedZone, "pool", allocatedPool)

// Backstop: If MAAS still returned a VM host, reject it for HCP control-plane
if s.scope.IsControlPlane() && s.scope.ClusterScope.IsLXDHostEnabled() {
pt := strings.ToLower(m.PowerType())
Expand Down