Skip to content

Commit 1b24f74

Browse files
andrewlecuyerJeff McCormick
authored andcommitted
Use the Operator namespace when looking up secret (CrunchyData#788)
'pgo-backrest-repo-config' when enabling S3 support
1 parent 7194f98 commit 1b24f74

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

operator/clusterutilities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func GetPgbackrestS3EnvVars(backrestLabel, backRestStorageTypeLabel string,
367367
PgbackrestS3Region: Pgo.Cluster.BackrestS3Region,
368368
}
369369

370-
secret, secretExists, err := kubeapi.GetSecret(clientset, "pgo-backrest-repo-config", ns)
370+
secret, secretExists, err := kubeapi.GetSecret(clientset, "pgo-backrest-repo-config", PgoNamespace)
371371
if err != nil {
372372
log.Error(err.Error())
373373
return ""

operator/common.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ import (
2929
var CRUNCHY_DEBUG bool
3030
var NAMESPACE string
3131

32+
var PgoNamespace string
33+
3234
var Pgo config.PgoConfig
3335

3436
type containerResourcesTemplateFields struct {
3537
RequestsMemory, RequestsCPU string
3638
LimitsMemory, LimitsCPU string
3739
}
3840

39-
func Initialize(clientset *kubernetes.Clientset, namespace string) {
41+
func Initialize(clientset *kubernetes.Clientset) {
4042

4143
tmp := os.Getenv("CRUNCHY_DEBUG")
4244
if tmp == "true" {
@@ -53,9 +55,15 @@ func Initialize(clientset *kubernetes.Clientset, namespace string) {
5355
log.Error("NAMESPACE env var is set to empty string which pgo intprets as meaning you want it to watch 'all' namespaces.")
5456
}
5557

58+
PgoNamespace = os.Getenv("PGO_OPERATOR_NAMESPACE")
59+
if PgoNamespace == "" {
60+
log.Error("PGO_OPERATOR_NAMESPACE environment variable is not set and is required, this is the namespace that the Operator is to run within.")
61+
os.Exit(2)
62+
}
63+
5664
var err error
5765

58-
err = Pgo.GetConfig(clientset, namespace)
66+
err = Pgo.GetConfig(clientset, PgoNamespace)
5967
if err != nil {
6068
log.Error(err)
6169
log.Error("pgo-config files and templates did not load")

postgres-operator.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
)
3838

3939
var Clientset *kubernetes.Clientset
40-
var PgoNamespace string
4140

4241
func main() {
4342
kubeconfig := flag.String("kubeconfig", "", "Path to a kube config. Only required if out-of-cluster.")
@@ -51,12 +50,6 @@ func main() {
5150
log.Info("debug flag set to false")
5251
}
5352

54-
PgoNamespace = os.Getenv("PGO_OPERATOR_NAMESPACE")
55-
if PgoNamespace == "" {
56-
log.Error("PGO_OPERATOR_NAMESPACE environment variable is not set and is required, this is the namespace that the Operator is to run within.")
57-
os.Exit(2)
58-
}
59-
6053
namespaceList := util.GetNamespaces()
6154
log.Debugf("watching the following namespaces: [%v]", namespaceList)
6255

@@ -81,7 +74,7 @@ func main() {
8174
os.Exit(2)
8275
}
8376

84-
operator.Initialize(Clientset, PgoNamespace)
77+
operator.Initialize(Clientset)
8578

8679
//validate the NAMESPACE env var
8780
err = util.ValidateNamespaces(Clientset)

0 commit comments

Comments
 (0)