Skip to content

Commit 0a187fc

Browse files
committed
STAC-23446 Fix logic for checking if global backup is enabled
1 parent c2314f8 commit 0a187fc

File tree

8 files changed

+64
-14
lines changed

8 files changed

+64
-14
lines changed

cmd/cmdutils/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Run(globalFlags *config.CLIGlobalFlags, runFunc func(ctx *app.Context) erro
1919
_, _ = fmt.Fprintf(os.Stderr, "❌ Error: %v\n", err)
2020
os.Exit(1)
2121
}
22-
if storageRequired && !appCtx.Config.StorageEnabled() {
22+
if storageRequired && !appCtx.Config.GlobalBackupEnabled() {
2323
appCtx.Logger.Errorf("commands that interact with S3-compatible storage require SUSE Observability to be deployed with .Values.global.backup.enabled=true")
2424
os.Exit(1)
2525
}

cmd/elasticsearch/configure_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ storage:
417417
assert.NotNil(t, cfg)
418418
// Verify storage mode
419419
assert.False(t, cfg.IsLegacyMode())
420-
assert.True(t, cfg.StorageEnabled())
420+
assert.True(t, cfg.GlobalBackupEnabled())
421421
assert.NotEmpty(t, cfg.Elasticsearch.SnapshotRepository.AccessKey)
422422
assert.NotEmpty(t, cfg.Elasticsearch.SnapshotRepository.SecretKey)
423423
}

cmd/elasticsearch/list_indices_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestListIndicesCmd_StorageIntegration(t *testing.T) {
4949
assert.Equal(t, "elasticsearch-master", cfg.Elasticsearch.Service.Name)
5050
assert.Equal(t, 9200, cfg.Elasticsearch.Service.Port)
5151
assert.False(t, cfg.IsLegacyMode())
52-
assert.True(t, cfg.StorageEnabled())
52+
assert.True(t, cfg.GlobalBackupEnabled())
5353
assert.Equal(t, "storage", cfg.GetStorageService().Name)
5454
}
5555

cmd/elasticsearch/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func TestListCmd_StorageIntegration(t *testing.T) {
327327
assert.Equal(t, "backup-repo", cfg.Elasticsearch.Restore.Repository)
328328
assert.Equal(t, "elasticsearch-master", cfg.Elasticsearch.Service.Name)
329329
assert.False(t, cfg.IsLegacyMode())
330-
assert.True(t, cfg.StorageEnabled())
330+
assert.True(t, cfg.GlobalBackupEnabled())
331331
assert.Equal(t, "storage", cfg.GetStorageService().Name)
332332
}
333333

cmd/settings/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func getAllBackups(appCtx *app.Context) ([]BackupFileInfo, error) {
9797
}
9898

9999
// Get backups from S3 if storage is enabled
100-
if appCtx.Config.StorageEnabled() {
100+
if appCtx.Config.GlobalBackupEnabled() {
101101
if backups, err = getBackupListFromS3(appCtx); err != nil {
102102
return nil, fmt.Errorf("failed to get list of backups from S3 storage: %v", err)
103103
}

cmd/settings/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func buildEnvVar(extraEnvVar []corev1.EnvVar, config *config.Config) []corev1.En
197197
{Name: "RECEIVER_BASE_URL", Value: config.Settings.Restore.ReceiverBaseURL},
198198
{Name: "PLATFORM_VERSION", Value: config.Settings.Restore.PlatformVersion},
199199
{Name: "ZOOKEEPER_QUORUM", Value: config.Settings.Restore.ZookeeperQuorum},
200-
{Name: "BACKUP_CONFIGURATION_UPLOAD_REMOTE", Value: strconv.FormatBool(config.StorageEnabled())},
200+
{Name: "BACKUP_CONFIGURATION_UPLOAD_REMOTE", Value: strconv.FormatBool(config.GlobalBackupEnabled())},
201201
}
202202
if fromPVC {
203203
// Force PVC mode in the shell script, suppress local bucket

internal/foundation/config/config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ func (c *Config) IsLegacyMode() bool {
3232
return c.Minio.Service.Name != ""
3333
}
3434

35-
// StorageEnabled returns true when S3-compatible storage is available,
36-
// either through legacy Minio (with Enabled=true) or when the new Storage config is used the
37-
// storage is always enabled
38-
func (c *Config) StorageEnabled() bool {
35+
// GlobalBackupEnabled returns true when global backup is enabled,
36+
// either through legacy Minio (with Enabled=true) or the new Storage config's globalBackupEnabled flag.
37+
func (c *Config) GlobalBackupEnabled() bool {
3938
if c.IsLegacyMode() {
4039
return c.Minio.Enabled
4140
}
42-
return true
41+
return c.Storage.GlobalBackupEnabled
4342
}
4443

4544
// GetStorageService returns the service config for the S3-compatible storage,

internal/foundation/config/config_test.go

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestLoadConfig_FromConfigMapOnly(t *testing.T) {
6161
assert.Equal(t, "configmap-secret-key", config.Elasticsearch.SnapshotRepository.SecretKey)
6262
// Verify legacy mode
6363
assert.True(t, config.IsLegacyMode())
64-
assert.True(t, config.StorageEnabled())
64+
assert.True(t, config.GlobalBackupEnabled())
6565
}
6666

6767
func TestLoadConfig_Storage_FromConfigMapOnly(t *testing.T) {
@@ -96,14 +96,65 @@ func TestLoadConfig_Storage_FromConfigMapOnly(t *testing.T) {
9696
assert.Equal(t, "configmap-secret-key", config.Elasticsearch.SnapshotRepository.SecretKey)
9797
// Verify new storage mode (not legacy)
9898
assert.False(t, config.IsLegacyMode())
99-
assert.True(t, config.StorageEnabled())
99+
assert.True(t, config.GlobalBackupEnabled())
100100
// Verify storage accessor methods return storage config values
101101
assert.Equal(t, "suse-observability-storage", config.GetStorageService().Name)
102102
assert.Equal(t, 9000, config.GetStorageService().Port)
103103
assert.Equal(t, "storageadmin", config.GetStorageAccessKey())
104104
assert.Equal(t, "storageadmin", config.GetStorageSecretKey())
105105
}
106106

107+
func TestGlobalBackupEnabled_StorageMode_Disabled(t *testing.T) {
108+
config := &Config{
109+
Storage: StorageConfig{
110+
GlobalBackupEnabled: false,
111+
Service: ServiceConfig{
112+
Name: "storage",
113+
Port: 9000,
114+
LocalPortForwardPort: 9000,
115+
},
116+
},
117+
}
118+
119+
assert.False(t, config.IsLegacyMode())
120+
assert.False(t, config.GlobalBackupEnabled())
121+
}
122+
123+
func TestGlobalBackupEnabled_StorageMode_Enabled(t *testing.T) {
124+
config := &Config{
125+
Storage: StorageConfig{
126+
GlobalBackupEnabled: true,
127+
Service: ServiceConfig{
128+
Name: "storage",
129+
Port: 9000,
130+
LocalPortForwardPort: 9000,
131+
},
132+
},
133+
}
134+
135+
assert.False(t, config.IsLegacyMode())
136+
assert.True(t, config.GlobalBackupEnabled())
137+
}
138+
139+
func TestGlobalBackupEnabled_LegacyMode(t *testing.T) {
140+
config := &Config{
141+
Minio: MinioConfig{
142+
Enabled: false,
143+
Service: ServiceConfig{
144+
Name: "minio",
145+
Port: 9000,
146+
LocalPortForwardPort: 9000,
147+
},
148+
},
149+
}
150+
151+
assert.True(t, config.IsLegacyMode())
152+
assert.False(t, config.GlobalBackupEnabled())
153+
154+
config.Minio.Enabled = true
155+
assert.True(t, config.GlobalBackupEnabled())
156+
}
157+
107158
func TestLoadConfig_CompleteConfiguration(t *testing.T) {
108159
fakeClient := fake.NewClientset()
109160
validConfigYAML := loadTestData(t, "validConfigMapConfig.yaml")
@@ -223,7 +274,7 @@ func TestLoadConfig_Storage_CompleteConfiguration(t *testing.T) {
223274

224275
// Verify new storage mode (not legacy)
225276
assert.False(t, config.IsLegacyMode())
226-
assert.True(t, config.StorageEnabled())
277+
assert.True(t, config.GlobalBackupEnabled())
227278

228279
// Service config
229280
assert.Equal(t, "suse-observability-elasticsearch-master-headless", config.Elasticsearch.Service.Name)

0 commit comments

Comments
 (0)