/
config.go
74 lines (66 loc) · 1.81 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
package provider
import (
"fmt"
"io"
"net"
"strings"
"github.com/BurntSushi/toml"
"github.com/virtual-kubelet/node-cli/provider"
)
type providerConfig struct {
ResourceGroup string
Region string
OperatingSystem string
CPU string
Memory string
Pods string
SubnetName string
SubnetCIDR string
}
func (p *ACIProvider) loadConfig(r io.Reader) error {
var config providerConfig
if _, err := toml.DecodeReader(r, &config); err != nil {
return err
}
p.region = config.Region
p.resourceGroup = config.ResourceGroup
// Default to 20 mcpu
p.cpu = "20"
if config.CPU != "" {
p.cpu = config.CPU
}
// Default to 100Gi
p.memory = "100Gi"
if config.Memory != "" {
p.memory = config.Memory
}
// Default to 20 pods
p.pods = "20"
if config.Pods != "" {
p.pods = config.Pods
}
// Default to Linux if the operating system was not defined in the config.
if config.OperatingSystem == "" {
config.OperatingSystem = provider.OperatingSystemLinux
} else {
// Validate operating system from config.
ok := provider.ValidOperatingSystems[config.OperatingSystem]
if !ok {
return fmt.Errorf("%q is not a valid operating system, try one of the following instead: %s", config.OperatingSystem, strings.Join(provider.ValidOperatingSystems.Names(), " | "))
}
}
// default subnet name
if config.SubnetName != "" {
p.subnetName = config.SubnetName
}
if config.SubnetCIDR != "" {
if config.SubnetName == "" {
return fmt.Errorf("subnet CIDR is set but no subnet name provided, must provide a subnet name in order to set a subnet CIDR")
}
if _, _, err := net.ParseCIDR(config.SubnetCIDR); err != nil {
return fmt.Errorf("error parsing provided subnet CIDR: %v", err)
}
}
p.operatingSystem = config.OperatingSystem
return nil
}