-
Notifications
You must be signed in to change notification settings - Fork 14
/
resource.go
54 lines (45 loc) · 1.04 KB
/
resource.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
package op
import (
"context"
"github.com/cybozu-go/cke"
)
type resourceApplyOp struct {
apiserver *cke.Node
resource cke.ResourceDefinition
finished bool
}
// ResourceApplyOp creates or updates a Kubernetes object.
func ResourceApplyOp(apiServer *cke.Node, resource cke.ResourceDefinition) cke.Operator {
return &resourceApplyOp{
apiserver: apiServer,
resource: resource,
}
}
func (o *resourceApplyOp) Name() string {
return "resource-apply"
}
func (o *resourceApplyOp) NextCommand() cke.Commander {
if o.finished {
return nil
}
o.finished = true
return o
}
func (o *resourceApplyOp) Targets() []string {
return []string{
o.apiserver.Address,
}
}
func (o *resourceApplyOp) Run(ctx context.Context, inf cke.Infrastructure, _ string) error {
cs, err := inf.K8sClient(ctx, o.apiserver)
if err != nil {
return err
}
return cke.ApplyResource(cs, o.resource.Definition, o.resource.Revision)
}
func (o *resourceApplyOp) Command() cke.Command {
return cke.Command{
Name: "apply-resource",
Target: o.resource.String(),
}
}