@@ -3,11 +3,13 @@ package imagereferencemutators
3
3
import (
4
4
"fmt"
5
5
6
- appsv1beta1 "k8s.io/api/apps/v1beta1"
6
+ kappsv1 "k8s.io/api/apps/v1"
7
+ kappsv1beta1 "k8s.io/api/apps/v1beta1"
8
+ kappsv1beta2 "k8s.io/api/apps/v1beta2"
7
9
batchv1 "k8s.io/api/batch/v1"
10
+ batchv1beta1 "k8s.io/api/batch/v1beta1"
8
11
batchv2alpha1 "k8s.io/api/batch/v2alpha1"
9
12
corev1 "k8s.io/api/core/v1"
10
- kapiv1 "k8s.io/api/core/v1"
11
13
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
12
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
15
"k8s.io/apimachinery/pkg/runtime"
@@ -93,38 +95,72 @@ func GetPodSpec(obj runtime.Object) (*kapi.PodSpec, *field.Path, error) {
93
95
// GetPodSpecV1 returns a mutable pod spec out of the provided object, including a field path
94
96
// to the field in the object, or an error if the object does not contain a pod spec.
95
97
// This only returns pod specs for v1 compatible objects.
96
- func GetPodSpecV1 (obj runtime.Object ) (* kapiv1 .PodSpec , * field.Path , error ) {
98
+ func GetPodSpecV1 (obj runtime.Object ) (* corev1 .PodSpec , * field.Path , error ) {
97
99
switch r := obj .(type ) {
98
- case * kapiv1.Pod :
100
+
101
+ case * corev1.Pod :
99
102
return & r .Spec , field .NewPath ("spec" ), nil
100
- case * kapiv1.PodTemplate :
103
+
104
+ case * corev1.PodTemplate :
101
105
return & r .Template .Spec , field .NewPath ("template" , "spec" ), nil
102
- case * kapiv1.ReplicationController :
106
+
107
+ case * corev1.ReplicationController :
103
108
if r .Spec .Template != nil {
104
109
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
105
110
}
111
+
106
112
case * extensionsv1beta1.DaemonSet :
107
113
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
114
+ case * kappsv1.DaemonSet :
115
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
116
+ case * kappsv1beta2.DaemonSet :
117
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
118
+
108
119
case * extensionsv1beta1.Deployment :
109
120
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
121
+ case * kappsv1.Deployment :
122
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
123
+ case * kappsv1beta1.Deployment :
124
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
125
+ case * kappsv1beta2.Deployment :
126
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
127
+
110
128
case * extensionsv1beta1.ReplicaSet :
111
129
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
130
+ case * kappsv1.ReplicaSet :
131
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
132
+ case * kappsv1beta2.ReplicaSet :
133
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
134
+
112
135
case * batchv1.Job :
113
136
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
137
+
114
138
case * batchv2alpha1.CronJob :
115
139
return & r .Spec .JobTemplate .Spec .Template .Spec , field .NewPath ("spec" , "jobTemplate" , "spec" , "template" , "spec" ), nil
140
+ case * batchv1beta1.CronJob :
141
+ return & r .Spec .JobTemplate .Spec .Template .Spec , field .NewPath ("spec" , "jobTemplate" , "spec" , "template" , "spec" ), nil
142
+
116
143
case * batchv2alpha1.JobTemplate :
117
144
return & r .Template .Spec .Template .Spec , field .NewPath ("template" , "spec" , "template" , "spec" ), nil
118
- case * appsv1beta1.StatefulSet :
145
+ case * batchv1beta1.JobTemplate :
146
+ return & r .Template .Spec .Template .Spec , field .NewPath ("template" , "spec" , "template" , "spec" ), nil
147
+
148
+ case * kappsv1.StatefulSet :
149
+ return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
150
+ case * kappsv1beta1.StatefulSet :
119
151
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
120
- case * appsv1beta1. Deployment :
152
+ case * kappsv1beta2. StatefulSet :
121
153
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
154
+
122
155
case * securityv1.PodSecurityPolicySubjectReview :
123
156
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
157
+
124
158
case * securityv1.PodSecurityPolicySelfSubjectReview :
125
159
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
160
+
126
161
case * securityv1.PodSecurityPolicyReview :
127
162
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
163
+
128
164
case * appsv1.DeploymentConfig :
129
165
if r .Spec .Template != nil {
130
166
return & r .Spec .Template .Spec , field .NewPath ("spec" , "template" , "spec" ), nil
@@ -137,68 +173,101 @@ func GetPodSpecV1(obj runtime.Object) (*kapiv1.PodSpec, *field.Path, error) {
137
173
// the object contains, or false if no such object is available.
138
174
func GetTemplateMetaObject (obj runtime.Object ) (metav1.Object , bool ) {
139
175
switch r := obj .(type ) {
140
- case * kapiv1.PodTemplate :
176
+
177
+ case * kapi.PodTemplate :
178
+ return & r .Template .ObjectMeta , true
179
+ case * corev1.PodTemplate :
141
180
return & r .Template .ObjectMeta , true
142
- case * kapiv1.ReplicationController :
181
+
182
+ case * kapi.ReplicationController :
183
+ if r .Spec .Template != nil {
184
+ return & r .Spec .Template .ObjectMeta , true
185
+ }
186
+ case * corev1.ReplicationController :
143
187
if r .Spec .Template != nil {
144
188
return & r .Spec .Template .ObjectMeta , true
145
189
}
190
+
191
+ case * extensions.DaemonSet :
192
+ return & r .Spec .Template .ObjectMeta , true
146
193
case * extensionsv1beta1.DaemonSet :
147
194
return & r .Spec .Template .ObjectMeta , true
148
- case * extensionsv1beta1. Deployment :
195
+ case * kappsv1. DaemonSet :
149
196
return & r .Spec .Template .ObjectMeta , true
150
- case * extensionsv1beta1. ReplicaSet :
197
+ case * kappsv1beta2. DaemonSet :
151
198
return & r .Spec .Template .ObjectMeta , true
152
- case * batchv1.Job :
199
+
200
+ case * extensions.Deployment :
153
201
return & r .Spec .Template .ObjectMeta , true
154
- case * batchv2alpha1.CronJob :
155
- return & r .Spec .JobTemplate .Spec .Template .ObjectMeta , true
156
- case * batchv2alpha1.JobTemplate :
157
- return & r .Template .Spec .Template .ObjectMeta , true
158
- case * appsv1beta1.StatefulSet :
202
+ case * extensionsv1beta1.Deployment :
159
203
return & r .Spec .Template .ObjectMeta , true
160
- case * appsv1beta1 .Deployment :
204
+ case * kappsv1 .Deployment :
161
205
return & r .Spec .Template .ObjectMeta , true
162
- case * securityv1. PodSecurityPolicySubjectReview :
206
+ case * kappsv1beta1. Deployment :
163
207
return & r .Spec .Template .ObjectMeta , true
164
- case * securityv1. PodSecurityPolicySelfSubjectReview :
208
+ case * kappsv1beta2. Deployment :
165
209
return & r .Spec .Template .ObjectMeta , true
166
- case * securityv1.PodSecurityPolicyReview :
210
+
211
+ case * extensions.ReplicaSet :
167
212
return & r .Spec .Template .ObjectMeta , true
168
- case * appsv1.DeploymentConfig :
169
- if r .Spec .Template != nil {
170
- return & r .Spec .Template .ObjectMeta , true
171
- }
172
- case * kapi.PodTemplate :
173
- return & r .Template .ObjectMeta , true
174
- case * kapi.ReplicationController :
175
- if r .Spec .Template != nil {
176
- return & r .Spec .Template .ObjectMeta , true
177
- }
178
- case * extensions.DaemonSet :
213
+ case * extensionsv1beta1.ReplicaSet :
179
214
return & r .Spec .Template .ObjectMeta , true
180
- case * extensions. Deployment :
215
+ case * kappsv1. ReplicaSet :
181
216
return & r .Spec .Template .ObjectMeta , true
182
- case * extensions .ReplicaSet :
217
+ case * kappsv1beta2 .ReplicaSet :
183
218
return & r .Spec .Template .ObjectMeta , true
219
+
184
220
case * batch.Job :
185
221
return & r .Spec .Template .ObjectMeta , true
222
+ case * batchv1.Job :
223
+ return & r .Spec .Template .ObjectMeta , true
224
+
186
225
case * batch.CronJob :
187
226
return & r .Spec .JobTemplate .Spec .Template .ObjectMeta , true
227
+ case * batchv2alpha1.CronJob :
228
+ return & r .Spec .JobTemplate .Spec .Template .ObjectMeta , true
229
+ case * batchv1beta1.CronJob :
230
+ return & r .Spec .JobTemplate .Spec .Template .ObjectMeta , true
231
+
188
232
case * batch.JobTemplate :
189
233
return & r .Template .Spec .Template .ObjectMeta , true
234
+ case * batchv2alpha1.JobTemplate :
235
+ return & r .Template .Spec .Template .ObjectMeta , true
236
+ case * batchv1beta1.JobTemplate :
237
+ return & r .Template .Spec .Template .ObjectMeta , true
238
+
190
239
case * apps.StatefulSet :
191
240
return & r .Spec .Template .ObjectMeta , true
241
+ case * kappsv1.StatefulSet :
242
+ return & r .Spec .Template .ObjectMeta , true
243
+ case * kappsv1beta1.StatefulSet :
244
+ return & r .Spec .Template .ObjectMeta , true
245
+ case * kappsv1beta2.StatefulSet :
246
+ return & r .Spec .Template .ObjectMeta , true
247
+
192
248
case * securityapi.PodSecurityPolicySubjectReview :
193
249
return & r .Spec .Template .ObjectMeta , true
250
+ case * securityv1.PodSecurityPolicySubjectReview :
251
+ return & r .Spec .Template .ObjectMeta , true
252
+
194
253
case * securityapi.PodSecurityPolicySelfSubjectReview :
195
254
return & r .Spec .Template .ObjectMeta , true
255
+ case * securityv1.PodSecurityPolicySelfSubjectReview :
256
+ return & r .Spec .Template .ObjectMeta , true
257
+
196
258
case * securityapi.PodSecurityPolicyReview :
197
259
return & r .Spec .Template .ObjectMeta , true
260
+ case * securityv1.PodSecurityPolicyReview :
261
+ return & r .Spec .Template .ObjectMeta , true
262
+
198
263
case * appsapi.DeploymentConfig :
199
264
if r .Spec .Template != nil {
200
265
return & r .Spec .Template .ObjectMeta , true
201
266
}
267
+ case * appsv1.DeploymentConfig :
268
+ if r .Spec .Template != nil {
269
+ return & r .Spec .Template .ObjectMeta , true
270
+ }
202
271
}
203
272
return nil , false
204
273
}
@@ -212,7 +281,7 @@ func (m containerMutator) GetImage() string { return m.Image }
212
281
func (m containerMutator ) SetImage (image string ) { m .Image = image }
213
282
214
283
type containerV1Mutator struct {
215
- * kapiv1 .Container
284
+ * corev1 .Container
216
285
}
217
286
218
287
func (m containerV1Mutator ) GetName () string { return m .Name }
@@ -322,16 +391,16 @@ func (m *podSpecMutator) GetContainerByIndex(init bool, i int) (ContainerMutator
322
391
323
392
// podSpecV1Mutator implements the mutation interface over objects with a pod spec.
324
393
type podSpecV1Mutator struct {
325
- spec * kapiv1 .PodSpec
326
- oldSpec * kapiv1 .PodSpec
394
+ spec * corev1 .PodSpec
395
+ oldSpec * corev1 .PodSpec
327
396
path * field.Path
328
397
}
329
398
330
399
func (m * podSpecV1Mutator ) Path () * field.Path {
331
400
return m .path
332
401
}
333
402
334
- func hasIdenticalPodSpecV1Image (spec * kapiv1 .PodSpec , containerName , image string ) bool {
403
+ func hasIdenticalPodSpecV1Image (spec * corev1 .PodSpec , containerName , image string ) bool {
335
404
if spec == nil {
336
405
return false
337
406
}
@@ -405,7 +474,7 @@ func (m *podSpecV1Mutator) GetContainerByName(name string) (ContainerMutator, bo
405
474
}
406
475
407
476
func (m * podSpecV1Mutator ) GetContainerByIndex (init bool , i int ) (ContainerMutator , bool ) {
408
- var container * kapiv1 .Container
477
+ var container * corev1 .Container
409
478
spec := m .spec
410
479
if init {
411
480
if i < 0 || i >= len (spec .InitContainers ) {
0 commit comments