-
Notifications
You must be signed in to change notification settings - Fork 407
/
Copy pathapply_addons.go
261 lines (222 loc) · 7.46 KB
/
apply_addons.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
Copyright 2021 The OpenYurt Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubernetes
import (
"context"
"fmt"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"github.com/openyurtio/openyurt/pkg/projectinfo"
"github.com/openyurtio/openyurt/pkg/yurtctl/constants"
"github.com/openyurtio/openyurt/pkg/yurtctl/util/edgenode"
)
func DeployYurtControllerManager(client *kubernetes.Clientset, yurtControllerManagerImage string) error {
if err := CreateServiceAccountFromYaml(client,
"kube-system", constants.YurtControllerManagerServiceAccount); err != nil {
return err
}
// create the clusterrole
if err := CreateClusterRoleFromYaml(client,
constants.YurtControllerManagerClusterRole); err != nil {
return err
}
// bind the clusterrole
if err := CreateClusterRoleBindingFromYaml(client,
constants.YurtControllerManagerClusterRoleBinding); err != nil {
return err
}
// create the yurt-controller-manager deployment
if err := CreateDeployFromYaml(client,
"kube-system",
constants.YurtControllerManagerDeployment,
map[string]string{
"image": yurtControllerManagerImage,
"edgeNodeLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}
return nil
}
func DeployYurtAppManager(
client *kubernetes.Clientset,
yurtappmanagerImage string,
yurtAppManagerClient dynamic.Interface,
systemArchitecture string) error {
// 1.create the YurtAppManagerCustomResourceDefinition
// 1.1 nodepool
if err := CreateCRDFromYaml(client, yurtAppManagerClient, "", []byte(constants.YurtAppManagerNodePool)); err != nil {
return err
}
// 1.2 uniteddeployment
if err := CreateCRDFromYaml(client, yurtAppManagerClient, "", []byte(constants.YurtAppManagerUnitedDeployment)); err != nil {
return err
}
// 2. create the YurtAppManagerRole
if err := CreateRoleFromYaml(client, "kube-system",
constants.YurtAppManagerRole); err != nil {
return err
}
// 3. create the ClusterRole
if err := CreateClusterRoleFromYaml(client,
constants.YurtAppManagerClusterRole); err != nil {
return err
}
// 4. create the RoleBinding
if err := CreateRoleBindingFromYaml(client, "kube-system",
constants.YurtAppManagerRolebinding); err != nil {
return err
}
// 5. create the ClusterRoleBinding
if err := CreateClusterRoleBindingFromYaml(client,
constants.YurtAppManagerClusterRolebinding); err != nil {
return err
}
// 6. create the Secret
if err := CreateSecretFromYaml(client, "kube-system",
constants.YurtAppManagerSecret); err != nil {
return err
}
// 7. create the Service
if err := CreateServiceFromYaml(client,
constants.YurtAppManagerService); err != nil {
return err
}
// 8. create the Deployment
if err := CreateDeployFromYaml(client,
"kube-system",
constants.YurtAppManagerDeployment,
map[string]string{
"image": yurtappmanagerImage,
"arch": systemArchitecture,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}
// 9. create the YurtAppManagerMutatingWebhookConfiguration
if err := CreateMutatingWebhookConfigurationFromYaml(client,
constants.YurtAppManagerMutatingWebhookConfiguration); err != nil {
return err
}
// 10. create the YurtAppManagerValidatingWebhookConfiguration
if err := CreateValidatingWebhookConfigurationFromYaml(client,
constants.YurtAppManagerValidatingWebhookConfiguration); err != nil {
return err
}
return nil
}
func DeployYurttunnelServer(
client *kubernetes.Clientset,
cloudNodes []string,
yurttunnelServerImage string,
systemArchitecture string) error {
// 1. create the ClusterRole
if err := CreateClusterRoleFromYaml(client,
constants.YurttunnelServerClusterRole); err != nil {
return err
}
// 2. create the ServiceAccount
if err := CreateServiceAccountFromYaml(client, "kube-system",
constants.YurttunnelServerServiceAccount); err != nil {
return err
}
// 3. create the ClusterRoleBinding
if err := CreateClusterRoleBindingFromYaml(client,
constants.YurttunnelServerClusterRolebinding); err != nil {
return err
}
// 4. create the Service
if err := CreateServiceFromYaml(client,
constants.YurttunnelServerService); err != nil {
return err
}
// 5. create the internal Service(type=ClusterIP)
if err := CreateServiceFromYaml(client,
constants.YurttunnelServerInternalService); err != nil {
return err
}
// 6. create the Configmap
if err := CreateConfigMapFromYaml(client,
"kube-system",
constants.YurttunnelServerConfigMap); err != nil {
return err
}
// 7. create the Deployment
if err := CreateDeployFromYaml(client,
"kube-system",
constants.YurttunnelServerDeployment,
map[string]string{
"image": yurttunnelServerImage,
"arch": systemArchitecture,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}
return nil
}
func DeployYurttunnelAgent(
client *kubernetes.Clientset,
tunnelServerAddress string,
yurttunnelAgentImage string) error {
// 1. Deploy the yurt-tunnel-agent DaemonSet
if err := CreateDaemonSetFromYaml(client,
constants.YurttunnelAgentDaemonSet,
map[string]string{
"image": yurttunnelAgentImage,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey(),
"tunnelServerAddress": tunnelServerAddress}); err != nil {
return err
}
return nil
}
// DeployYurthubSetting deploy clusterrole, clusterrolebinding for yurthub static pod.
func DeployYurthubSetting(client *kubernetes.Clientset) error {
// 1. create the ClusterRole
if err := CreateClusterRoleFromYaml(client, edgenode.YurthubClusterRole); err != nil {
return err
}
// 2. create the ClusterRoleBinding
if err := CreateClusterRoleBindingFromYaml(client, edgenode.YurthubClusterRoleBinding); err != nil {
return err
}
// 3. create the Configmap
if err := CreateConfigMapFromYaml(client,
"kube-system",
edgenode.YurthubConfigMap); err != nil {
return err
}
return nil
}
// DeleteYurthubSetting rm settings for yurthub pod
func DeleteYurthubSetting(client *kubernetes.Clientset) error {
// 1. delete the ClusterRoleBinding
if err := client.RbacV1().ClusterRoleBindings().
Delete(context.Background(), edgenode.YurthubComponentName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the clusterrolebinding/%s: %s",
edgenode.YurthubComponentName, err)
}
// 2. delete the ClusterRole
if err := client.RbacV1().ClusterRoles().
Delete(context.Background(), edgenode.YurthubComponentName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the clusterrole/%s: %s",
edgenode.YurthubComponentName, err)
}
// 3. remove the ConfigMap
if err := client.CoreV1().ConfigMaps(edgenode.YurthubNamespace).
Delete(context.Background(), edgenode.YurthubCmName,
metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("fail to delete the configmap/%s: %s",
edgenode.YurthubCmName, err)
}
return nil
}