Skip to content

Commit b09e359

Browse files
committed
CLI support for backingstore endpoint update
Signed-off-by: Karthik P S <karthikperla2000@gmail.com>
1 parent cde9dbe commit b09e359

1 file changed

Lines changed: 91 additions & 2 deletions

File tree

pkg/backingstore/backingstore.go

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"os"
8+
"slices"
89
"strings"
910
"time"
1011

@@ -31,6 +32,21 @@ import (
3132
sigyaml "sigs.k8s.io/yaml"
3233
)
3334

35+
const (
36+
S3Compatible = "s3-compatible"
37+
IBMCOS = "ibm-cos"
38+
AWSS3 = "aws-s3"
39+
AWSSTSS3 = "aws-sts-s3"
40+
GoogleCloudStorage = "google-cloud-storage"
41+
GoogleCloudStorageSTS = "google-cloud-storage-sts"
42+
AzureBlob = "azure-blob"
43+
AzureSTSBlob = "azure-sts-blob"
44+
PVPool = "pv-pool"
45+
)
46+
47+
var validBackingStores = []string{S3Compatible, IBMCOS, AWSS3, AWSSTSS3, GoogleCloudStorage,
48+
GoogleCloudStorageSTS, AzureBlob, AzureSTSBlob, PVPool}
49+
3450
var ctx = context.TODO()
3551

3652
// Cmd returns a CLI command
@@ -41,6 +57,7 @@ func Cmd() *cobra.Command {
4157
}
4258
cmd.AddCommand(
4359
CmdCreate(),
60+
CmdUpdate(),
4461
CmdDelete(),
4562
CmdStatus(),
4663
CmdList(),
@@ -71,6 +88,17 @@ func CmdCreate() *cobra.Command {
7188
return cmd
7289
}
7390

91+
func CmdUpdate() *cobra.Command {
92+
cmd := &cobra.Command{
93+
Use: "update <backing-store-name>",
94+
Short: "Update a backing store",
95+
Run: RunUpdate,
96+
}
97+
cmd.Flags().String("endpoint", "", "New endpoint URL")
98+
99+
return cmd
100+
}
101+
74102
// CmdCreateAWSSTSS3 returns a cli command
75103
func CmdCreateAWSSTSS3() *cobra.Command {
76104
cmd := &cobra.Command{
@@ -518,8 +546,7 @@ func RunCreate(cmd *cobra.Command, args []string) {
518546
if len(args) != 1 || args[0] == "" {
519547
log.Fatalf(`❌ Missing expected arguments: <backing-store-type> %s`, cmd.UsageString())
520548
}
521-
if args[0] != "aws-s3" && args[0] != "aws-sts-s3" && args[0] != "google-cloud-storage" && args[0] != "google-cloud-storage-sts" &&
522-
args[0] != "azure-blob" && args[0] != "ibm-cos" && args[0] != "pv-pool" && args[0] != "s3-compatible" && args[0] != "azure-sts-blob" {
549+
if !slices.Contains(validBackingStores, args[0]) {
523550
log.Fatalf(`❌ Unsupported <backing-store-type> -> %s %s`, args[0], cmd.UsageString())
524551
}
525552
}
@@ -931,6 +958,68 @@ func RunCreatePVPool(cmd *cobra.Command, args []string) {
931958
})
932959
}
933960

961+
func RunUpdate(cmd *cobra.Command, args []string) {
962+
// args: <backingstore name>
963+
// flags: <endpoint>
964+
log := util.Logger()
965+
966+
if len(args) != 1 || args[0] == "" {
967+
log.Fatalf(`❌ Missing expected arguments: <backing-store-name> %s`, cmd.UsageString())
968+
}
969+
970+
endpoint, err := cmd.Flags().GetString("endpoint")
971+
endpoint = strings.TrimSpace(endpoint)
972+
if err != nil || len(endpoint) == 0 {
973+
log.Fatalf("❌ Endpoint is required for update command")
974+
}
975+
976+
o := util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_backingstore_cr_yaml)
977+
bs := o.(*nbv1.BackingStore)
978+
bs.Name = args[0]
979+
bs.Namespace = options.Namespace
980+
981+
err = util.KubeClient().Get(util.Context(), util.ObjectKey(bs), bs)
982+
if err != nil {
983+
log.Fatalf("❌ Could not fetch the backing store: %v", err)
984+
}
985+
986+
storeType := bs.Spec.Type
987+
if !slices.Contains(validBackingStores, string(storeType)) {
988+
log.Fatalf(`❌ Unsupported <backing-store-type> %s`, storeType)
989+
} else if storeType != IBMCOS && storeType != S3Compatible {
990+
log.Fatalf("❌ Target endpoint for backing store type %s cannot be updated", storeType)
991+
}
992+
993+
switch storeType {
994+
case S3Compatible:
995+
if bs.Spec.S3Compatible == nil {
996+
log.Fatalf(`❌ Invalid backing store spec`)
997+
}
998+
bs.Spec.S3Compatible.Endpoint = endpoint
999+
case IBMCOS:
1000+
if bs.Spec.IBMCos == nil {
1001+
log.Fatalf(`❌ Invalid backing store spec`)
1002+
}
1003+
bs.Spec.IBMCos.Endpoint = endpoint
1004+
default:
1005+
}
1006+
1007+
success := util.KubeUpdate(bs)
1008+
if !success {
1009+
log.Fatalf("❌ Error updating backing store %s", bs.Name)
1010+
}
1011+
1012+
log.Printf("✅ BackingStore %s Spec updated. Changes will be applied", bs.Name)
1013+
log.Printf("")
1014+
log.Printf("BackingStore Wait Ready:")
1015+
1016+
if WaitReady(bs) {
1017+
log.Printf("")
1018+
log.Printf("")
1019+
RunStatus(cmd, args)
1020+
}
1021+
}
1022+
9341023
// RunDelete runs a CLI command
9351024
func RunDelete(cmd *cobra.Command, args []string) {
9361025

0 commit comments

Comments
 (0)