@@ -105,11 +105,13 @@ func (r *Reconciliation) initChildJobDetails() {
105
105
if r .childJob .GetKind () != types .KindJob ||
106
106
r .childJob .GetAPIVersion () != types .JobAPIVersion {
107
107
r .err = errors .Errorf (
108
- "Invalid child: Expected %s/%s : Got %s/%s " ,
108
+ "Invalid child: Expected %q %q : Got %q %q: Command %q / %q " ,
109
109
types .JobAPIVersion ,
110
110
types .KindJob ,
111
111
r .childJob .GetAPIVersion (),
112
112
r .childJob .GetKind (),
113
+ r .command .GetNamespace (),
114
+ r .command .GetName (),
113
115
)
114
116
return
115
117
}
@@ -120,31 +122,79 @@ func (r *Reconciliation) initChildJobDetails() {
120
122
}
121
123
122
124
if ! found {
125
+ klog .V (3 ).Infof (
126
+ "Job is not available: Command %q / %q" ,
127
+ r .command .GetNamespace (),
128
+ r .command .GetName (),
129
+ )
123
130
return
124
131
}
132
+
125
133
// At this point Job is present in Kubernetes cluster
126
134
r .isChildJobFound = true
127
- // Extract status.phase of this Job
128
- phase , found , err := unstructured .NestedString (
135
+
136
+ // Extract status.failed of this Job
137
+ failedCount , found , err := unstructured .NestedInt64 (
129
138
got .Object ,
130
139
"status" ,
131
- "phase " ,
140
+ "failed " ,
132
141
)
133
142
if err != nil {
134
143
r .err = errors .Wrapf (
135
144
err ,
136
- "Failed to get status.phase : Kind %q: Name %q / %q" ,
145
+ "Failed to get Job status.failed : Kind %q: Job %q / %q" ,
137
146
r .childJob .GetKind (),
138
147
r .childJob .GetNamespace (),
139
148
r .childJob .GetName (),
140
149
)
141
150
return
142
151
}
143
152
if ! found {
144
- // Job's status.phase is not set
153
+ klog .V (1 ).Infof (
154
+ "Job status.failed is not set: Kind %q: Job %q / %q" ,
155
+ r .childJob .GetKind (),
156
+ r .childJob .GetNamespace (),
157
+ r .childJob .GetName (),
158
+ )
159
+ }
160
+ if failedCount > 0 {
161
+ r .isChildJobCompleted = false
162
+ return
163
+ }
164
+
165
+ // Extract status.active of this Job
166
+ activeCount , found , err := unstructured .NestedInt64 (
167
+ got .Object ,
168
+ "status" ,
169
+ "active" ,
170
+ )
171
+ if err != nil {
172
+ r .err = errors .Wrapf (
173
+ err ,
174
+ "Failed to get Job status.active: Kind %q: Job %q / %q" ,
175
+ r .childJob .GetKind (),
176
+ r .childJob .GetNamespace (),
177
+ r .childJob .GetName (),
178
+ )
145
179
return
146
180
}
147
- r .isChildJobCompleted = phase == types .JobPhaseCompleted
181
+ if ! found {
182
+ klog .V (1 ).Infof (
183
+ "Job status.active is not set: Kind %q: Job %q / %q" ,
184
+ r .childJob .GetKind (),
185
+ r .childJob .GetNamespace (),
186
+ r .childJob .GetName (),
187
+ )
188
+ // Job's status.active is not set
189
+ //
190
+ // Nothing to do
191
+ // Wait for next reconcile
192
+ return
193
+ }
194
+
195
+ if activeCount > 0 {
196
+ r .isChildJobCompleted = true
197
+ }
148
198
}
149
199
150
200
func (r * Reconciliation ) initCommandDetails () {
@@ -172,12 +222,13 @@ func (r *Reconciliation) initCommandDetails() {
172
222
func (r * Reconciliation ) initLocking () {
173
223
if metac .KubeDetails == nil {
174
224
r .err = errors .Errorf (
175
- "Failed to init lock: Nil metac kube details: Command %s %s " ,
225
+ "Failed to init lock: Nil kube details: Command %q / %q " ,
176
226
r .command .GetNamespace (),
177
227
r .command .GetName (),
178
228
)
179
229
return
180
230
}
231
+
181
232
r .locker , r .err = lock .NewLocker (lock.LockingConfig {
182
233
// D-Operators uses metac as a library
183
234
// Metac on its part populates the kube config & api discovery
@@ -275,7 +326,7 @@ func (r *Reconciliation) createChildJob() (types.CommandStatus, error) {
275
326
return types.CommandStatus {
276
327
Phase : types .CommandPhaseJobCreated ,
277
328
Message : fmt .Sprintf (
278
- "Command Job created: %s %s : %s " ,
329
+ "Command Job created: %q %q : %q " ,
279
330
got .GetNamespace (),
280
331
got .GetName (),
281
332
got .GetUID (),
@@ -302,7 +353,6 @@ func (r *Reconciliation) isChildJobAvailable() (*unstructured.Unstructured, bool
302
353
)
303
354
}
304
355
return got , got != nil , nil
305
-
306
356
}
307
357
308
358
func (r * Reconciliation ) deleteChildJob () (types.CommandStatus , error ) {
@@ -321,7 +371,7 @@ func (r *Reconciliation) deleteChildJob() (types.CommandStatus, error) {
321
371
return types.CommandStatus {
322
372
Phase : types .CommandPhaseJobDeleted ,
323
373
Message : fmt .Sprintf (
324
- "Command Job deleted: %s %s : %s " ,
374
+ "Command Job deleted: %q / %q : %q " ,
325
375
r .childJob .GetNamespace (),
326
376
r .childJob .GetName (),
327
377
r .childJob .GetUID (),
@@ -331,7 +381,9 @@ func (r *Reconciliation) deleteChildJob() (types.CommandStatus, error) {
331
381
332
382
func (r * Reconciliation ) reconcileRunOnceCommand () (types.CommandStatus , error ) {
333
383
klog .V (1 ).Infof (
334
- "Reconcile run once command started" ,
384
+ "Reconcile started: Run once: Command %q / %q" ,
385
+ r .command .GetNamespace (),
386
+ r .command .GetName (),
335
387
)
336
388
var isDeleteChildJob = func () bool {
337
389
if ! r .isChildJobFound || ! r .isChildJobCompleted {
@@ -353,16 +405,25 @@ func (r *Reconciliation) reconcileRunOnceCommand() (types.CommandStatus, error)
353
405
}
354
406
if isCreateChildJob () {
355
407
klog .V (1 ).Infof (
356
- "Will create job" ,
408
+ "Will create command job: Command %q / %q" ,
409
+ r .command .GetNamespace (),
410
+ r .command .GetName (),
357
411
)
358
412
return r .createChildJob ()
359
413
}
360
414
if isDeleteChildJob () {
361
415
klog .V (1 ).Infof (
362
- "Will delete job" ,
416
+ "Will delete command job: Command %q / %q" ,
417
+ r .command .GetNamespace (),
418
+ r .command .GetName (),
363
419
)
364
420
return r .deleteChildJob ()
365
421
}
422
+ klog .V (1 ).Infof (
423
+ "Previous reconciliation is in-progress: Command %q / %q" ,
424
+ r .command .GetNamespace (),
425
+ r .command .GetName (),
426
+ )
366
427
return types.CommandStatus {
367
428
Phase : types .CommandPhaseInProgress ,
368
429
Message : "Previous reconciliation is in-progress" ,
@@ -371,18 +432,23 @@ func (r *Reconciliation) reconcileRunOnceCommand() (types.CommandStatus, error)
371
432
372
433
func (r * Reconciliation ) reconcileRunAlwaysCommand () (types.CommandStatus , error ) {
373
434
klog .V (1 ).Infof (
374
- "Run always: %q" ,
375
- r .childJob .GetName (),
435
+ "Reconcile started: Run always: Command %q / %q" ,
436
+ r .command .GetNamespace (),
437
+ r .command .GetName (),
376
438
)
377
439
if ! r .isChildJobFound {
378
440
klog .V (1 ).Infof (
379
- "Will create job" ,
441
+ "Will create command job: Command %q / %q" ,
442
+ r .command .GetNamespace (),
443
+ r .command .GetName (),
380
444
)
381
445
return r .createChildJob ()
382
446
}
383
447
if r .isStatusSet && r .isChildJobCompleted {
384
448
klog .V (1 ).Infof (
385
- "Will delete job" ,
449
+ "Will delete command job: Command %q / %q" ,
450
+ r .command .GetNamespace (),
451
+ r .command .GetName (),
386
452
)
387
453
return r .deleteChildJob ()
388
454
}
@@ -402,7 +468,9 @@ func (r *Reconciliation) deleteChildJobOnDisabledCommand() (types.CommandStatus,
402
468
return output , nil
403
469
}
404
470
klog .V (1 ).Infof (
405
- "Will delete job" ,
471
+ "Will delete command job: Command is disabled: Command %q / %q" ,
472
+ r .command .GetNamespace (),
473
+ r .command .GetName (),
406
474
)
407
475
// Delete without any checks
408
476
_ , err := r .deleteChildJob ()
@@ -415,19 +483,25 @@ func (r *Reconciliation) deleteChildJobOnDisabledCommand() (types.CommandStatus,
415
483
// Reconcile either creates or deletes a Kubernetes job or does nothing
416
484
// as part of reconciling a Command resource.
417
485
func (r * Reconciliation ) Reconcile () (status types.CommandStatus , err error ) {
418
- // klog.V(1).Infof(
419
- // "Reconcilation struct: %#v",
420
- // r,
421
- // )
422
486
if r .isRunNever {
423
487
return r .deleteChildJobOnDisabledCommand ()
424
488
}
425
489
isLocked , err := r .locker .IsLocked ()
426
490
if err != nil {
427
- klog .Errorf ("Failed to check lock status: %s" , err .Error ())
491
+ klog .Errorf (
492
+ "Failed to check lock status for command: %q / %q: %s" ,
493
+ r .command .GetNamespace (),
494
+ r .command .GetName (),
495
+ err .Error (),
496
+ )
428
497
return types.CommandStatus {}, err
429
498
}
430
499
if isLocked {
500
+ klog .V (3 ).Infof (
501
+ "Will skip command reconciliation: It is locked: Command %q / %q" ,
502
+ r .command .GetNamespace (),
503
+ r .command .GetName (),
504
+ )
431
505
return types.CommandStatus {
432
506
Phase : types .CommandPhaseLocked ,
433
507
}, nil
@@ -441,9 +515,6 @@ func (r *Reconciliation) Reconcile() (status types.CommandStatus, err error) {
441
515
}
442
516
return types.CommandStatus {}, err
443
517
}
444
- klog .V (1 ).Infof (
445
- "Reconcile started" ,
446
- )
447
518
// make use of defer to UNLOCK
448
519
defer func () {
449
520
// FORCE UNLOCK in case of the following:
@@ -456,7 +527,7 @@ func (r *Reconciliation) Reconcile() (status types.CommandStatus, err error) {
456
527
if unlockerr != nil {
457
528
// swallow unlock error by logging
458
529
klog .Errorf (
459
- "Forced unlock failed: Command %q %q: Status %q %q: %s" ,
530
+ "Forced unlock failed: Command %q / %q: Status %q %q: %s" ,
460
531
r .command .Namespace ,
461
532
r .command .Name ,
462
533
r .commandStatus .Phase ,
@@ -467,7 +538,7 @@ func (r *Reconciliation) Reconcile() (status types.CommandStatus, err error) {
467
538
return
468
539
}
469
540
klog .V (3 ).Infof (
470
- "Forced unlock was successful: Command %q %q: Status %q %q" ,
541
+ "Forced unlock was successful: Command %q / %q: Status %q %q" ,
471
542
r .command .Namespace ,
472
543
r .command .Name ,
473
544
r .commandStatus .Phase ,
@@ -491,7 +562,7 @@ func (r *Reconciliation) Reconcile() (status types.CommandStatus, err error) {
491
562
if unlockerr != nil {
492
563
// swallow the unlock error by logging
493
564
klog .Errorf (
494
- "Graceful unlock failed: Command %q %q: Status %q %q: %s" ,
565
+ "Graceful unlock failed: Command %q / %q: Status %q %q: %s" ,
495
566
r .command .Namespace ,
496
567
r .command .Name ,
497
568
r .commandStatus .Phase ,
@@ -502,7 +573,7 @@ func (r *Reconciliation) Reconcile() (status types.CommandStatus, err error) {
502
573
return
503
574
}
504
575
klog .V (3 ).Infof (
505
- "Unlocked gracefully: Command %q %q: Status %q %q: %s" ,
576
+ "Unlocked gracefully: Command %q / %q: Status %q %q: %s" ,
506
577
r .command .Namespace ,
507
578
r .command .Name ,
508
579
r .commandStatus .Phase ,
0 commit comments