@@ -451,6 +451,16 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
451
451
}
452
452
}
453
453
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
+ }
454
464
//set the metrics flag with the global setting first
455
465
userLabelsMap [util .LABEL_COLLECT ] = strconv .FormatBool (apiserver .MetricsFlag )
456
466
if err != nil {
@@ -498,6 +508,13 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
498
508
userLabelsMap [util .LABEL_BACKREST ] = strconv .FormatBool (apiserver .Pgo .Cluster .Backrest )
499
509
}
500
510
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
+
501
518
//add archive if backrest is requested
502
519
if userLabelsMap [util .LABEL_BACKREST ] == "true" {
503
520
userLabelsMap [util .LABEL_ARCHIVE ] = "true"
@@ -569,17 +586,6 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
569
586
}
570
587
}
571
588
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
-
583
589
if request .SecretFrom != "" {
584
590
err = validateSecretFrom (request .SecretFrom )
585
591
if err != nil {
@@ -979,3 +985,24 @@ func getReplicas(cluster *crv1.Pgcluster) ([]msgs.ShowClusterReplica, error) {
979
985
980
986
return output , err
981
987
}
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