diff --git a/go.mod b/go.mod index 3b7a3aea..e1b1146e 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/prometheus/client_golang v1.20.5 github.com/prometheus/common v0.61.0 github.com/rs/cors v1.11.1 - github.com/sapcc/go-api-declarations v1.13.1 + github.com/sapcc/go-api-declarations v1.13.2 github.com/sapcc/go-bits v0.0.0-20241213102058-cb5d877d1274 go.uber.org/automaxprocs v1.6.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index afa6b0a9..6cd3024e 100644 --- a/go.sum +++ b/go.sum @@ -157,8 +157,8 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/sapcc/go-api-declarations v1.13.1 h1:rovCnLscnoZaIZPWhohSYHzwwYjOnCPsRw3zwtu4tLI= -github.com/sapcc/go-api-declarations v1.13.1/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI= +github.com/sapcc/go-api-declarations v1.13.2 h1:dPYYsjwKGObSAm6+K+dYCiLQWunYuWkywlZnuXfjsmk= +github.com/sapcc/go-api-declarations v1.13.2/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI= github.com/sapcc/go-bits v0.0.0-20241213102058-cb5d877d1274 h1:ja3KsSLFDrjtPLqFt6qnPMxMnTuseP5+JpP0IshJSe4= github.com/sapcc/go-bits v0.0.0-20241213102058-cb5d877d1274/go.mod h1:hhH7PgcPklzzJdx1zMhv3KiMEnoCZV+pnapPRcgI7wk= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= diff --git a/internal/liquids/cinder/usage.go b/internal/liquids/cinder/usage.go index 2a5536f8..b8e1b9c2 100644 --- a/internal/liquids/cinder/usage.go +++ b/internal/liquids/cinder/usage.go @@ -23,7 +23,6 @@ import ( "context" "encoding/json" "fmt" - "slices" "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/quotasets" "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/snapshots" @@ -106,10 +105,7 @@ func (l *Logic) collectVolumeSubresources(ctx context.Context, projectUUID strin } for _, volume := range vols { - az := liquid.AvailabilityZone(volume.AvailabilityZone) - if !slices.Contains(allAZs, az) { - az = liquid.AvailabilityZoneUnknown - } + az := liquid.NormalizeAZ(volume.AvailabilityZone, allAZs) vt := VolumeType(volume.VolumeType) placementForVolumeUUID[volume.ID] = VolumePlacement{vt, az} @@ -171,10 +167,7 @@ func (l *Logic) collectSnapshotSubresources(ctx context.Context, projectUUID str snapshot.VolumeID, snapshot.ID, projectUUID, err) } vt := VolumeType(volume.VolumeType) - az := liquid.AvailabilityZone(volume.AvailabilityZone) - if !slices.Contains(allAZs, az) { - az = liquid.AvailabilityZoneUnknown - } + az := liquid.NormalizeAZ(volume.AvailabilityZone, allAZs) placement = VolumePlacement{vt, az} } diff --git a/internal/liquids/ironic/capacity.go b/internal/liquids/ironic/capacity.go index c84f6ba1..9649a9c1 100644 --- a/internal/liquids/ironic/capacity.go +++ b/internal/liquids/ironic/capacity.go @@ -50,8 +50,8 @@ func (l *Logic) ScanCapacity(ctx context.Context, req liquid.ServiceCapacityRequ // so we can use this to establish an AZ-to-node relationship. azForResourceProviderUUID := make(map[string]liquid.AvailabilityZone) for _, aggr := range allAggregates { - az := liquid.AvailabilityZone(aggr.AvailabilityZone) - if az == "" || !slices.Contains(req.AllAZs, az) { + az := liquid.NormalizeAZ(aggr.AvailabilityZone, req.AllAZs) + if az == liquid.AvailabilityZoneUnknown { // we are only interested in aggregates that are connected to AZs that we know continue } diff --git a/internal/liquids/ironic/usage.go b/internal/liquids/ironic/usage.go index d7a1c168..f34a99aa 100644 --- a/internal/liquids/ironic/usage.go +++ b/internal/liquids/ironic/usage.go @@ -22,7 +22,6 @@ package ironic import ( "context" "fmt" - "slices" "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/limits" "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/quotasets" @@ -122,10 +121,7 @@ func (l *Logic) addInstanceToReport(ctx context.Context, resources map[liquid.Re } // count this instance for the AZ breakdown - az := liquid.AvailabilityZone(instance.AvailabilityZone) - if !slices.Contains(allAZs, az) { - az = liquid.AvailabilityZoneUnknown - } + az := liquid.NormalizeAZ(instance.AvailabilityZone, allAZs) resReport.AddLocalizedUsage(az, 1) // add subresource if requested diff --git a/vendor/github.com/sapcc/go-api-declarations/liquid/availability_zone.go b/vendor/github.com/sapcc/go-api-declarations/liquid/availability_zone.go index 662d3d2b..b876f024 100644 --- a/vendor/github.com/sapcc/go-api-declarations/liquid/availability_zone.go +++ b/vendor/github.com/sapcc/go-api-declarations/liquid/availability_zone.go @@ -19,6 +19,8 @@ package liquid +import "slices" + // AvailabilityZone is the name of an availability zone. // Some special values are enumerated below. type AvailabilityZone string @@ -35,3 +37,14 @@ const ( func InAnyAZ[T any](value T) map[AvailabilityZone]*T { return map[AvailabilityZone]*T{AvailabilityZoneAny: &value} } + +// NormalizeAZ takes an AZ name as reported by an OpenStack service and safely casts it into the AvailabilityZone type. +// If the provided raw value is not equal to any of the AZs known to Limes (from the second list), AvailabilityZoneUnknown will be returned. +func NormalizeAZ(rawAZ string, allAZs []AvailabilityZone) AvailabilityZone { + az := AvailabilityZone(rawAZ) + if slices.Contains(allAZs, az) { + return az + } else { + return AvailabilityZoneUnknown + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index f24bc7af..e72088b3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -141,7 +141,7 @@ github.com/rabbitmq/amqp091-go ## explicit; go 1.13 github.com/rs/cors github.com/rs/cors/internal -# github.com/sapcc/go-api-declarations v1.13.1 +# github.com/sapcc/go-api-declarations v1.13.2 ## explicit; go 1.21 github.com/sapcc/go-api-declarations/bininfo github.com/sapcc/go-api-declarations/cadf