Skip to content

Commit

Permalink
fix bug operator restart on GCP cluster
Browse files Browse the repository at this point in the history
Signed-off-by: shirady <[email protected]>
  • Loading branch information
shirady committed Dec 3, 2023
1 parent 127c1fe commit 3a08ae3
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,31 +956,34 @@ func (r *Reconciler) prepareGCPBackingStore() error {
return err
}
projectID := authJSON.ProjectID
r.GCPBucketCreds.StringData["GoogleServiceAccountPrivateKeyJson"] = cloudCredsSecret.StringData["service_account.json"]
ctx := context.Background()
gcpclient, err := storage.NewClient(ctx, option.WithCredentialsJSON([]byte(cloudCredsSecret.StringData["service_account.json"])))
if err != nil {
r.Logger.Info(err)
return err
}
if r.GCPBucketCreds.StringData != nil {
r.GCPBucketCreds.StringData["GoogleServiceAccountPrivateKeyJson"] = cloudCredsSecret.StringData["service_account.json"]

var bucketName = strings.ToLower(randname.GenerateWithPrefix("noobaabucket", 5))
if err := r.createGCPBucketForBackingStore(gcpclient, projectID, bucketName); err != nil {
r.Logger.Info(err)
return err
}
ctx := context.Background()
gcpclient, err := storage.NewClient(ctx, option.WithCredentialsJSON([]byte(cloudCredsSecret.StringData["service_account.json"])))
if err != nil {
r.Logger.Info(err)
return err
}

if errUpdate := r.Client.Update(r.Ctx, r.GCPBucketCreds); errUpdate != nil {
return fmt.Errorf("got error on GCPBucketCreds update. error: %v", errUpdate)
}
// create backing store
r.DefaultBackingStore.Spec.Type = nbv1.StoreTypeGoogleCloudStorage
r.DefaultBackingStore.Spec.GoogleCloudStorage = &nbv1.GoogleCloudStorageSpec{
TargetBucket: bucketName,
Secret: corev1.SecretReference{
Name: r.GCPBucketCreds.Name,
Namespace: r.GCPBucketCreds.Namespace,
},
var bucketName = strings.ToLower(randname.GenerateWithPrefix("noobaabucket", 5))
if err := r.createGCPBucketForBackingStore(gcpclient, projectID, bucketName); err != nil {
r.Logger.Info(err)
return err
}

if errUpdate := r.Client.Update(r.Ctx, r.GCPBucketCreds); errUpdate != nil {
return fmt.Errorf("got error on GCPBucketCreds update. error: %v", errUpdate)
}
// create backing store
r.DefaultBackingStore.Spec.Type = nbv1.StoreTypeGoogleCloudStorage
r.DefaultBackingStore.Spec.GoogleCloudStorage = &nbv1.GoogleCloudStorageSpec{
TargetBucket: bucketName,
Secret: corev1.SecretReference{
Name: r.GCPBucketCreds.Name,
Namespace: r.GCPBucketCreds.Namespace,
},
}
}
return nil
}
Expand Down

0 comments on commit 3a08ae3

Please sign in to comment.