-
Notifications
You must be signed in to change notification settings - Fork 163
/
core.go
181 lines (169 loc) · 4.9 KB
/
core.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package resourceapply
import (
"context"
corev1 "k8s.io/api/core/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/record"
)
func ApplyConfigMapWithControl(
ctx context.Context,
control ApplyControlInterface[*corev1.ConfigMap],
recorder record.EventRecorder,
required *corev1.ConfigMap,
options ApplyOptions,
) (*corev1.ConfigMap, bool, error) {
return ApplyGeneric[*corev1.ConfigMap](ctx, control, recorder, required, options)
}
func ApplyConfigMap(
ctx context.Context,
client corev1client.ConfigMapsGetter,
lister corev1listers.ConfigMapLister,
recorder record.EventRecorder,
required *corev1.ConfigMap,
options ApplyOptions,
) (*corev1.ConfigMap, bool, error) {
return ApplyConfigMapWithControl(
ctx,
ApplyControlFuncs[*corev1.ConfigMap]{
GetCachedFunc: lister.ConfigMaps(required.Namespace).Get,
CreateFunc: client.ConfigMaps(required.Namespace).Create,
UpdateFunc: client.ConfigMaps(required.Namespace).Update,
DeleteFunc: client.ConfigMaps(required.Namespace).Delete,
},
recorder,
required,
options,
)
}
func ApplySecretWithControl(
ctx context.Context,
control ApplyControlInterface[*corev1.Secret],
recorder record.EventRecorder,
required *corev1.Secret,
options ApplyOptions,
) (*corev1.Secret, bool, error) {
return ApplyGeneric[*corev1.Secret](ctx, control, recorder, required, options)
}
func ApplySecret(
ctx context.Context,
client corev1client.SecretsGetter,
lister corev1listers.SecretLister,
recorder record.EventRecorder,
required *corev1.Secret,
options ApplyOptions,
) (*corev1.Secret, bool, error) {
return ApplySecretWithControl(
ctx,
ApplyControlFuncs[*corev1.Secret]{
GetCachedFunc: lister.Secrets(required.Namespace).Get,
CreateFunc: client.Secrets(required.Namespace).Create,
UpdateFunc: client.Secrets(required.Namespace).Update,
DeleteFunc: client.Secrets(required.Namespace).Delete,
},
recorder,
required,
options,
)
}
func ApplyServiceWithControl(
ctx context.Context,
control ApplyControlInterface[*corev1.Service],
recorder record.EventRecorder,
required *corev1.Service,
options ApplyOptions,
) (*corev1.Service, bool, error) {
return ApplyGenericWithHandlers[*corev1.Service](
ctx,
control,
recorder,
required,
options,
func(required **corev1.Service, existing *corev1.Service) {
(*required).Spec.ClusterIP = existing.Spec.ClusterIP
(*required).Spec.ClusterIPs = existing.Spec.ClusterIPs
},
nil,
)
}
func ApplyService(
ctx context.Context,
client corev1client.ServicesGetter,
lister corev1listers.ServiceLister,
recorder record.EventRecorder,
required *corev1.Service,
options ApplyOptions,
) (*corev1.Service, bool, error) {
return ApplyServiceWithControl(
ctx,
ApplyControlFuncs[*corev1.Service]{
GetCachedFunc: lister.Services(required.Namespace).Get,
CreateFunc: client.Services(required.Namespace).Create,
UpdateFunc: client.Services(required.Namespace).Update,
DeleteFunc: client.Services(required.Namespace).Delete,
},
recorder,
required,
options,
)
}
func ApplyServiceAccountWithControl(
ctx context.Context,
control ApplyControlInterface[*corev1.ServiceAccount],
recorder record.EventRecorder,
required *corev1.ServiceAccount,
options ApplyOptions,
) (*corev1.ServiceAccount, bool, error) {
return ApplyGeneric[*corev1.ServiceAccount](ctx, control, recorder, required, options)
}
func ApplyServiceAccount(
ctx context.Context,
client corev1client.ServiceAccountsGetter,
lister corev1listers.ServiceAccountLister,
recorder record.EventRecorder,
required *corev1.ServiceAccount,
options ApplyOptions,
) (*corev1.ServiceAccount, bool, error) {
return ApplyServiceAccountWithControl(
ctx,
ApplyControlFuncs[*corev1.ServiceAccount]{
GetCachedFunc: lister.ServiceAccounts(required.Namespace).Get,
CreateFunc: client.ServiceAccounts(required.Namespace).Create,
UpdateFunc: client.ServiceAccounts(required.Namespace).Update,
DeleteFunc: client.ServiceAccounts(required.Namespace).Delete,
},
recorder,
required,
options,
)
}
func ApplyNamespaceWithControl(
ctx context.Context,
control ApplyControlInterface[*corev1.Namespace],
recorder record.EventRecorder,
required *corev1.Namespace,
options ApplyOptions,
) (*corev1.Namespace, bool, error) {
return ApplyGeneric[*corev1.Namespace](ctx, control, recorder, required, options)
}
func ApplyNamespace(
ctx context.Context,
client corev1client.NamespacesGetter,
lister corev1listers.NamespaceLister,
recorder record.EventRecorder,
required *corev1.Namespace,
options ApplyOptions,
) (*corev1.Namespace, bool, error) {
return ApplyNamespaceWithControl(
ctx,
ApplyControlFuncs[*corev1.Namespace]{
GetCachedFunc: lister.Get,
CreateFunc: client.Namespaces().Create,
UpdateFunc: client.Namespaces().Update,
DeleteFunc: client.Namespaces().Delete,
},
recorder,
required,
options,
)
}