From b0512eee813844bb8cd1acbc3107b54ada4332ab Mon Sep 17 00:00:00 2001 From: VoigtS Date: Fri, 6 Dec 2024 14:19:08 +0100 Subject: [PATCH] change sort function naming. Adjust set quota value assignment --- internal/plugins/capacity_liquid.go | 2 +- internal/plugins/liquid.go | 6 ++---- internal/plugins/utils.go | 6 +++--- internal/test/plugins/quota_generic.go | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/plugins/capacity_liquid.go b/internal/plugins/capacity_liquid.go index 7f1278fb..b8a044f9 100644 --- a/internal/plugins/capacity_liquid.go +++ b/internal/plugins/capacity_liquid.go @@ -94,7 +94,7 @@ func (p *liquidCapacityPlugin) Scrape(ctx context.Context, backchannel core.Capa logg.Fatal("ServiceInfo version for %s changed from %d to %d; restarting now to reload ServiceInfo...", p.LiquidServiceType, p.LiquidServiceInfo.Version, resp.InfoVersion) } - resourceNames := SortMapKeys(p.LiquidServiceInfo.Resources) + resourceNames := SortedMapKeys(p.LiquidServiceInfo.Resources) var errs []error for _, resourceName := range resourceNames { perAZ := resp.Resources[resourceName].PerAZ diff --git a/internal/plugins/liquid.go b/internal/plugins/liquid.go index 9779cd3b..8617313a 100644 --- a/internal/plugins/liquid.go +++ b/internal/plugins/liquid.go @@ -123,7 +123,7 @@ func (p *liquidQuotaPlugin) Scrape(ctx context.Context, project core.KeystonePro logg.Fatal("ServiceInfo version for %s changed from %d to %d; restarting now to reload ServiceInfo...", p.LiquidServiceType, p.LiquidServiceInfo.Version, resp.InfoVersion) } - resourceNames := SortMapKeys(p.LiquidServiceInfo.Resources) + resourceNames := SortedMapKeys(p.LiquidServiceInfo.Resources) var errs []error for _, resourceName := range resourceNames { perAZ := resp.Resources[resourceName].PerAZ @@ -198,9 +198,7 @@ func (p *liquidQuotaPlugin) SetQuota(ctx context.Context, project core.KeystoneP req := liquid.ServiceQuotaRequest{ Resources: make(map[liquid.ResourceName]liquid.ResourceQuotaRequest, len(quotaReq)), } - for resName, request := range quotaReq { - req.Resources[resName] = liquid.ResourceQuotaRequest{Quota: request.Quota, PerAZ: request.PerAZ} - } + req = liquid.ServiceQuotaRequest{Resources: quotaReq} if p.LiquidServiceInfo.QuotaUpdateNeedsProjectMetadata { req.ProjectMetadata = project.ForLiquid() } diff --git a/internal/plugins/utils.go b/internal/plugins/utils.go index 6bca811c..944e9723 100644 --- a/internal/plugins/utils.go +++ b/internal/plugins/utils.go @@ -33,7 +33,7 @@ func p2u64(val uint64) *uint64 { return &val } -func SortMapKeys[M map[K]V, K ~string, V any](mapToSort M) []K { +func SortedMapKeys[M map[K]V, K ~string, V any](mapToSort M) []K { sortedKeys := slices.Collect(maps.Keys(mapToSort)) slices.Sort(sortedKeys) return sortedKeys @@ -43,7 +43,7 @@ func CheckResourceTopologies(serviceInfo liquid.ServiceInfo) (err error) { var errs []error resources := serviceInfo.Resources - resourceNames := SortMapKeys(resources) + resourceNames := SortedMapKeys(resources) for _, resourceName := range resourceNames { topology := resources[resourceName].Topology if topology == "" { @@ -84,6 +84,6 @@ func MatchLiquidReportToTopology[V any](perAZReport map[liquid.AvailabilityZone] return } - reportedAZs := SortMapKeys(perAZReport) + reportedAZs := SortedMapKeys(perAZReport) return fmt.Errorf("scrape with topology type: %s returned AZs: %v", topology, reportedAZs) } diff --git a/internal/test/plugins/quota_generic.go b/internal/test/plugins/quota_generic.go index 18f324ad..1373b07c 100644 --- a/internal/test/plugins/quota_generic.go +++ b/internal/test/plugins/quota_generic.go @@ -174,7 +174,7 @@ func (p *GenericQuotaPlugin) Scrape(ctx context.Context, project core.KeystonePr if len(p.ReportedAZs) > 0 { var errs []error - resourceNames := plugins.SortMapKeys(p.LiquidServiceInfo.Resources) + resourceNames := plugins.SortedMapKeys(p.LiquidServiceInfo.Resources) for _, resourceName := range resourceNames { topology := p.LiquidServiceInfo.Resources[resourceName].Topology err := plugins.MatchLiquidReportToTopology(p.ReportedAZs, topology)