Skip to content

Commit ee27048

Browse files
author
Jeff McCormick
committed
add client config validations
1 parent 674aea8 commit ee27048

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

client/cmd/cluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func showCluster(args []string) {
6262
//each arg represents a cluster name or the special 'all' value
6363
for _, arg := range args {
6464
for _, cluster := range clusterList.Items {
65-
fmt.Println("")
65+
//fmt.Println("")
6666
if arg == "all" || cluster.Spec.Name == arg {
6767
itemFound = true
6868
if PostgresVersion == "" || (PostgresVersion != "" && cluster.Spec.POSTGRES_FULL_VERSION == PostgresVersion) {
@@ -81,6 +81,7 @@ func showCluster(args []string) {
8181
}
8282
}
8383
}
84+
fmt.Println("")
8485
}
8586
if !itemFound {
8687
fmt.Println(arg + " was not found")

client/cmd/root.go

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ package cmd
1717
import (
1818
log "github.com/Sirupsen/logrus"
1919
"os"
20+
"strconv"
2021

22+
"github.com/crunchydata/postgres-operator/tpr"
2123
"github.com/fatih/color"
2224
"github.com/spf13/cobra"
2325
"github.com/spf13/viper"
26+
27+
"k8s.io/client-go/pkg/api"
28+
"k8s.io/client-go/pkg/api/resource"
2429
)
2530

2631
var RED, GREEN func(a ...interface{}) string
@@ -119,11 +124,8 @@ func initConfig() {
119124
}
120125

121126
log.Debug("namespace is " + viper.GetString("NAMESPACE"))
122-
if viper.GetString("MASTER_STORAGE.STORAGE_TYPE") == "dynamic" ||
123-
viper.GetString("REPLICA_STORAGE.STORAGE_TYPE") == "dynamic" {
124-
log.Error("STORAGE_TYPE dynamic is not supported yet")
125-
os.Exit(2)
126-
}
127+
128+
validateConfig()
127129

128130
ConnectToKube()
129131

@@ -137,3 +139,79 @@ func initConfig() {
137139
*/
138140

139141
}
142+
143+
func validateConfig() {
144+
switch viper.GetString("MASTER_STORAGE.PVC_ACCESS_MODE") {
145+
case string(api.ReadWriteOnce), string(api.ReadWriteMany), string(api.ReadOnlyMany):
146+
default:
147+
log.Error("invalid MASTER_STORAGE.PVC_ACCESS_MODE specified")
148+
os.Exit(2)
149+
}
150+
switch viper.GetString("REPLICA_STORAGE.PVC_ACCESS_MODE") {
151+
case string(api.ReadWriteOnce), string(api.ReadWriteMany), string(api.ReadOnlyMany):
152+
default:
153+
log.Error("invalid REPLICA_STORAGE.PVC_ACCESS_MODE specified")
154+
os.Exit(2)
155+
}
156+
switch viper.GetString("MASTER_STORAGE.STORAGE_TYPE") {
157+
case tpr.STORAGE_EXISTING, tpr.STORAGE_CREATE, tpr.STORAGE_EMPTYDIR, tpr.STORAGE_DYNAMIC:
158+
default:
159+
log.Error("invalid MASTER_STORAGE.STORAGE_TYPE specified")
160+
os.Exit(2)
161+
}
162+
switch viper.GetString("REPLICA_STORAGE.STORAGE_TYPE") {
163+
case tpr.STORAGE_EXISTING, tpr.STORAGE_CREATE, tpr.STORAGE_EMPTYDIR, tpr.STORAGE_DYNAMIC:
164+
default:
165+
log.Error("invalid REPLICA_STORAGE.STORAGE_TYPE specified")
166+
os.Exit(2)
167+
}
168+
169+
if viper.GetString("MASTER_STORAGE.STORAGE_TYPE") == "dynamic" ||
170+
viper.GetString("REPLICA_STORAGE.STORAGE_TYPE") == "dynamic" {
171+
log.Error("STORAGE_TYPE dynamic is not supported yet")
172+
os.Exit(2)
173+
}
174+
175+
rep := viper.GetString("CLUSTER.REPLICAS")
176+
if rep != "" {
177+
_, err := strconv.Atoi(rep)
178+
if err != nil {
179+
log.Error("CLUSTER.REPLICAS not a valid integer")
180+
os.Exit(2)
181+
}
182+
}
183+
port := viper.GetString("CLUSTER.PORT")
184+
if port != "" {
185+
_, err := strconv.Atoi(port)
186+
if err != nil {
187+
log.Error("CLUSTER.PORT not a valid integer")
188+
os.Exit(2)
189+
}
190+
}
191+
strategy := viper.GetString("CLUSTER.STRATEGY")
192+
if strategy != "" {
193+
_, err := strconv.Atoi(strategy)
194+
if err != nil {
195+
log.Error("CLUSTER.STRATEGY not a valid integer")
196+
os.Exit(2)
197+
}
198+
}
199+
200+
pvcsize := viper.GetString("MASTER_STORAGE.PVC_SIZE")
201+
if pvcsize != "" {
202+
_, err := resource.ParseQuantity(pvcsize)
203+
if err != nil {
204+
log.Error("MASTER_STORAGE.PVC_SIZE not a valid quantity")
205+
os.Exit(2)
206+
}
207+
}
208+
pvcsize = viper.GetString("REPLICA_STORAGE.PVC_SIZE")
209+
if pvcsize != "" {
210+
_, err := resource.ParseQuantity(pvcsize)
211+
if err != nil {
212+
log.Error("REPLICA_STORAGE.PVC_SIZE not a valid quantity")
213+
os.Exit(2)
214+
}
215+
}
216+
217+
}

tpr/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const PGROOT_SECRET_SUFFIX = "-pgroot-secret"
2424
const PGUSER_SECRET_SUFFIX = "-pguser-secret"
2525
const PGMASTER_SECRET_SUFFIX = "-pgmaster-secret"
2626

27+
const STORAGE_EXISTING = "existing"
28+
const STORAGE_CREATE = "create"
29+
const STORAGE_EMPTYDIR = "emptydir"
30+
const STORAGE_DYNAMIC = "dynamic"
31+
2732
type PgStorageSpec struct {
2833
PvcName string `json:"pvcname"`
2934
StorageClass string `json:"storageclass"`

0 commit comments

Comments
 (0)