-
Notifications
You must be signed in to change notification settings - Fork 48
/
components.go
141 lines (125 loc) · 3.92 KB
/
components.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
package check
import (
"fmt"
"io/ioutil"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)
type Component struct {
ComponentName string
ClusterRole string
ClusterRoleBinding string
SecurityContextConstraints string
DaemonSets []string
Deployments []string
Secret string
MutatingWebhookConfiguration string
}
var (
KubeMacPoolComponent = Component{
ComponentName: "KubeMacPool",
ClusterRole: "kubemacpool-manager-role",
ClusterRoleBinding: "kubemacpool-manager-rolebinding",
Deployments: []string{"kubemacpool-mac-controller-manager", "kubemacpool-cert-manager"},
MutatingWebhookConfiguration: "kubemacpool-mutator",
}
LinuxBridgeComponent = Component{
ComponentName: "Linux Bridge",
ClusterRole: "bridge-marker-cr",
ClusterRoleBinding: "bridge-marker-crb",
SecurityContextConstraints: "linux-bridge",
DaemonSets: []string{
"bridge-marker",
"kube-cni-linux-bridge-plugin",
},
}
MultusComponent = Component{
ComponentName: "Multus",
ClusterRole: "multus",
ClusterRoleBinding: "multus",
SecurityContextConstraints: "multus",
DaemonSets: []string{"multus"},
}
NMStateComponent = Component{
ComponentName: "NMState",
ClusterRoleBinding: "nmstate-handler",
ClusterRole: "nmstate-handler",
SecurityContextConstraints: "nmstate",
DaemonSets: []string{
"nmstate-handler",
},
Deployments: []string{
"nmstate-webhook",
"nmstate-cert-manager",
},
MutatingWebhookConfiguration: "nmstate",
}
OvsComponent = Component{
ComponentName: "Ovs",
ClusterRole: "ovs-cni-marker-cr",
ClusterRoleBinding: "ovs-cni-marker-crb",
SecurityContextConstraints: "ovs-cni-marker",
DaemonSets: []string{
"ovs-cni-amd64",
},
}
MacvtapComponent = Component{
ComponentName: "Macvtap",
ClusterRole: "",
ClusterRoleBinding: "",
SecurityContextConstraints: "macvtap-cni",
DaemonSets: []string{
"macvtap-cni",
},
}
AllComponents = []Component{
KubeMacPoolComponent,
LinuxBridgeComponent,
MultusComponent,
NMStateComponent,
OvsComponent,
MacvtapComponent,
}
)
type ComponentUpdatePolicy string
const (
Tagged ComponentUpdatePolicy = "tagged"
Static ComponentUpdatePolicy = "static"
Latest ComponentUpdatePolicy = "latest"
)
type ComponentsConfig struct {
Components map[string]ComponentSource `yaml:"components"`
}
type ComponentSource struct {
Url string `yaml:"url"`
Commit string `yaml:"commit"`
Branch string `yaml:"branch"`
UpdatePolicy ComponentUpdatePolicy `yaml:"update-policy"`
Metadata string `yaml:"metadata"`
}
func GetComponentSource(component string) (ComponentSource, error) {
componentsConfig, err := parseComponentsYaml("components.yaml")
if err != nil {
return ComponentSource{}, errors.Wrapf(err, "Failed to get components config")
}
componentSource, ok := componentsConfig.Components[component]
if !ok {
return ComponentSource{}, errors.Wrapf(err, "Failed to get component %s", component)
}
return componentSource, nil
}
func parseComponentsYaml(componentsConfigPath string) (ComponentsConfig, error) {
config := ComponentsConfig{}
componentsData, err := ioutil.ReadFile(componentsConfigPath)
if err != nil {
return ComponentsConfig{}, errors.Wrapf(err, "Failed to open file %s", componentsConfigPath)
}
err = yaml.Unmarshal(componentsData, &config)
if err != nil {
return ComponentsConfig{}, errors.Wrapf(err, "Failed to Unmarshal %s", componentsConfigPath)
}
if len(config.Components) == 0 {
return ComponentsConfig{}, fmt.Errorf("Failed to Unmarshal %s. Output is empty", componentsConfigPath)
}
return config, nil
}