From dbd69e5f33998844bf53db0bed76635575358eb7 Mon Sep 17 00:00:00 2001 From: Simon Murray Date: Tue, 1 Oct 2024 14:25:57 +0100 Subject: [PATCH] Fix Blockstorage Quotas (#61) Beacuse like anything openstack, smaller is better. Like she never said... --- charts/region/Chart.yaml | 4 ++-- pkg/providers/openstack/blockstorage.go | 16 ++++++++++++++++ pkg/providers/openstack/provider.go | 9 +++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/charts/region/Chart.yaml b/charts/region/Chart.yaml index 630b2e1..b9742a4 100644 --- a/charts/region/Chart.yaml +++ b/charts/region/Chart.yaml @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn's Region Controller type: application -version: v0.1.41 -appVersion: v0.1.41 +version: v0.1.42 +appVersion: v0.1.42 icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/dark-on-light/icon.png diff --git a/pkg/providers/openstack/blockstorage.go b/pkg/providers/openstack/blockstorage.go index 11ac8f3..a10342b 100644 --- a/pkg/providers/openstack/blockstorage.go +++ b/pkg/providers/openstack/blockstorage.go @@ -23,9 +23,11 @@ import ( "github.com/gophercloud/gophercloud/v2" "github.com/gophercloud/gophercloud/v2/openstack" "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/availabilityzones" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/quotasets" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" + "github.com/unikorn-cloud/core/pkg/util" "github.com/unikorn-cloud/region/pkg/constants" ) @@ -84,3 +86,17 @@ func (c *BlockStorageClient) AvailabilityZones(ctx context.Context) ([]availabil return filtered, nil } + +func (c *BlockStorageClient) UpdateQuotas(ctx context.Context, projectID string) error { + tracer := otel.GetTracerProvider().Tracer(constants.Application) + + _, span := tracer.Start(ctx, "PUT /block-storage/v3/os-quota-sets") + defer span.End() + + opts := "asets.UpdateOpts{ + Volumes: util.ToPointer(-1), + Gigabytes: util.ToPointer(-1), + } + + return quotasets.Update(ctx, c.client, projectID, opts).Err +} diff --git a/pkg/providers/openstack/provider.go b/pkg/providers/openstack/provider.go index e33df8c..b3e8ed4 100644 --- a/pkg/providers/openstack/provider.go +++ b/pkg/providers/openstack/provider.go @@ -549,10 +549,19 @@ func (p *Provider) provisionQuotas(ctx context.Context, identity *unikornv1.Open return err } + blockstorage, err := NewBlockStorageClient(ctx, providerClient) + if err != nil { + return err + } + if err := compute.UpdateQuotas(ctx, *identity.Spec.ProjectID); err != nil { return err } + if err := blockstorage.UpdateQuotas(ctx, *identity.Spec.ProjectID); err != nil { + return err + } + return nil }