Skip to content

Commit 13a5a71

Browse files
authored
Use default storage class for postgre/prometheus if not user specified (#1359)
Currently we are using empty string as storage class for postgre and prometheus pods when the user does not provide any value. However any empty value as storage class has a special meaning in Kubernetes: ``` If storageClassName is set to an empty string ('') in the PVC, no storage class will be used (i.e.; dynamic provisioning is disabled for this PVC) Existing, “Available”, PVs (that do not have a specified storageClassName) will be considered for binding to the PVC. ``` This commit will avoid setting the storage class in the PVC declaration, so the default storage class will be used.
1 parent fc5cf8a commit 13a5a71

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

operatorapi/operator_tenants.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,10 +1243,10 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre
12431243

12441244
//Default class name for Log search
12451245
diskSpaceFromAPI := int64(5) * humanize.GiByte // Default is 5Gi
1246-
logSearchStorageClass := "" // Default is ""
12471246
logSearchImage := ""
12481247
logSearchPgImage := ""
12491248
logSearchPgInitImage := ""
1249+
var logSearchStorageClass *string // Nil means use default storage class
12501250
var logSearchSecurityContext *corev1.PodSecurityContext
12511251
var logSearchPgSecurityContext *corev1.PodSecurityContext
12521252

@@ -1255,7 +1255,7 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre
12551255
diskSpaceFromAPI = int64(*tenantReq.LogSearchConfiguration.StorageSize) * humanize.GiByte
12561256
}
12571257
if tenantReq.LogSearchConfiguration.StorageClass != "" {
1258-
logSearchStorageClass = tenantReq.LogSearchConfiguration.StorageClass
1258+
logSearchStorageClass = stringPtr(tenantReq.LogSearchConfiguration.StorageClass)
12591259
}
12601260
if tenantReq.LogSearchConfiguration.Image != "" {
12611261
logSearchImage = tenantReq.LogSearchConfiguration.Image
@@ -1308,7 +1308,7 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre
13081308
corev1.ResourceStorage: *logSearchDiskSpace,
13091309
},
13101310
},
1311-
StorageClassName: &logSearchStorageClass,
1311+
StorageClassName: logSearchStorageClass,
13121312
},
13131313
},
13141314
},
@@ -1331,17 +1331,18 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre
13311331
}
13321332

13331333
prometheusDiskSpace := 5 // Default is 5 by API
1334-
prometheusStorageClass := "" // Default is ""
13351334
prometheusImage := "" // Default is ""
13361335
prometheusSidecardImage := "" // Default is ""
13371336
prometheusInitImage := "" // Default is ""
13381337

1338+
var prometheusStorageClass *string // Nil means default storage class
1339+
13391340
if tenantReq.PrometheusConfiguration != nil {
13401341
if tenantReq.PrometheusConfiguration.StorageSize != nil {
13411342
prometheusDiskSpace = int(*tenantReq.PrometheusConfiguration.StorageSize)
13421343
}
13431344
if tenantReq.PrometheusConfiguration.StorageClass != "" {
1344-
prometheusStorageClass = tenantReq.PrometheusConfiguration.StorageClass
1345+
prometheusStorageClass = stringPtr(tenantReq.PrometheusConfiguration.StorageClass)
13451346
}
13461347
if tenantReq.PrometheusConfiguration.Image != "" {
13471348
prometheusImage = tenantReq.PrometheusConfiguration.Image
@@ -1356,7 +1357,7 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre
13561357

13571358
minInst.Spec.Prometheus = &miniov2.PrometheusConfig{
13581359
DiskCapacityDB: swag.Int(prometheusDiskSpace),
1359-
StorageClassName: &prometheusStorageClass,
1360+
StorageClassName: prometheusStorageClass,
13601361
}
13611362
if prometheusImage != "" {
13621363
minInst.Spec.Prometheus.Image = prometheusImage

operatorapi/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ func GenerateTenantConfigurationFile(configuration map[string]string) string {
6363
}
6464
return rawConfiguration
6565
}
66+
67+
// Create a copy of a string and return its pointer
68+
func stringPtr(str string) *string {
69+
return &str
70+
}

0 commit comments

Comments
 (0)