-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
37 lines (32 loc) · 1.01 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"encoding/json"
"fmt"
)
type localClusterConfig struct {
KubeConfigPath string `json:"kubeConfigPath"`
}
type remoteClusterConfig struct {
KubeConfigPath string `json:"kubeConfigPath"`
APIURL string `json:"apiURL"`
CAURL string `json:"caURL"`
SATokenPath string `json:"saTokenPath"`
}
// Config holds the application configuration
type Config struct {
Local localClusterConfig `json:"local"`
Remotes []*remoteClusterConfig `json:"remotes"`
}
func parseConfig(rawConfig []byte) (*Config, error) {
conf := &Config{}
if err := json.Unmarshal(rawConfig, conf); err != nil {
return nil, fmt.Errorf("error unmarshalling config: %v", err)
}
// Check for mandatory remote config.
for _, r := range conf.Remotes {
if (r.APIURL == "" || r.CAURL == "" || r.SATokenPath == "") && r.KubeConfigPath == "" {
return nil, fmt.Errorf("Insufficient configuration to create remote cluster client. Set kubeConfigPath or apiURL and caURL and saTokenPath")
}
}
return conf, nil
}