@@ -11,6 +11,7 @@ import (
11
11
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
12
12
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
13
13
"github.com/stretchr/testify/assert"
14
+ batchv1 "k8s.io/api/batch/v1"
14
15
corev1 "k8s.io/api/core/v1"
15
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
17
"k8s.io/apimachinery/pkg/labels"
@@ -141,22 +142,22 @@ func TestBuildRequest(t *testing.T) {
141
142
assert .NotContains (t , containerfile , content )
142
143
}
143
144
144
- buildPod := br .Builder ().GetObject ().(* corev1. Pod )
145
+ buildJob := br .Builder ().GetObject ().(* batchv1. Job )
145
146
146
- _ , err = NewBuilder (buildPod )
147
+ _ , err = NewBuilder (buildJob )
147
148
assert .NoError (t , err )
148
149
149
150
assert .Equal (t , "containerfile-worker-afc35db0f874c9bfdc586e6ba39f1504" , configmaps [0 ].Name )
150
151
assert .Equal (t , "mc-worker-afc35db0f874c9bfdc586e6ba39f1504" , configmaps [1 ].Name )
151
- assert .Equal (t , "build-worker-afc35db0f874c9bfdc586e6ba39f1504" , buildPod .Name )
152
+ assert .Equal (t , "build-worker-afc35db0f874c9bfdc586e6ba39f1504" , buildJob .Name )
152
153
153
154
secrets , err := br .Secrets ()
154
155
assert .NoError (t , err )
155
156
156
157
objects := []metav1.Object {
157
158
configmaps [0 ],
158
159
configmaps [1 ],
159
- buildPod ,
160
+ buildJob ,
160
161
secrets [0 ],
161
162
secrets [1 ],
162
163
}
@@ -174,7 +175,7 @@ func TestBuildRequest(t *testing.T) {
174
175
assert .Equal (t , secrets [0 ].Name , "base-worker-afc35db0f874c9bfdc586e6ba39f1504" )
175
176
assert .Equal (t , secrets [1 ].Name , "final-worker-afc35db0f874c9bfdc586e6ba39f1504" )
176
177
177
- assertBuildPodIsCorrect (t , buildPod , opts )
178
+ assertBuildJobIsCorrect (t , buildJob , opts )
178
179
})
179
180
}
180
181
}
@@ -190,37 +191,37 @@ func assertSecretInCorrectFormat(t *testing.T, secret *corev1.Secret) {
190
191
assert .JSONEq (t , string (secret .Data [corev1 .DockerConfigJsonKey ]), `{"auths":{"registry.hostname.com": {"username": "user", "password": "s3kr1t", "auth": "s00pers3kr1t", "email": "user@hostname.com"}}}` )
191
192
}
192
193
193
- func assertBuildPodIsCorrect (t * testing.T , buildPod * corev1. Pod , opts BuildRequestOpts ) {
194
+ func assertBuildJobIsCorrect (t * testing.T , buildJob * batchv1. Job , opts BuildRequestOpts ) {
194
195
etcRpmGpgKeysOpts := optsForEtcRpmGpgKeys ()
195
- assertBuildPodMatchesExpectations (t , opts .HasEtcPkiRpmGpgKeys , buildPod ,
196
+ assertBuildJobMatchesExpectations (t , opts .HasEtcPkiRpmGpgKeys , buildJob ,
196
197
etcRpmGpgKeysOpts .envVar (),
197
198
etcRpmGpgKeysOpts .volumeForSecret (constants .EtcPkiRpmGpgSecretName ),
198
199
etcRpmGpgKeysOpts .volumeMount (),
199
200
)
200
201
201
202
etcYumReposDOpts := optsForEtcYumReposD ()
202
- assertBuildPodMatchesExpectations (t , opts .HasEtcYumReposDConfigs , buildPod ,
203
+ assertBuildJobMatchesExpectations (t , opts .HasEtcYumReposDConfigs , buildJob ,
203
204
etcYumReposDOpts .envVar (),
204
205
etcYumReposDOpts .volumeForConfigMap (),
205
206
etcYumReposDOpts .volumeMount (),
206
207
)
207
208
208
209
etcPkiEntitlementKeysOpts := optsForEtcPkiEntitlements ()
209
- assertBuildPodMatchesExpectations (t , opts .HasEtcPkiEntitlementKeys , buildPod ,
210
+ assertBuildJobMatchesExpectations (t , opts .HasEtcPkiEntitlementKeys , buildJob ,
210
211
etcPkiEntitlementKeysOpts .envVar (),
211
212
etcPkiEntitlementKeysOpts .volumeForSecret (constants .EtcPkiEntitlementSecretName + "-" + opts .MachineOSConfig .Spec .MachineConfigPool .Name ),
212
213
etcPkiEntitlementKeysOpts .volumeMount (),
213
214
)
214
215
215
- assert .Equal (t , buildPod .Spec .Containers [0 ].Image , mcoImagePullspec )
216
+ assert .Equal (t , buildJob . Spec . Template .Spec .Containers [0 ].Image , mcoImagePullspec )
216
217
expectedPullspecs := []string {
217
218
"base-os-image-from-machineosconfig" ,
218
219
fixtures .OSImageURLConfig ().BaseOSContainerImage ,
219
220
}
220
221
221
- assert .Contains (t , expectedPullspecs , buildPod .Spec .Containers [1 ].Image )
222
+ assert .Contains (t , expectedPullspecs , buildJob . Spec . Template .Spec .Containers [1 ].Image )
222
223
223
- assertPodHasVolume (t , buildPod , corev1.Volume {
224
+ assertPodHasVolume (t , buildJob . Spec . Template . Spec , corev1.Volume {
224
225
Name : "final-image-push-creds" ,
225
226
VolumeSource : corev1.VolumeSource {
226
227
Secret : & corev1.SecretVolumeSource {
@@ -235,7 +236,7 @@ func assertBuildPodIsCorrect(t *testing.T, buildPod *corev1.Pod, opts BuildReque
235
236
},
236
237
})
237
238
238
- assertPodHasVolume (t , buildPod , corev1.Volume {
239
+ assertPodHasVolume (t , buildJob . Spec . Template . Spec , corev1.Volume {
239
240
Name : "base-image-pull-creds" ,
240
241
VolumeSource : corev1.VolumeSource {
241
242
Secret : & corev1.SecretVolumeSource {
@@ -251,20 +252,20 @@ func assertBuildPodIsCorrect(t *testing.T, buildPod *corev1.Pod, opts BuildReque
251
252
})
252
253
}
253
254
254
- func assertPodHasVolume (t * testing.T , pod * corev1.Pod , volume corev1.Volume ) {
255
- assert .Contains (t , pod .Spec . Volumes , volume )
255
+ func assertPodHasVolume (t * testing.T , pod corev1.PodSpec , volume corev1.Volume ) {
256
+ assert .Contains (t , pod .Volumes , volume )
256
257
}
257
258
258
- func assertBuildPodMatchesExpectations (t * testing.T , shouldBePresent bool , buildPod * corev1. Pod , envvar corev1.EnvVar , volume corev1.Volume , volumeMount corev1.VolumeMount ) {
259
- for _ , container := range buildPod .Spec .Containers {
259
+ func assertBuildJobMatchesExpectations (t * testing.T , shouldBePresent bool , buildJob * batchv1. Job , envvar corev1.EnvVar , volume corev1.Volume , volumeMount corev1.VolumeMount ) {
260
+ for _ , container := range buildJob . Spec . Template .Spec .Containers {
260
261
if shouldBePresent {
261
262
assert .Contains (t , container .Env , envvar )
262
263
assert .Contains (t , container .VolumeMounts , volumeMount )
263
- assertPodHasVolume (t , buildPod , volume )
264
+ assertPodHasVolume (t , buildJob . Spec . Template . Spec , volume )
264
265
} else {
265
266
assert .NotContains (t , container .Env , envvar )
266
267
assert .NotContains (t , container .VolumeMounts , volumeMount )
267
- assert .NotContains (t , buildPod .Spec .Volumes , volume )
268
+ assert .NotContains (t , buildJob . Spec . Template .Spec .Volumes , volume )
268
269
}
269
270
270
271
assert .Contains (t , container .Env , corev1.EnvVar {
0 commit comments