Skip to content

Commit

Permalink
Updated forceMD5Etag to boolean pointer type to work efficiently
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Sep 10, 2024
1 parent 1d40d80 commit 0ff1930
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/noobaa/v1alpha1/noobaaaccount_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type NooBaaAccountSpec struct {

// ForceMd5Etag specifies whether MD5 Etags should be calculated for the account or not
// +optional
ForceMd5Etag *bool `json:"force_md5_etag,omitempty"`
ForceMd5Etag bool `json:"force_md5_etag,omitempty"`
}

// AccountNsfsConfig is the configuration of NSFS of CreateAccountParams
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions pkg/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func RunCreate(cmd *cobra.Command, args []string) {
maxSize, _ := cmd.Flags().GetString("max-size")
maxObjects, _ := cmd.Flags().GetString("max-objects")

err = nbClient.CreateBucketAPI(nb.CreateBucketParams{Name: bucketName, Tiering: tierName, ForceMd5Etag: forceMd5Etag})
err = nbClient.CreateBucketAPI(nb.CreateBucketParams{Name: bucketName, Tiering: tierName, ForceMd5Etag: &forceMd5Etag})
if err != nil {
log.Fatal(err)
}
Expand All @@ -139,13 +139,20 @@ func RunUpdate(cmd *cobra.Command, args []string) {
maxSize, _ := cmd.Flags().GetString("max-size")
maxObjects, _ := cmd.Flags().GetString("max-objects")

updateParams := nb.CreateBucketParams{
Name: bucketName,
}

if cmd.Flags().Changed("force_md5_etag") {
updateParams.ForceMd5Etag = &forceMd5Etag
}

quota, updateQuota := prepareQuotaConfig(maxSize, maxObjects)
var err error
if updateQuota {
err = nbClient.UpdateBucketAPI(nb.CreateBucketParams{Name: bucketName, ForceMd5Etag: forceMd5Etag, Quota: &quota})
} else {
err = nbClient.UpdateBucketAPI(nb.CreateBucketParams{Name: bucketName, ForceMd5Etag: forceMd5Etag})
updateParams.Quota = &quota
}

err := nbClient.UpdateBucketAPI(updateParams)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/nb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ type CreateSystemReply struct {
type CreateBucketParams struct {
Name string `json:"name"`
Tiering string `json:"tiering,omitempty"`
ForceMd5Etag bool `json:"force_md5_etag,omitempty"`
ForceMd5Etag *bool `json:"force_md5_etag,omitempty"`
BucketClaim *BucketClaimInfo `json:"bucket_claim,omitempty"`
Namespace *NamespaceBucketInfo `json:"namespace,omitempty"`
Quota *QuotaConfig `json:"quota,omitempty"`
Expand Down
15 changes: 8 additions & 7 deletions pkg/noobaaaccount/noobaaaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func RunCreate(cmd *cobra.Command, args []string) {
noobaaAccount.Name = name
noobaaAccount.Namespace = options.Namespace
noobaaAccount.Spec.AllowBucketCreate = allowBucketCreate
noobaaAccount.Spec.ForceMd5Etag = &forceMd5Etag
noobaaAccount.Spec.ForceMd5Etag = forceMd5Etag

if nsfsAccountConfig {
nsfsUID := util.GetFlagIntOrPrompt(cmd, "uid")
Expand Down Expand Up @@ -272,11 +272,7 @@ func RunUpdate(cmd *cobra.Command, args []string) {
name := args[0]

newDefaultResource := util.GetFlagStringOrPrompt(cmd, "new_default_resource")
var forceMd5EtagPtr *bool = nil
if cmd.Flags().Changed("force_md5_etag") {
forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")
forceMd5EtagPtr = &forceMd5Etag
}
forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")

o := util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_noobaaaccount_cr_yaml)
noobaaAccount := o.(*nbv1.NooBaaAccount)
Expand All @@ -294,6 +290,11 @@ func RunUpdate(cmd *cobra.Command, args []string) {
newDefaultResource, options.Namespace)
}

var forceMd5EtagPtr *bool = nil
if cmd.Flags().Changed("force_md5_etag") {
forceMd5EtagPtr = &forceMd5Etag
}

// Checking if noobaaAccount is a CRD account
if util.KubeCheck(noobaaAccount) {
noobaaAccount.Spec.DefaultResource = newDefaultResource
Expand All @@ -305,7 +306,7 @@ func RunUpdate(cmd *cobra.Command, args []string) {

noobaaAccount.Spec.DefaultResource = newDefaultResource
if forceMd5EtagPtr != nil {
noobaaAccount.Spec.ForceMd5Etag = forceMd5EtagPtr
noobaaAccount.Spec.ForceMd5Etag = forceMd5Etag
}

if !util.KubeUpdate(noobaaAccount) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/noobaaaccount/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (r *Reconciler) CreateNooBaaAccount() error {
DefaultResource: r.NooBaaAccount.Spec.DefaultResource,
HasLogin: false,
S3Access: true,
ForceMd5Etag: *r.NooBaaAccount.Spec.ForceMd5Etag,
ForceMd5Etag: r.NooBaaAccount.Spec.ForceMd5Etag,
AllowBucketCreate: r.NooBaaAccount.Spec.AllowBucketCreate,
}

Expand Down Expand Up @@ -413,7 +413,7 @@ func (r *Reconciler) UpdateNooBaaAccount() error {
Email: r.NooBaaAccount.Name,
DefaultResource: &r.NooBaaAccount.Spec.DefaultResource,
S3Access: true,
ForceMd5Etag: r.NooBaaAccount.Spec.ForceMd5Etag,
ForceMd5Etag: &r.NooBaaAccount.Spec.ForceMd5Etag,
AllowBucketCreation: &r.NooBaaAccount.Spec.AllowBucketCreate,
}

Expand Down

0 comments on commit 0ff1930

Please sign in to comment.