forked from kubernetes/kops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
104 lines (93 loc) · 2.96 KB
/
client.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
/*
Copyright 2018 The Kubernetes 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 main
import (
"time"
"k8s.io/kops/node-authorizer/pkg/client"
"github.com/urfave/cli"
)
// addClientCommand creates and returns a client command
func addClientCommand() cli.Command {
return cli.Command{
Name: "client",
Usage: "starts the service in a client mode and attempts to acquire a bootstrap token",
Flags: []cli.Flag{
cli.StringFlag{
Name: "authorizer",
Usage: "provider we should use to authorize the node registration `NAME`",
EnvVar: "AUTHORIZER",
Value: "aws",
},
cli.StringFlag{
Name: "node-url",
Usage: "the url for the node authorizer service `URL`",
EnvVar: "NODE_AUTHORIZER_URL",
},
cli.StringFlag{
Name: "kubeapi-url",
Usage: "the url for the kubernetes api `URL`",
EnvVar: "KUBEAPI_URL",
},
cli.StringFlag{
Name: "kubeconfig",
Usage: "location to write bootstrap token config `PATH`",
EnvVar: "KUBECONFIG_BOOTSTRAP",
Value: "/var/lib/kubelet/bootstrap-kubeconfig",
},
cli.StringFlag{
Name: "tls-client-ca",
Usage: "file containing the certificate authority used to verify node endpoint `PATH`",
EnvVar: "TLS_CLIENT_CA",
},
cli.StringFlag{
Name: "tls-cert",
Usage: "file containing the client certificate `PATH`",
EnvVar: "TLS_CERT",
},
cli.StringFlag{
Name: "tls-private-key",
Usage: "file containing the client private key `PATH`",
EnvVar: "TLS_PRIVATE_KEY",
},
cli.DurationFlag{
Name: "interval",
Usage: "an interval to wait between failed request `DURATION`",
EnvVar: "INTERVAL",
Value: 3 * time.Second,
},
cli.DurationFlag{
Name: "timeout",
Usage: "the max time to wait before timing out `DURATION`",
EnvVar: "TIMEOUT",
Value: 30 * time.Second,
},
},
Action: func(ctx *cli.Context) error {
return actionClientCommand(ctx)
},
}
}
// actionClientCommand is the client action
func actionClientCommand(ctx *cli.Context) error {
return client.New(&client.Config{
Authorizer: ctx.String("authorizer"),
Interval: ctx.Duration("interval"),
KubeAPI: ctx.String("kubeapi-url"),
KubeConfigPath: ctx.String("kubeconfig"),
NodeURL: ctx.String("node-url"),
TLSCertPath: ctx.String("tls-cert"),
TLSClientCAPath: ctx.String("tls-client-ca"),
TLSPrivateKeyPath: ctx.String("tls-private-key"),
Timeout: ctx.Duration("timeout"),
})
}