Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion capi-lab/mini-lab
26 changes: 13 additions & 13 deletions capi-lab/mini-lab-overrides/extra-vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ metal_partition_metal_api_basepath: "/"
metal_partition_mgmt_gateway: 203.0.113.1

metal_api_images:
- id: firewall-ubuntu-3.0
name: Firewall 3 Ubuntu
description: Firewall 3 Ubuntu Latest Release
url: https://images.metal-stack.io/metal-os/stable/firewall/3.0-ubuntu/img.tar.lz4
features:
- firewall
- id: ubuntu-24.04
name: Ubuntu 24.04 with Kubernetes 1.30.6
description: Ubuntu 24.04 with Kubernetes 1.30.6
url: https://images.metal-stack.io/metal-os/pull_requests/273-cluster-api-k8s-v1.30.6/cluster-api/cluster-api-k8s-1.30.6/img.tar.lz4
features:
- machine
- id: firewall-ubuntu-3.0
name: Firewall 3 Ubuntu
description: Firewall 3 Ubuntu Latest Release
url: https://images.metal-stack.io/metal-os/stable/firewall/3.0-ubuntu/img.tar.lz4
features:
- firewall
- id: ubuntu-24.04
name: Ubuntu 24.04 with Kubernetes 1.30.6
description: Ubuntu 24.04 with Kubernetes 1.30.6
url: https://images.metal-stack.io/metal-os/pull_requests/273-cluster-api-k8s-v1.30.6/cluster-api/cluster-api-k8s-1.30.6/img.tar.lz4
features:
- machine

sonic_mgmtif_gateway: "203.0.113.1"

sonic_nameservers:
- "203.0.113.1"
- "1.1.1.1"
- "1.0.0.1"
- "1.0.0.1"
38 changes: 37 additions & 1 deletion internal/controller/metalstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func (r *machineReconciler) reconcile() (ctrl.Result, error) {
}
r.infraMachine.Spec.ProviderID = encodeProviderID(m)

r.patchMachineLabels(m)

result := ctrl.Result{}

isReady, err := r.getMachineStatus(m)
Expand Down Expand Up @@ -296,7 +298,7 @@ func (r *machineReconciler) create() (*models.V1MachineResponse, error) {
Partitionid: &r.infraCluster.Spec.Partition,
Projectid: &r.infraCluster.Spec.ProjectID,
PlacementTags: []string{tag.New(tag.ClusterID, string(r.infraCluster.GetUID()))},
Tags: r.machineTags(),
Tags: append(r.machineTags(), r.additionalMachineTags()...),
Name: r.infraMachine.Name,
Hostname: r.infraMachine.Name,
Sizeid: &r.infraMachine.Spec.Size,
Expand Down Expand Up @@ -392,6 +394,31 @@ func (r *machineReconciler) findProviderMachine() (*models.V1MachineResponse, er
}
}

func (r *machineReconciler) patchMachineLabels(m *models.V1MachineResponse) {
if r.infraMachine.Labels == nil {
r.infraMachine.Labels = make(map[string]string)
}

if m.Allocation != nil && m.Allocation.Hostname != nil {
r.infraMachine.Labels[corev1.LabelHostname] = *m.Allocation.Hostname
}
if m.Partition != nil && m.Partition.ID != nil {
r.infraMachine.Labels[corev1.LabelTopologyZone] = *m.Partition.ID
}
if m.Rackid != "" {
r.infraMachine.Labels[tag.MachineRack] = m.Rackid
}

tagMap := tag.NewTagMap(m.Tags)

if asn, ok := tagMap.Value(tag.MachineNetworkPrimaryASN); ok {
r.infraMachine.Labels[tag.MachineNetworkPrimaryASN] = asn
}
if chassis, ok := tagMap.Value(tag.MachineChassis); ok {
r.infraMachine.Labels[tag.MachineChassis] = chassis
}
}

func (r *machineReconciler) machineTags() []string {
tags := []string{
tag.New(tag.ClusterID, string(r.infraCluster.GetUID())),
Expand All @@ -405,6 +432,15 @@ func (r *machineReconciler) machineTags() []string {
return tags
}

func (r *machineReconciler) additionalMachineTags() []string {
tags := []string{
tag.New(corev1.LabelTopologyZone, r.infraCluster.Spec.Partition),
tag.New(corev1.LabelHostname, r.infraMachine.Name),
}

return tags
}

func encodeProviderID(m *models.V1MachineResponse) string {
return fmt.Sprintf("metal://%s/%s", pointer.SafeDeref(pointer.SafeDeref(m.Partition).ID), pointer.SafeDeref(m.ID))
}
Expand Down
Loading