6
6
"github.com/choerodon/choerodon-cluster-agent/manager"
7
7
"github.com/choerodon/choerodon-cluster-agent/pkg/cluster"
8
8
"github.com/choerodon/choerodon-cluster-agent/pkg/cluster/kubernetes"
9
- k8sclient "k8s.io/client-go/kubernetes"
10
- meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
9
"github.com/choerodon/choerodon-cluster-agent/pkg/git"
12
10
"github.com/choerodon/choerodon-cluster-agent/pkg/helm"
13
11
"github.com/choerodon/choerodon-cluster-agent/pkg/kube"
@@ -17,6 +15,8 @@ import (
17
15
"github.com/choerodon/choerodon-cluster-agent/ws"
18
16
"github.com/golang/glog"
19
17
"github.com/spf13/pflag"
18
+ meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
+ k8sclient "k8s.io/client-go/kubernetes"
20
20
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
21
21
"net/http"
22
22
"os"
@@ -36,12 +36,19 @@ const (
36
36
)
37
37
38
38
type AgentOptions struct {
39
- Listen string
40
- UpstreamURL string
41
- Token string
39
+ Listen string
40
+ UpstreamURL string
41
+ Token string
42
+ ReadLimit int64
43
+ ConnectionTimeout time.Duration
44
+ WriteTimeout time.Duration
45
+ HealthCheckDuration time.Duration
46
+ HealthCheckTimeout time.Duration
47
+ HealthCheckTryNumber int32
48
+
42
49
PrintVersion bool
43
50
// kubernetes controller
44
- PlatformCode string
51
+ PlatformCode string
45
52
ConcurrentEndpointSyncs int32
46
53
ConcurrentServiceSyncs int32
47
54
ConcurrentRSSyncs int32
@@ -127,8 +134,15 @@ func Run(o *AgentOptions, f cmdutil.Factory) {
127
134
128
135
checkKube (kubeClient .GetKubeClient ())
129
136
137
+ appClient , err := ws .NewClient (ws .Token (o .Token ), o .UpstreamURL , chans , & ws.Conf {
138
+ ReadLimit : o .ReadLimit ,
139
+ ConnectionTimeout : o .ConnectionTimeout ,
140
+ WriteTimeout : o .WriteTimeout ,
141
+ HealthCheckTryNumber : o .HealthCheckTryNumber ,
142
+ HealthCheckTimeout : o .HealthCheckTimeout ,
143
+ HealthCheckDuration : o .HealthCheckDuration ,
144
+ })
130
145
131
- appClient , err := ws .NewClient (ws .Token (o .Token ), o .UpstreamURL , chans )
132
146
if err != nil {
133
147
errChan <- err
134
148
return
@@ -137,14 +151,14 @@ func Run(o *AgentOptions, f cmdutil.Factory) {
137
151
138
152
//gitRemote := git.Remote{URL: o.gitURL}
139
153
gitConfig := git.Config {
140
- Branch : o .gitBranch ,
141
- Path : o .gitPath ,
142
- UserName : o .gitUser ,
143
- GitUrl : o .gitURL ,
144
- UserEmail : o .gitEmail ,
145
- SyncTag : o .gitSyncTag ,
146
- DevOpsTag : o .gitDevOpsSyncTag ,
147
- NotesRef : o .gitNotesRef ,
154
+ Branch : o .gitBranch ,
155
+ Path : o .gitPath ,
156
+ UserName : o .gitUser ,
157
+ GitUrl : o .gitURL ,
158
+ UserEmail : o .gitEmail ,
159
+ SyncTag : o .gitSyncTag ,
160
+ DevOpsTag : o .gitDevOpsSyncTag ,
161
+ NotesRef : o .gitNotesRef ,
148
162
GitPollInterval : o .gitPollInterval ,
149
163
}
150
164
//gitRepo := git.NewRepo(gitRemote, git.PollInterval(o.gitPollInterval))
@@ -178,7 +192,6 @@ func Run(o *AgentOptions, f cmdutil.Factory) {
178
192
// k8sManifests = &kubernetes.Manifests{Namespace: o.Namespace}
179
193
//}
180
194
181
-
182
195
namespaces := manager .NewNamespaces ()
183
196
184
197
ctx := controller .CreateControllerContext (
@@ -204,11 +217,11 @@ func Run(o *AgentOptions, f cmdutil.Factory) {
204
217
glog .Fatal (err )
205
218
}
206
219
glog .Infof ("kubectl %s" , kubectl )
207
- cfg ,_ := f .ClientConfig ()
220
+ cfg , _ := f .ClientConfig ()
208
221
kubectlApplier := kubernetes .NewKubectl (kubectl , cfg )
209
222
kubectlApplier .ApplySingleObj ("kube-system" , model .CRD_YAML )
210
223
211
- k8s = kubernetes .NewCluster ( kubeClient .GetKubeClient (), kubeClient .GetC7NClient (), kubectlApplier )
224
+ k8s = kubernetes .NewCluster (kubeClient .GetKubeClient (), kubeClient .GetC7NClient (), kubectlApplier )
212
225
k8sManifests = & kubernetes.Manifests {}
213
226
}
214
227
workerManager := worker .NewWorkerManager (
@@ -233,15 +246,12 @@ func Run(o *AgentOptions, f cmdutil.Factory) {
233
246
go workerManager .Start ()
234
247
shutdownWg .Add (1 )
235
248
236
-
237
-
238
249
go func () {
239
250
errChan <- http .ListenAndServe (o .Listen , nil )
240
251
}()
241
252
242
253
}
243
254
244
-
245
255
func (o * AgentOptions ) BindFlags (fs * pflag.FlagSet ) {
246
256
fs .BoolVar (& o .PrintVersion , "version" , false , "print the version number" )
247
257
fs .StringVar (& o .Listen , "listen" , o .Listen , "address:port to listen on" )
@@ -250,6 +260,12 @@ func (o *AgentOptions) BindFlags(fs *pflag.FlagSet) {
250
260
fs .StringVar (& o .UpstreamURL , "connect" , "" , "Connect to an upstream service" )
251
261
fs .StringVar (& o .Token , "token" , "" , "Authentication token for upstream service" )
252
262
fs .Int32Var (& o .ClusterId , "clusterId" , 0 , "the env cluster id in devops" )
263
+ fs .Int64Var (& o .ReadLimit , "readLimit" , 524288 , "message read size" )
264
+ fs .DurationVar (& o .ConnectionTimeout , "connectionTimeout" , 10 * time .Second , "connection server timeout, default 10 second." )
265
+ fs .DurationVar (& o .WriteTimeout , "writeTimeout" , 3 * time .Second , "write message timeout, default 3 second." )
266
+ fs .DurationVar (& o .HealthCheckDuration , "healthCheckDuration" , 3 * time .Second , "health check duration." )
267
+ fs .DurationVar (& o .HealthCheckTimeout , "healthCheckTimeout" , 10 * time .Second , "health check wait pong duration." )
268
+ fs .Int32Var (& o .HealthCheckTryNumber , "healthCheckTryNumber" , int32 (3 ), "health check max try number." )
253
269
254
270
// kubernetes controller
255
271
fs .StringVar (& o .PlatformCode , "choerodon-id" , "" , "choerodon platform id label" )
@@ -279,13 +295,12 @@ func (o *AgentOptions) BindFlags(fs *pflag.FlagSet) {
279
295
fs .StringVar (& o .kubernetesKubectl , "kubernetes-kubectl" , "" , "Optional, explicit path to kubectl tool" )
280
296
}
281
297
282
- func checkKube (client * k8sclient.Clientset ) {
298
+ func checkKube (client * k8sclient.Clientset ) {
283
299
glog .Infof ("check k8s role binding..." )
284
300
_ , err := client .CoreV1 ().Pods ("" ).List (meta_v1.ListOptions {})
285
301
if err != nil {
286
302
glog .Errorf ("check role binding failed %v" , err )
287
- os .Exit (0 )
303
+ os .Exit (0 )
288
304
}
289
305
glog .Infof (" k8s role binding succeed." )
290
306
}
291
-
0 commit comments