Skip to content

Commit be4837f

Browse files
author
Jeff McCormick
committed
add node labels to pgo.yaml support
1 parent bcbd95d commit be4837f

File tree

7 files changed

+101
-19
lines changed

7 files changed

+101
-19
lines changed

apiserver/clusterservice/clusterimpl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
547547
}
548548
}
549549

550+
if apiserver.Pgo.Cluster.PrimaryNodeLabel != "" {
551+
//already should be validate at apiserver startup
552+
parts := strings.Split(apiserver.Pgo.Cluster.PrimaryNodeLabel, "=")
553+
userLabelsMap[util.LABEL_NODE_LABEL_KEY] = parts[0]
554+
userLabelsMap[util.LABEL_NODE_LABEL_VALUE] = parts[1]
555+
log.Debug("primary node labels used from pgo.yaml")
556+
}
557+
550558
if request.NodeLabel != "" {
551559
parts := strings.Split(request.NodeLabel, "=")
552560
if len(parts) != 2 {
@@ -572,6 +580,7 @@ func CreateCluster(request *msgs.CreateClusterRequest) msgs.CreateClusterRespons
572580
resp.Status.Msg = request.NodeLabel + " node label value was not valid .. check node labels for correct values to specify"
573581
return resp
574582
}
583+
log.Debug("primary node labels used from user entered flag")
575584
userLabelsMap[util.LABEL_NODE_LABEL_KEY] = parts[0]
576585
userLabelsMap[util.LABEL_NODE_LABEL_VALUE] = parts[1]
577586
}

apiserver/clusterservice/scaleimpl.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ func ScaleCluster(name, replicaCount, resourcesConfig, storageConfig, nodeLabel,
9696
}
9797

9898
var parts []string
99+
100+
if apiserver.Pgo.Cluster.ReplicaNodeLabel != "" {
101+
//should have been validated at apiserver startup
102+
parts = strings.Split(apiserver.Pgo.Cluster.ReplicaNodeLabel, "=")
103+
spec.UserLabels[util.LABEL_NODE_LABEL_KEY] = parts[0]
104+
spec.UserLabels[util.LABEL_NODE_LABEL_VALUE] = parts[1]
105+
log.Debug("using pgo.yaml ReplicaNodeLabel for replica creation")
106+
}
107+
99108
//validate nodeLabel
100109
if nodeLabel != "" {
101110
parts = strings.Split(nodeLabel, "=")
@@ -124,6 +133,7 @@ func ScaleCluster(name, replicaCount, resourcesConfig, storageConfig, nodeLabel,
124133
}
125134
spec.UserLabels[util.LABEL_NODE_LABEL_KEY] = parts[0]
126135
spec.UserLabels[util.LABEL_NODE_LABEL_VALUE] = parts[1]
136+
log.Debug("using user entered node label for replica creation")
127137

128138
}
129139

apiserver/root.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func Initialize() {
8787

8888
Pgo.GetConf()
8989
log.Println("CCPImageTag=" + Pgo.Cluster.CCPImageTag)
90+
log.Println("PrimaryNodeLabel=" + Pgo.Cluster.PrimaryNodeLabel)
9091
Pgo.Validate()
9192

9293
Namespace = os.Getenv("NAMESPACE")
@@ -116,6 +117,7 @@ func Initialize() {
116117

117118
ConnectToKube()
118119

120+
validateWithKube()
119121
}
120122

121123
// ConnectToKube ...
@@ -456,3 +458,38 @@ func initTemplates() {
456458
JobTemplate = util.LoadTemplate(LoadTemplatePath)
457459

458460
}
461+
462+
func validateWithKube() {
463+
log.Debug("validateWithKube called")
464+
465+
configNodeLabels := make([]string, 2)
466+
configNodeLabels[0] = Pgo.Cluster.PrimaryNodeLabel
467+
configNodeLabels[1] = Pgo.Cluster.ReplicaNodeLabel
468+
469+
for _, n := range configNodeLabels {
470+
471+
if n != "" {
472+
parts := strings.Split(n, "=")
473+
if len(parts) != 2 {
474+
log.Error(n + " node label in pgo.yaml does not follow key=value format")
475+
os.Exit(2)
476+
}
477+
478+
keyValid, valueValid, err := IsValidNodeLabel(parts[0], parts[1])
479+
if err != nil {
480+
log.Error(err)
481+
os.Exit(2)
482+
}
483+
484+
if !keyValid {
485+
log.Error(n + " key not a valid node label key in pgo.yaml")
486+
os.Exit(2)
487+
}
488+
if !valueValid {
489+
log.Error(n + "value not a valid node label value in pgo.yaml ")
490+
os.Exit(2)
491+
}
492+
log.Debug(n + " is a valid pgo.yaml node label default")
493+
}
494+
}
495+
}

conf/apiserver/pgo.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Cluster:
2+
PrimaryNodeLabel:
3+
ReplicaNodeLabel:
24
CCPImagePrefix: crunchydata
35
Metrics: false
46
Badger: false

config/pgoconfig.go

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,31 @@ import (
2222
"gopkg.in/yaml.v2"
2323
"io/ioutil"
2424
"strconv"
25+
"strings"
2526
)
2627

27-
const PGO_VERSION = "3.2"
28+
//const PGO_VERSION = "3.2"
2829

2930
type ClusterStruct struct {
30-
CCPImagePrefix string `yaml:"CCPImagePrefix"`
31-
CCPImageTag string `yaml:"CCPImageTag"`
32-
Policies string `yaml:"Policies"`
33-
Metrics bool `yaml:"Metrics"`
34-
Badger bool `yaml:"Badger"`
35-
Port string `yaml:"Port"`
36-
ArchiveTimeout string `yaml:"ArchiveTimeout"`
37-
ArchiveMode string `yaml:"ArchiveMode"`
38-
User string `yaml:"User"`
39-
Database string `yaml:"Database"`
40-
PasswordAgeDays string `yaml:"PasswordAgeDays"`
41-
PasswordLength string `yaml:"PasswordLength"`
42-
Strategy string `yaml:"Strategy"`
43-
Replicas string `yaml:"Replicas"`
44-
ServiceType string `yaml:"ServiceType"`
45-
Backrest bool `yaml:"Backrest"`
46-
Autofail bool `yaml:"Autofail"`
31+
CCPImagePrefix string `yaml:"CCPImagePrefix"`
32+
CCPImageTag string `yaml:"CCPImageTag"`
33+
PrimaryNodeLabel string `yaml:"PrimaryNodeLabel"`
34+
ReplicaNodeLabel string `yaml:"ReplicaNodeLabel"`
35+
Policies string `yaml:"Policies"`
36+
Metrics bool `yaml:"Metrics"`
37+
Badger bool `yaml:"Badger"`
38+
Port string `yaml:"Port"`
39+
ArchiveTimeout string `yaml:"ArchiveTimeout"`
40+
ArchiveMode string `yaml:"ArchiveMode"`
41+
User string `yaml:"User"`
42+
Database string `yaml:"Database"`
43+
PasswordAgeDays string `yaml:"PasswordAgeDays"`
44+
PasswordLength string `yaml:"PasswordLength"`
45+
Strategy string `yaml:"Strategy"`
46+
Replicas string `yaml:"Replicas"`
47+
ServiceType string `yaml:"ServiceType"`
48+
Backrest bool `yaml:"Backrest"`
49+
Autofail bool `yaml:"Autofail"`
4750
}
4851

4952
type StorageStruct struct {
@@ -90,6 +93,21 @@ const LOAD_BALANCER_SERVICE_TYPE = "LoadBalancer"
9093

9194
func (c *PgoConfig) Validate() error {
9295
var err error
96+
97+
if c.Cluster.PrimaryNodeLabel != "" {
98+
parts := strings.Split(c.Cluster.PrimaryNodeLabel, "=")
99+
if len(parts) != 2 {
100+
return errors.New("Cluster.PrimaryNodeLabel does not follow key=value format")
101+
}
102+
}
103+
104+
if c.Cluster.ReplicaNodeLabel != "" {
105+
parts := strings.Split(c.Cluster.ReplicaNodeLabel, "=")
106+
if len(parts) != 2 {
107+
return errors.New("Cluster.ReplicaNodeLabel does not follow key=value format")
108+
}
109+
}
110+
93111
log.Info("pgo.yaml Cluster.Backrest is %v", c.Cluster.Backrest)
94112
_, ok := c.Storage[c.PrimaryStorage]
95113
if !ok {

hugo/content/installation/configuration.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ looks like this -
227227
....
228228
BasicAuth: true
229229
Cluster:
230+
PrimaryNodeLabel:
231+
ReplicaNodeLabel:
230232
CCPImageTag: centos7-10.5-2.1.0
231233
Metrics: false
232234
Badger: false
@@ -273,7 +275,7 @@ Pgo:
273275
LSPVCTemplate: /config/pgo.lspvc-template.json
274276
CSVLoadTemplate: /config/pgo.load-template.json
275277
COImagePrefix: crunchydata
276-
COImageTag: centos7-2.7
278+
COImageTag: centos7-3.3.0
277279
....
278280

279281
Values in the pgo configuration file have the following meaning:
@@ -283,6 +285,8 @@ Values in the pgo configuration file have the following meaning:
283285
|======================
284286
|Setting | Definition
285287
|BasicAuth | if set to *true* will enable Basic Authentication
288+
|Cluster.PrimaryNodeLabel |newly created primary deployments will specify this node label if specified, unless you override it using the --node-label command line flag, if not set, no node label is specifed
289+
|Cluster.ReplicaNodeLabel |newly created replica deployments will specify this node label if specified, unless you override it using the --node-label command line flag, if not set, no node label is specifed
286290
|Cluster.CCPImageTag |newly created containers will be based on this image version (e.g. centos7-10.4-1.8.3), unless you override it using the --ccp-image-tag command line flag
287291
|Cluster.Port | the PostgreSQL port to use for new containers (e.g. 5432)
288292
|Cluster.User | the PostgreSQL normal user name

pgo/cmd/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func showConfig(args []string) {
5353

5454
fmt.Printf("%s%s\n", "BasicAuth: ", pgo.BasicAuth)
5555
fmt.Printf("%s\n", "Cluster:")
56+
fmt.Printf("%s%s\n", " PrimaryNodeLabel: ", pgo.Cluster.PrimaryNodeLabel)
57+
fmt.Printf("%s%s\n", " ReplicaNodeLabel: ", pgo.Cluster.ReplicaNodeLabel)
5658
fmt.Printf("%s%s\n", " CCPImagePrefix: ", pgo.Cluster.CCPImagePrefix)
5759
fmt.Printf("%s%s\n", " CCPImageTag: ", pgo.Cluster.CCPImageTag)
5860
fmt.Printf("%s%s\n", " ServiceType: ", pgo.Cluster.ServiceType)

0 commit comments

Comments
 (0)