Skip to content

Commit

Permalink
set quota configuration on bucket
Browse files Browse the repository at this point in the history
draft patch

Signed-off-by: Vinayakswami Hariharmath <[email protected]>
  • Loading branch information
vh05 committed Nov 27, 2023
1 parent 2b58b1e commit 68c66d8
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pkg/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package bucket

import (
"fmt"
"strconv"

"github.com/noobaa/noobaa-operator/v5/pkg/bucketclass"
"github.com/noobaa/noobaa-operator/v5/pkg/nb"
"github.com/noobaa/noobaa-operator/v5/pkg/options"
"github.com/noobaa/noobaa-operator/v5/pkg/system"
"github.com/noobaa/noobaa-operator/v5/pkg/util"
res "k8s.io/apimachinery/pkg/api/resource"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,6 +38,10 @@ func CmdCreate() *cobra.Command {
Run: RunCreate,
}
cmd.Flags().Bool("force_md5_etag", false, "This flag enables md5 etag calculation for bucket")
cmd.Flags().String("max-objects", "",
"Set quota max objects quantity config to requested bucket")
cmd.Flags().String("max-size", "",
"Set quota max size config to requested bucket")
return cmd
}

Expand All @@ -47,6 +53,10 @@ func CmdUpdate() *cobra.Command {
Run: RunUpdate,
}
cmd.Flags().Bool("force_md5_etag", false, "This flag enables md5 etag calculation for bucket")
cmd.Flags().String("max-objects", "",
"Set quota max objects quantity config to requested bucket")
cmd.Flags().String("max-size", "",
"Set quota max size config to requested bucket")
return cmd
}

Expand Down Expand Up @@ -101,11 +111,31 @@ func RunCreate(cmd *cobra.Command, args []string) {
}

forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")
maxSize, _ := cmd.Flags().GetString("max-size")
maxObjects, _ := cmd.Flags().GetString("max-objects")
quota := nb.QuotaConfig{}

if len(maxSize) > 0 {
quantity, _ := res.ParseQuantity(maxSize)
bucketMaxSize := quantity.Value()
f, u := nb.GetBytesAndUnits(bucketMaxSize, 2)
quota.Size = &nb.SizeQuotaConfig{Value: f, Unit: u}
}

if len(maxObjects) > 0 {
bucketMaxObjects, _ := strconv.ParseInt(maxObjects, 10, 32)
quota.Quantity = &nb.QuantityQuotaConfig{Value: int(bucketMaxObjects)}
}

err = nbClient.CreateBucketAPI(nb.CreateBucketParams{Name: bucketName, Tiering: tierName, ForceMd5Etag: forceMd5Etag})
if err != nil {
log.Fatal(err)
}

err = nbClient.UpdateBucketAPI(nb.CreateBucketParams{Name: bucketName, Quota: &quota})
if err != nil {
log.Fatal(err)
}
}

// RunUpdate runs a CLI command
Expand All @@ -118,7 +148,6 @@ func RunUpdate(cmd *cobra.Command, args []string) {
nbClient := system.GetNBClient()

forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")

err := nbClient.UpdateBucketAPI(nb.CreateBucketParams{Name: bucketName, ForceMd5Etag: forceMd5Etag})
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 68c66d8

Please sign in to comment.