diff --git a/capi-lab/mini-lab b/capi-lab/mini-lab index 4b32d5e..72acbfb 160000 --- a/capi-lab/mini-lab +++ b/capi-lab/mini-lab @@ -1 +1 @@ -Subproject commit 4b32d5e16de1b5205ffc1deaa1e1731a9c7c913b +Subproject commit 72acbfbffce1866ea6ac8352f38506c5e2f95291 diff --git a/capi-lab/mini-lab-overrides/extra-vars.yaml b/capi-lab/mini-lab-overrides/extra-vars.yaml index afe306e..659ff4d 100644 --- a/capi-lab/mini-lab-overrides/extra-vars.yaml +++ b/capi-lab/mini-lab-overrides/extra-vars.yaml @@ -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" \ No newline at end of file + - "1.0.0.1" diff --git a/internal/controller/metalstackmachine_controller.go b/internal/controller/metalstackmachine_controller.go index e38dfac..be2f305 100644 --- a/internal/controller/metalstackmachine_controller.go +++ b/internal/controller/metalstackmachine_controller.go @@ -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) @@ -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, @@ -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())), @@ -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)) }