Skip to content

Commit

Permalink
Backport to 5.17 (#1453)
Browse files Browse the repository at this point in the history
* Add check env var is not null

Signed-off-by: jackyalbo <[email protected]>
(cherry picked from commit 1bf5238)

* Updated forceMD5Etag to boolean pointer type to work efficiently

Signed-off-by: Aayush Chouhan <[email protected]>
(cherry picked from commit a914ff5)

* Fix #432 POSTGRES_HOST use service url with namespace

Signed-off-by: Guy Margalit <[email protected]>
(cherry picked from commit 822cd32)

* Update noobaa operator csv to install on all namespaces

Signed-off-by: Kaustav Majumder <[email protected]>
(cherry picked from commit 21de9af)

---------

Co-authored-by: Aayush Chouhan <[email protected]>
Co-authored-by: Guy Margalit <[email protected]>
Co-authored-by: Kaustav Majumder <[email protected]>
  • Loading branch information
4 people authored Sep 30, 2024
1 parent 890bade commit d32f752
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion deploy/olm/noobaa-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec:
type: SingleNamespace
- supported: false
type: MultiNamespace
- supported: false
- supported: true
type: AllNamespaces
install:
strategy: deployment
Expand Down
4 changes: 2 additions & 2 deletions pkg/backingstore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,8 @@ func (r *Reconciler) needUpdate(pod *corev1.Pod) bool {
configMapValue := r.CoreAppConfig.Data[name]
noobaaLogEnvVar := util.GetEnvVariable(&c.Env, name)

if configMapValue != noobaaLogEnvVar.Value {
r.Logger.Warnf("%s Env variable change detected: (%v) on the config map (%v)", name, noobaaLogEnvVar.Value, configMapValue)
if (noobaaLogEnvVar == nil && configMapValue != "") || (noobaaLogEnvVar != nil && configMapValue != noobaaLogEnvVar.Value) {
r.Logger.Warnf("%s Env variable change detected: (%v) on the config map (%v)", name, noobaaLogEnvVar, configMapValue)
return true
}
}
Expand Down
28 changes: 20 additions & 8 deletions pkg/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ func RunCreate(cmd *cobra.Command, args []string) {
log.Fatal(fmt.Errorf("CreateTieringStructure for PlacementPolicy failed to create policy %q with error: %v", tierName, err))
}

forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")
forceMd5EtagPtr, err := util.GetBoolFlagPtr(cmd, "force_md5_etag")
if err != nil {
log.Fatal(err)
}
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: forceMd5EtagPtr})
if err != nil {
log.Fatal(err)
}
Expand All @@ -135,17 +138,24 @@ func RunUpdate(cmd *cobra.Command, args []string) {
}
bucketName := args[0]
nbClient := system.GetNBClient()
forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")
forceMd5EtagPtr, err := util.GetBoolFlagPtr(cmd, "force_md5_etag")
if err != nil {
log.Fatal(err)
}
maxSize, _ := cmd.Flags().GetString("max-size")
maxObjects, _ := cmd.Flags().GetString("max-objects")

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

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 Expand Up @@ -187,7 +197,9 @@ func RunStatus(cmd *cobra.Command, args []string) {
}
fmt.Printf(" %-22s : %s\n", "Type", b.BucketType)
fmt.Printf(" %-22s : %s\n", "Mode", b.Mode)
fmt.Printf(" %-22s : %t\n", "Force Md5 Etag", b.ForceMd5Etag)
if b.ForceMd5Etag != nil {
fmt.Printf(" %-22s : %t\n", "Force Md5 Etag", *b.ForceMd5Etag)
}
if b.PolicyModes != nil {
fmt.Printf(" %-22s : %s\n", "ResiliencyStatus", b.PolicyModes.ResiliencyStatus)
fmt.Printf(" %-22s : %s\n", "QuotaStatus", b.PolicyModes.QuotaStatus)
Expand Down
4 changes: 2 additions & 2 deletions pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5907,7 +5907,7 @@ s3 ls s3://first.bucket
` + "`" + `` + "`" + `` + "`" + `
`

const Sha256_deploy_olm_noobaa_operator_clusterserviceversion_yaml = "900ed615837a7f63510de5bff4bd8ffdcc02bea8cec0cf231d21e32812f78ed7"
const Sha256_deploy_olm_noobaa_operator_clusterserviceversion_yaml = "3b11ab7cce6a4dfc36ad13f75b37821c8e200aec4cf21007208948e74ce9cc44"

const File_deploy_olm_noobaa_operator_clusterserviceversion_yaml = `apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
Expand Down Expand Up @@ -5971,7 +5971,7 @@ spec:
type: SingleNamespace
- supported: false
type: MultiNamespace
- supported: false
- supported: true
type: AllNamespaces
install:
strategy: deployment
Expand Down
6 changes: 3 additions & 3 deletions pkg/nb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type BucketInfo struct {
BucketType string `json:"bucket_type"`
Mode string `json:"mode"`
Undeletable string `json:"undeletable"`
ForceMd5Etag bool `json:"force_md5_etag"`
ForceMd5Etag *bool `json:"force_md5_etag,omitempty"`

BucketClaim *BucketClaimInfo `json:"bucket_claim,omitempty"`
Tiering *TieringPolicyInfo `json:"tiering,omitempty"`
Expand Down 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 Expand Up @@ -411,7 +411,7 @@ type CreateAccountParams struct {
S3Access bool `json:"s3_access"`
AllowBucketCreate bool `json:"allow_bucket_creation"`
DefaultResource string `json:"default_resource,omitempty"`
ForceMd5Etag bool `json:"force_md5_etag,omitempty"`
ForceMd5Etag *bool `json:"force_md5_etag,omitempty"`
BucketClaimOwner string `json:"bucket_claim_owner,omitempty"`
NsfsAccountConfig *nbv1.AccountNsfsConfig `json:"nsfs_account_config,omitempty"`
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/noobaaaccount/noobaaaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ func RunCreate(cmd *cobra.Command, args []string) {
defaultResource, _ := cmd.Flags().GetString("default_resource")

nsfsAccountConfig, _ := cmd.Flags().GetBool("nsfs_account_config")
forceMd5Etag, _ := cmd.Flags().GetBool("force_md5_etag")
forceMd5EtagPtr, err := util.GetBoolFlagPtr(cmd, "force_md5_etag")
if err != nil {
log.Fatal(err)
}

newBucketsPath, _ := cmd.Flags().GetString("new_buckets_path")
nsfsOnly, _ := cmd.Flags().GetBool("nsfs_only")
Expand All @@ -198,7 +201,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 = forceMd5EtagPtr

if nsfsAccountConfig {
nsfsUID := util.GetFlagIntOrPrompt(cmd, "uid")
Expand Down Expand Up @@ -240,7 +243,7 @@ func RunCreate(cmd *cobra.Command, args []string) {

noobaaAccount.Spec.DefaultResource = defaultResource

err := util.KubeClient().Get(util.Context(), util.ObjectKey(noobaaAccount), noobaaAccount)
err = util.KubeClient().Get(util.Context(), util.ObjectKey(noobaaAccount), noobaaAccount)
if err == nil {
log.Fatalf(`❌ noobaaAccount %q already exists in namespace %q`, noobaaAccount.Name, noobaaAccount.Namespace)
}
Expand Down Expand Up @@ -272,10 +275,9 @@ 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
forceMd5EtagPtr, err := util.GetBoolFlagPtr(cmd, "force_md5_etag")
if err != nil {
log.Fatal(err)
}

o := util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_noobaaaccount_cr_yaml)
Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) {

case "POSTGRES_HOST":
if r.NooBaa.Spec.ExternalPgSecret == nil {
c.Env[j].Value = r.NooBaaPostgresDB.Name + "-0." + r.NooBaaPostgresDB.Spec.ServiceName
c.Env[j].Value = r.NooBaaPostgresDB.Name + "-0." + r.NooBaaPostgresDB.Spec.ServiceName + "." + r.NooBaaPostgresDB.Namespace + ".svc"
}

case "DB_TYPE":
Expand Down
13 changes: 13 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,19 @@ func GetFlagStringOrPromptPassword(cmd *cobra.Command, flag string) string {
return str
}

// GetBoolFlagPtr returns a pointer to the boolean flag value if set, or nil if not set
func GetBoolFlagPtr(cmd *cobra.Command, flag string) (*bool, error) {
if cmd.Flags().Changed(flag) {
flagVal, err := cmd.Flags().GetBool(flag)
if err != nil {
return nil, err
}
return &flagVal, nil
}

return nil, nil
}

// PrintThisNoteWhenFinishedApplyingAndStartWaitLoop is a common log task
func PrintThisNoteWhenFinishedApplyingAndStartWaitLoop() {
log := Logger()
Expand Down

0 comments on commit d32f752

Please sign in to comment.