@@ -21,7 +21,6 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"strconv"
24
- "time"
25
24
26
25
"reflect"
27
26
@@ -30,12 +29,10 @@ import (
30
29
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
31
30
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
32
31
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
33
- "github.com/openstack-k8s-operators/lib-common/modules/common/job"
34
32
common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac"
35
- "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
36
33
testv1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
34
+ v1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
37
35
"github.com/openstack-k8s-operators/test-operator/pkg/ansibletest"
38
- batchv1 "k8s.io/api/batch/v1"
39
36
corev1 "k8s.io/api/core/v1"
40
37
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
41
38
ctrl "sigs.k8s.io/controller-runtime"
@@ -54,7 +51,6 @@ func (r *AnsibleTestReconciler) GetLogger(ctx context.Context) logr.Logger {
54
51
// +kubebuilder:rbac:groups=test.openstack.org,resources=ansibletests,verbs=get;list;watch;create;update;patch;delete
55
52
// +kubebuilder:rbac:groups=test.openstack.org,resources=ansibletests/status,verbs=get;update;patch
56
53
// +kubebuilder:rbac:groups=test.openstack.org,resources=ansibletests/finalizers,verbs=update;patch
57
- // +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;patch;update;delete;
58
54
// +kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
59
55
// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=roles,verbs=get;list;watch;create;update;patch
60
56
// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=rolebindings,verbs=get;list;watch;create;update;patch
@@ -143,12 +139,12 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
143
139
return ctrl.Result {}, err
144
140
145
141
case Wait :
146
- Log .Info (InfoWaitingOnJob )
142
+ Log .Info (InfoWaitingOnPod )
147
143
return ctrl.Result {RequeueAfter : RequeueAfterValue }, nil
148
144
149
145
case EndTesting :
150
- // All jobs created by the instance were completed. Release the lock
151
- // so that other instances can spawn their jobs .
146
+ // All pods created by the instance were completed. Release the lock
147
+ // so that other instances can spawn their pods .
152
148
if lockReleased , err := r .ReleaseLock (ctx , instance ); ! lockReleased {
153
149
Log .Info (fmt .Sprintf (InfoCanNotReleaseLock , testOperatorLockName ))
154
150
return ctrl.Result {RequeueAfter : RequeueAfterValue }, err
@@ -161,7 +157,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
161
157
Log .Info (InfoTestingCompleted )
162
158
return ctrl.Result {}, nil
163
159
164
- case CreateFirstJob :
160
+ case CreateFirstPod :
165
161
lockAcquired , err := r .AcquireLock (ctx , instance , helper , false )
166
162
if ! lockAcquired {
167
163
Log .Info (fmt .Sprintf (InfoCanNotAcquireLock , testOperatorLockName ))
@@ -170,7 +166,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
170
166
171
167
Log .Info (fmt .Sprintf (InfoCreatingFirstPod , nextWorkflowStep ))
172
168
173
- case CreateNextJob :
169
+ case CreateNextPod :
174
170
// Confirm that we still hold the lock. This is useful to check if for
175
171
// example somebody / something deleted the lock and it got claimed by
176
172
// another instance. This is considered to be an error state.
@@ -211,9 +207,9 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
211
207
212
208
instance .Status .Conditions .MarkTrue (condition .ServiceConfigReadyCondition , condition .ServiceConfigReadyMessage )
213
209
214
- // Create a new job
210
+ // Create a new pod
215
211
mountCerts := r .CheckSecretExists (ctx , instance , "combined-ca-bundle" )
216
- jobName := r .GetJobName (instance , nextWorkflowStep )
212
+ podName := r .GetPodName (instance , nextWorkflowStep )
217
213
envVars , workflowOverrideParams := r .PrepareAnsibleEnv (instance , nextWorkflowStep )
218
214
logsPVCName := r .GetPVCLogsName (instance , 0 )
219
215
containerImage , err := r .GetContainerImage (ctx , workflowOverrideParams ["ContainerImage" ], instance )
@@ -249,11 +245,10 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
249
245
return rbacResult , nil
250
246
}
251
247
// Service account, role, binding - end
252
-
253
- jobDef := ansibletest .Job (
248
+ podDef := ansibletest .Pod (
254
249
instance ,
255
250
serviceLabels ,
256
- jobName ,
251
+ podName ,
257
252
logsPVCName ,
258
253
mountCerts ,
259
254
envVars ,
@@ -262,19 +257,12 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
262
257
containerImage ,
263
258
privileged ,
264
259
)
265
- ansibleTestsJob := job .NewJob (
266
- jobDef ,
267
- testv1beta1 .ConfigHash ,
268
- true ,
269
- time .Duration (5 )* time .Second ,
270
- "" ,
271
- )
272
260
273
- ctrlResult , err = ansibleTestsJob . DoJob (ctx , helper )
261
+ ctrlResult , err = r . CreatePod (ctx , * helper , podDef )
274
262
if err != nil {
275
- // Creation of the ansibleTests job was not successfull.
263
+ // Creation of the ansibleTests pod was not successfull.
276
264
// Release the lock and allow other controllers to spawn
277
- // a job .
265
+ // a pod .
278
266
if lockReleased , err := r .ReleaseLock (ctx , instance ); ! lockReleased {
279
267
return ctrl.Result {}, err
280
268
}
@@ -294,7 +282,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
294
282
condition .DeploymentReadyRunningMessage ))
295
283
return ctrlResult , nil
296
284
}
297
- // Create a new job - end
285
+ // Create a new pod - end
298
286
Log .Info ("Reconciled Service successfully" )
299
287
return ctrl.Result {}, nil
300
288
}
@@ -303,7 +291,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
303
291
func (r * AnsibleTestReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
304
292
return ctrl .NewControllerManagedBy (mgr ).
305
293
For (& testv1beta1.AnsibleTest {}).
306
- Owns (& batchv1. Job {}).
294
+ Owns (& corev1. Pod {}).
307
295
Owns (& corev1.Secret {}).
308
296
Owns (& corev1.ConfigMap {}).
309
297
Complete (r )
0 commit comments