forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet.go
48 lines (42 loc) · 878 Bytes
/
net.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
package net
import (
"bytes"
"text/template"
)
const (
CALICO = "calico"
FLANNEL = "flannel"
defaultInterface = "eth.*|en.*"
defaultCIDR = "100.64.0.0/10"
)
type MetaData struct {
Interface string
CIDR string
// ipip mode for calico.yml
IPIP bool
// MTU size
MTU string
}
// Net is CNI interface
type Net interface {
// if template is "" using default template
Manifests(template string) string
// return cni template file
Template() string
}
func NewNetwork(t string, metadata MetaData) Net {
switch t {
case CALICO:
return &Calico{metadata: metadata}
case FLANNEL:
return &Flannel{metadata: metadata}
default:
return &Calico{metadata: metadata}
}
}
func render(data MetaData, temp string) string {
var b bytes.Buffer
t := template.Must(template.New("net").Parse(temp))
t.Execute(&b, &data)
return b.String()
}