From f94a01febd783f20d2477aa296add1bd68c526d2 Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Tue, 22 Apr 2025 03:31:37 +0300 Subject: [PATCH] Indicate the IP address pool and storage class When populating the WorkloadMonitor objects, the status field is now populated with a specially formatted string, mimicking the keys of ResourceQuota.spec.hard, e.g. `.storageclass.storage.k8s.io/requests.storage` or `.ipaddresspool.metallb.io/requests.ipaddresses` so the storage class or IP pool in use can be tracked. Part of #788. Signed-off-by: Timofei Larkin --- .../controller/workloadmonitor_controller.go | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/controller/workloadmonitor_controller.go b/internal/controller/workloadmonitor_controller.go index 1c23a749..330d1dc5 100644 --- a/internal/controller/workloadmonitor_controller.go +++ b/internal/controller/workloadmonitor_controller.go @@ -116,15 +116,24 @@ func (r *WorkloadMonitorReconciler) reconcileServiceForMonitor( resources := make(map[string]resource.Quantity) - q := resource.MustParse("0") + quantity := resource.MustParse("0") for _, ing := range svc.Status.LoadBalancer.Ingress { if ing.IP != "" { - q.Add(resource.MustParse("1")) + quantity.Add(resource.MustParse("1")) } } - resources["public-ips"] = q + var resourceLabel string + if svc.Annotations != nil { + var ok bool + resourceLabel, ok = svc.Annotations["metallb.universe.tf/ip-allocated-from-pool"] + if !ok { + resourceLabel = "default" + } + } + resourceLabel = fmt.Sprintf("%s.ipaddresspool.metallb.io/requests.ipaddresses", resourceLabel) + resources[resourceLabel] = quantity _, err := ctrl.CreateOrUpdate(ctx, r.Client, workload, func() error { // Update owner references with the new monitor @@ -165,7 +174,12 @@ func (r *WorkloadMonitorReconciler) reconcilePVCForMonitor( resources := make(map[string]resource.Quantity) for resourceName, resourceQuantity := range pvc.Status.Capacity { - resources[resourceName.String()] = resourceQuantity + storageClass := "default" + if pvc.Spec.StorageClassName != nil || *pvc.Spec.StorageClassName == "" { + storageClass = *pvc.Spec.StorageClassName + } + resourceLabel := fmt.Sprintf("%s.storageclass.storage.k8s.io/requests.%s", storageClass, resourceName.String()) + resources[resourceLabel] = resourceQuantity } _, err := ctrl.CreateOrUpdate(ctx, r.Client, workload, func() error {