-
Notifications
You must be signed in to change notification settings - Fork 14
/
create_configmap.go
78 lines (67 loc) · 1.66 KB
/
create_configmap.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
package nodedns
import (
"context"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/op"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
type createConfigMapOp struct {
apiserver *cke.Node
clusterIP string
domain string
dnsServers []string
finished bool
}
// CreateConfigMapOp returns an Operator to create ConfigMap for unbound daemonset.
func CreateConfigMapOp(apiserver *cke.Node, clusterIP, domain string, dnsServers []string) cke.Operator {
return &createConfigMapOp{
apiserver: apiserver,
clusterIP: clusterIP,
domain: domain,
dnsServers: dnsServers,
}
}
func (o *createConfigMapOp) Name() string {
return "create-node-dns-configmap"
}
func (o *createConfigMapOp) NextCommand() cke.Commander {
if o.finished {
return nil
}
o.finished = true
return createConfigMapCommand{o.apiserver, o.clusterIP, o.domain, o.dnsServers}
}
type createConfigMapCommand struct {
apiserver *cke.Node
clusterIP string
domain string
dnsServers []string
}
func (c createConfigMapCommand) Run(ctx context.Context, inf cke.Infrastructure) error {
cs, err := inf.K8sClient(ctx, c.apiserver)
if err != nil {
return err
}
// ConfigMap
configs := cs.CoreV1().ConfigMaps("kube-system")
_, err = configs.Get(op.NodeDNSAppName, v1.GetOptions{})
switch {
case err == nil:
case errors.IsNotFound(err):
configMap := ConfigMap(c.clusterIP, c.domain, c.dnsServers)
_, err = configs.Create(configMap)
if err != nil {
return err
}
default:
return err
}
return nil
}
func (c createConfigMapCommand) Command() cke.Command {
return cke.Command{
Name: "createConfigMapCommand",
Target: "kube-system",
}
}