-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.go
165 lines (150 loc) · 5.44 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package validate
import (
"time"
"github.com/gookit/validate"
)
type Config struct {
ClusterName string `validate:"required"`
TalosVersion string `validate:"isVersion"`
KubernetesVersion string `validate:"isVersion"`
Endpoint string `validate:"isTalosEndpoint"`
Domain string `validate:"isDomain"`
AllowSchedulingOnMasters string `validate:"isBool"`
AllowSchedulingOnControlPlanes string `validate:"isBool"`
ClusterPodNets []string `validate:"isCIDRList"`
ClusterSvcNets []string `validate:"isCIDRList"`
CniConfig *CNIConfig
Nodes []*Node
ControlPlane struct {
ConfigPatches []map[string]interface{} `validate:"isRFC6902List"`
}
Worker struct {
ConfigPatches []map[string]interface{} `validate:"isRFC6902List"`
}
}
type CNIConfig struct {
Name string `validate:"isCNIName|requiredWith:CniConfig"`
Urls []string `validate:"isURLList|requiredIf:CniConfig.Name,custom"`
}
type Node struct {
Hostname string `validate:"required"`
IPAddress string `validate:"required|isDomainOrIP"`
ControlPlane string `validate:"isBool"`
InstallDisk string `validate:"requiredWithout:Nodes.InstallDiskSelector"`
DisableSearchDomain string `validate:"isBool"`
Nameservers []string `validate:"isIPList"`
ConfigPatches []map[string]interface{} `validate:"isRFC6902List"`
NetworkInterfaces []*NetworkInterface
InstallDiskSelector *InstallDiskSelector
}
type InstallDiskSelector struct {
Size string
Name string
Model string
Modalias string
UUID string
WWID string
Type string
BusPath string
}
type NetworkInterface struct {
Interface string `validate:"required_with:Nodes.NetworkInterfaces"`
Addresses []string `validate:"isCIDRList"`
Routes []Route
Bond *Bond
Vlans []*Vlan
Mtu string `validate:"isIntString"`
Dhcp string `validate:"isBool"`
Ignore string `validate:"isBool"`
Dummy string `validate:"isBool"`
DhcpOptions *DhcpOption
Wireguard *Wireguard
Vip *Vip
}
type Route struct {
Network string `validate:"isCIDR"`
Gateway string `validate:"isIP"`
Source string `validate:"isIP"`
Metric string `validate:"isUint"`
}
type Bond struct {
Interfaces []string `validate:"requiredWith:Nodes.NetworkInterfaces.Bond"`
ArpIPTarget []string
Mode string
XmitHashPolicy string
LacpRate string
AdActorSystem string
ArpValidate string
Primary string
PrimaryReselect string
FailOverMac string
AdSelect string
MiiMon string `validate:"isUint"`
Updelay string `validate:"isUint"`
Downdelay string `validate:"isUint"`
ArpInterval string `validate:"isUint"`
ResendIgmp string `validate:"isUint"`
MinLinks string `validate:"isUint"`
LpInterval string `validate:"isUint"`
PacketsPerSlave string `validate:"isUint"`
NumPeerNotif string `validate:"isUint"`
TlbDynamicLb string `validate:"isUint"`
AllSlavesActive string `validate:"isUint"`
UseCarrier string `validate:"isBool"`
AdActorSysPrio string `validate:"isUint"`
AdUserPortKey string `validate:"isUint"`
PeerNotifyDelay string `validate:"isUint"`
}
type Vip struct {
Ip string `validate:"isIP"`
EquinixMetal struct {
ApiToken string
}
Hcloud struct {
ApiToken string
}
}
type Vlan struct {
Addresses []string `validate:"isCIDRList"`
Routes []*Route
Dhcp string `validate:"isBool"`
VlanId string `validate:"isUint"`
Mtu string `validate:"isUint"`
Vip *Vip
}
type DhcpOption struct {
RouteMetric string `validate:"isUint"`
Ipv4 string `validate:"isBool"`
Ipv6 string `validate:"isBool"`
}
type Wireguard struct {
PrivateKey string
ListenPort string `validate:"isIntString"`
FirewallMark string `validate:"isIntString"`
Peers []*Peer
}
type Peer struct {
PublicKey string
Endpoint string
PersistentKeepAliveInterval time.Duration
AllowedIPs []string
}
func (c Config) Messages() map[string]string {
return validate.MS{
"required": "{field} is required",
"CniConfig.Urls.requiredIf": "{field} is required when {args0} is \"custom\"",
"isRFC6902List": "{field} doesn't look like list of RFC 6902 JSON patches",
"isCIDR": "{field} doesn't look like CIDR notation",
"isCIDRList": "{field} doesn't look like list of CIDR notations",
"isIP": "{field} doesn't look like IP address",
"isIPList": "{field} doesn't look like list of IP addresses",
"isURLList": "{field} doesn't look like list of URLs",
"isTalosEndpoint": "{field} is not a valid Talos endpoint",
"isDomain": "{field} is not a valid domain",
"isCNIName": "{field} is not a valid CNI name (none,flannel,custom)",
"isBool": "{field} is not a valid boolean (true or false)",
"isInt": "{field} is not a valid integer",
"isUint": "{field} is not a valid unsigned integer",
"isDomainOrIP": "{field} is not a valid domain or IP address",
}
}