-
Notifications
You must be signed in to change notification settings - Fork 53
/
config.go
118 lines (108 loc) · 3.26 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"os"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
func LoadConfig(ctx *pulumi.Context) *Config {
var clusterConfig ClusterConfig
namePrefix := config.Require(ctx, "opni:namePrefix")
zoneID := config.Require(ctx, "opni:zoneID")
useLocalCharts := config.GetBool(ctx, "opni:useLocalCharts")
chartsRepo := config.Get(ctx, "opni:chartsRepo")
chartVersion := config.Get(ctx, "opni:chartVersion")
config.GetObject(ctx, "opni:cluster", &clusterConfig)
tags := map[string]string{}
config.GetObject(ctx, "opni:tags", &tags)
useIdInDnsNames := config.GetBool(ctx, "opni:useIdInDnsNames")
clusterConfig.LoadDefaults()
var cloud, imageRepo, imageTag, minimalImageTag string
if value, ok := os.LookupEnv("CLOUD"); ok {
cloud = value
} else {
cloud = config.Get(ctx, "opni:cloud")
}
if value, ok := os.LookupEnv("IMAGE_REPO"); ok {
imageRepo = value
} else {
imageRepo = config.Get(ctx, "opni:imageRepo")
}
if value, ok := os.LookupEnv("IMAGE_TAG"); ok {
imageTag = value
} else {
imageTag = config.Get(ctx, "opni:imageTag")
}
if value, ok := os.LookupEnv("MINIMAL_IMAGE_TAG"); ok {
minimalImageTag = value
} else {
minimalImageTag = config.Get(ctx, "opni:minimalImageTag")
}
conf := &Config{
NamePrefix: namePrefix,
ZoneID: zoneID,
Cloud: cloud,
ImageRepo: imageRepo,
ImageTag: imageTag,
MinimalImageTag: minimalImageTag,
UseLocalCharts: useLocalCharts,
ChartsRepo: chartsRepo,
ChartVersion: chartVersion,
Cluster: clusterConfig,
Tags: tags,
UseIdInDnsNames: useIdInDnsNames,
}
conf.LoadDefaults()
return conf
}
type Config struct {
NamePrefix string `json:"namePrefix"`
ZoneID string `json:"zoneID"`
Cloud string `json:"cloud"`
ImageRepo string `json:"imageRepo"`
ImageTag string `json:"imageTag"`
MinimalImageTag string `json:"minimalImageTag"`
UseLocalCharts bool `json:"useLocalCharts"`
ChartsRepo string `json:"chartsRepo"`
ChartVersion string `json:"chartVersion"`
Cluster ClusterConfig `json:"cluster"`
Tags map[string]string `json:"tags"`
UseIdInDnsNames bool `json:"useIdInDnsNames"`
}
type ClusterConfig struct {
NodeInstanceType string `json:"nodeInstanceType"`
NodeGroupMinSize int `json:"nodeGroupMinSize"`
NodeGroupMaxSize int `json:"nodeGroupMaxSize"`
NodeGroupDesiredSize int `json:"nodeGroupDesiredSize"`
}
func (c *Config) LoadDefaults() {
if c.Cloud == "" {
c.Cloud = "aws"
}
if c.ImageRepo == "" {
c.ImageRepo = "rancher/opni"
}
if c.ImageTag == "" {
c.ImageTag = "latest"
}
if c.MinimalImageTag == "" {
c.MinimalImageTag = "latest-minimal"
}
if c.ChartsRepo == "" {
c.ChartsRepo = "https://raw.githubusercontent.com/rancher/opni/charts-repo/"
}
c.Cluster.LoadDefaults()
}
func (c *ClusterConfig) LoadDefaults() {
if c.NodeInstanceType == "" {
c.NodeInstanceType = "r6a.xlarge"
}
if c.NodeGroupMinSize == 0 {
c.NodeGroupMinSize = 3
}
if c.NodeGroupMaxSize == 0 {
c.NodeGroupMaxSize = 3
}
if c.NodeGroupDesiredSize == 0 {
c.NodeGroupDesiredSize = 3
}
}