Skip to content

Commit 625557d

Browse files
andrewlecuyerjkatz
authored andcommitted
Update logic for obtaining the global
custom configuration configMap to pull from the proper (i.e. cluster) namespace, and to ensure a user provided custom configMap takes precedence over the global configMap (if available).
1 parent 3ebd9fc commit 625557d

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

operator/cluster/clusterlogic.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ package cluster
1919
*/
2020

2121
import (
22-
"strings"
2322
"bytes"
2423
"encoding/json"
24+
"fmt"
2525
"os"
26+
"strings"
2627
"time"
2728

2829
crv1 "github.com/crunchydata/postgres-operator/apis/cr/v1"
@@ -154,20 +155,22 @@ func AddCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl *cr
154155
operator.AddDefaultPostgresHaConfigMap(clientset, cl, deploymentFields.IsInit, true, namespace)
155156
} else {
156157
configMap, found := kubeapi.GetConfigMap(clientset, strings.Trim(deploymentFields.ConfVolume, "\""), namespace)
157-
if found {
158-
if _, exists := configMap.Data[config.PostgresHaTemplatePath]; !exists {
159-
log.Debugf("Custom postgres-ha config file not found in custom configMap, " +
160-
"creating default configMap with default postgres-ha config file")
161-
operator.AddDefaultPostgresHaConfigMap(clientset, cl, deploymentFields.IsInit, true, namespace)
162-
} else {
163-
log.Debugf("Custom postgres-ha config file found in custom configMap, " +
164-
"creating default configMap without default postgres-ha config file")
165-
operator.AddDefaultPostgresHaConfigMap(clientset, cl, deploymentFields.IsInit, false, namespace)
166-
}
167-
} else {
158+
if !found {
159+
err = fmt.Errorf("Unable to find custom configMap %s configured for deplyment %s when "+
160+
"creating the default postgres-ha config file", deploymentFields.ConfVolume,
161+
deploymentFields.Name)
168162
log.Error(err.Error())
169163
return err
170164
}
165+
if _, exists := configMap.Data[config.PostgresHaTemplatePath]; !exists {
166+
log.Debugf("Custom postgres-ha config file not found in custom configMap, " +
167+
"creating default configMap with default postgres-ha config file")
168+
operator.AddDefaultPostgresHaConfigMap(clientset, cl, deploymentFields.IsInit, true, namespace)
169+
} else {
170+
log.Debugf("Custom postgres-ha config file found in custom configMap, " +
171+
"creating default configMap without default postgres-ha config file")
172+
operator.AddDefaultPostgresHaConfigMap(clientset, cl, deploymentFields.IsInit, false, namespace)
173+
}
171174
}
172175

173176
log.Debug("collectaddon value is [" + deploymentFields.CollectAddon + "]")

operator/clusterutilities.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,24 @@ func GetConfVolume(clientset *kubernetes.Clientset, cl *crv1.Pgcluster, namespac
258258
var found bool
259259
var configMapStr string
260260

261+
//check for user provided configmap
262+
if cl.Spec.CustomConfig != "" {
263+
_, found = kubeapi.GetConfigMap(clientset, cl.Spec.CustomConfig, namespace)
264+
if !found {
265+
//you should NOT get this error because of apiserver validation of this value!
266+
log.Errorf("%s was not found, error, skipping user provided configMap", cl.Spec.CustomConfig)
267+
} else {
268+
log.Debugf("user provided configmap %s was used for this cluster", cl.Spec.CustomConfig)
269+
return "\"" + cl.Spec.CustomConfig + "\""
270+
}
271+
}
272+
261273
//check for global custom configmap "pgo-custom-pg-config"
262-
_, found = kubeapi.GetConfigMap(clientset, config.GLOBAL_CUSTOM_CONFIGMAP, PgoNamespace)
274+
_, found = kubeapi.GetConfigMap(clientset, config.GLOBAL_CUSTOM_CONFIGMAP, namespace)
263275
if found {
264-
configMapStr = "\"pgo-custom-pg-config\""
265-
} else {
266-
log.Debug(config.GLOBAL_CUSTOM_CONFIGMAP + " was not found, skipping global configMap")
267-
268-
//check for user provided configmap
269-
if cl.Spec.CustomConfig != "" {
270-
_, found = kubeapi.GetConfigMap(clientset, cl.Spec.CustomConfig, namespace)
271-
if !found {
272-
//you should NOT get this error because of apiserver validation of this value!
273-
log.Errorf("%s was not found, error, skipping user provided configMap", cl.Spec.CustomConfig)
274-
} else {
275-
log.Debugf("user provided configmap %s was used for this cluster", cl.Spec.CustomConfig)
276-
configMapStr = "\"" + cl.Spec.CustomConfig + "\""
277-
}
278-
}
276+
return "\"pgo-custom-pg-config\""
279277
}
278+
log.Debug(config.GLOBAL_CUSTOM_CONFIGMAP + " was not found, skipping global configMap")
280279

281280
return configMapStr
282281
}

0 commit comments

Comments
 (0)