-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
71 lines (55 loc) · 1.11 KB
/
options.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
package gkube
import (
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type HelperOption interface {
ApplyToHelper(*helper)
}
func (h *helper) ApplyOptions(opts []HelperOption) {
for _, o := range opts {
o.ApplyToHelper(h)
}
}
// Client Option
func WithClient(c client.Client) k8sClient {
return k8sClient{c}
}
type k8sClient struct {
client.Client
}
func (c k8sClient) ApplyToHelper(opts *helper) {
opts.Client = c.Client
}
// Config Option
func WithConfig(c *rest.Config) k8sConfig {
return k8sConfig{c}
}
type k8sConfig struct {
*rest.Config
}
func (c k8sConfig) ApplyToHelper(opts *helper) {
opts.Config = c.Config
}
// Scheme Option
func WithScheme(s *runtime.Scheme) k8sScheme {
return k8sScheme{s}
}
type k8sScheme struct {
*runtime.Scheme
}
func (s k8sScheme) ApplyToHelper(opts *helper) {
opts.Scheme = s.Scheme
}
// Context Option
func WithContext(c context.Context) k8sContext {
return k8sContext{c}
}
type k8sContext struct {
context.Context
}
func (c k8sContext) ApplyToHelper(opts *helper) {
opts.Context = c.Context
}