Skip to content

Commit 55cb557

Browse files
author
jmccormick2001
committed
put ina check for the backrest configmap
1 parent e4095b5 commit 55cb557

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

apiserver/clusterservice/clusterimpl.go

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
451451
}
452452
}
453453

454+
if request.CustomConfig != "" {
455+
found := validateCustomConfig(request.CustomConfig)
456+
if !found {
457+
resp.Status.Code = msgs.Error
458+
resp.Status.Msg = request.CustomConfig + " configmap was not found "
459+
return resp
460+
}
461+
//add a label for the custom config
462+
userLabelsMap[util.LABEL_CUSTOM_CONFIG] = request.CustomConfig
463+
}
454464
//set the metrics flag with the global setting first
455465
userLabelsMap[util.LABEL_COLLECT] = strconv.FormatBool(apiserver.MetricsFlag)
456466
if err != nil {
@@ -498,6 +508,13 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
498508
userLabelsMap[util.LABEL_BACKREST] = strconv.FormatBool(apiserver.Pgo.Cluster.Backrest)
499509
}
500510

511+
err = validateBackrestConfig(userLabelsMap)
512+
if err != nil {
513+
resp.Status.Code = msgs.Error
514+
resp.Status.Msg = err.Error()
515+
return resp
516+
}
517+
501518
//add archive if backrest is requested
502519
if userLabelsMap[util.LABEL_BACKREST] == "true" {
503520
userLabelsMap[util.LABEL_ARCHIVE] = "true"
@@ -569,17 +586,6 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
569586
}
570587
}
571588

572-
if request.CustomConfig != "" {
573-
found := validateCustomConfig(request.CustomConfig)
574-
if !found {
575-
resp.Status.Code = msgs.Error
576-
resp.Status.Msg = request.CustomConfig + " configmap was not found "
577-
return resp
578-
}
579-
//add a label for the custom config
580-
userLabelsMap["custom-config"] = request.CustomConfig
581-
}
582-
583589
if request.SecretFrom != "" {
584590
err = validateSecretFrom(request.SecretFrom)
585591
if err != nil {
@@ -979,3 +985,24 @@ func getReplicas(cluster *crv1.Pgcluster) ([]msgs.ShowClusterReplica, error) {
979985

980986
return output, err
981987
}
988+
989+
func validateBackrestConfig(labels map[string]string) error {
990+
var err error
991+
992+
if labels[util.LABEL_BACKREST] == "true" {
993+
if labels[util.LABEL_CUSTOM_CONFIG] != "" {
994+
//TODO could check the contents of that config map here tomake sure it include a pgbackrest.conf key
995+
return err
996+
} else {
997+
//check the global configmap here
998+
_, found := kubeapi.GetConfigMap(apiserver.Clientset, util.GLOBAL_CUSTOM_CONFIGMAP, apiserver.Namespace)
999+
if !found {
1000+
log.Debug(util.GLOBAL_CUSTOM_CONFIGMAP + " was not found")
1001+
return errors.New(util.GLOBAL_CUSTOM_CONFIGMAP + " global configmap or --custom-config flag not set, one of these is required for enabling pgbackrest")
1002+
}
1003+
1004+
}
1005+
}
1006+
return err
1007+
1008+
}

0 commit comments

Comments
 (0)