Skip to content

Commit 82b9631

Browse files
committed
feat: update ImagePrefetch status conditions to include NodeImageSetsCreated and NoImagePullFailed
Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp>
1 parent 9c23699 commit 82b9631

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

api/v1/imageprefetch_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ type ImagePrefetchStatus struct {
6666
}
6767

6868
const (
69-
ConditionReady = "Ready"
70-
ConditionProgressing = "Progressing"
71-
ConditionImagePullFailed = "ImagePullFailed"
69+
ConditionReady = "Ready"
70+
ConditionNodeImageSetsCreated = "NodeImageSetsCreated"
71+
ConditionNoImagePullFailed = "NoImagePullFailed"
7272
)
7373

7474
// +genclient

internal/controller/imageprefetch_controller.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,26 @@ func (r *ImagePrefetchReconciler) updateStatus(ctx context.Context, imgPrefetch
427427
imgPrefetchSSA.Status.WithImagePullingNodes(status.pullingNodes)
428428
imgPrefetchSSA.Status.WithImagePullFailedNodes(status.pullFailedNodes)
429429

430+
if len(nodeImageSets.Items) == len(selectedNodes) {
431+
imgPrefetchSSA.Status.WithConditions(
432+
metav1apply.Condition().
433+
WithType(ofenv1.ConditionNodeImageSetsCreated).
434+
WithStatus(metav1.ConditionTrue).
435+
WithReason("NodeImageSetsCreated").
436+
WithMessage("All NodeImageSets have been created").
437+
WithLastTransitionTime(metav1.Now()),
438+
)
439+
} else {
440+
imgPrefetchSSA.Status.WithConditions(
441+
metav1apply.Condition().
442+
WithType(ofenv1.ConditionNodeImageSetsCreated).
443+
WithStatus(metav1.ConditionFalse).
444+
WithReason("NodeImageSetsCreating").
445+
WithMessage("Waiting for all NodeImageSets to be created").
446+
WithLastTransitionTime(metav1.Now()),
447+
)
448+
}
449+
430450
if status.availableNodes == status.desiredNodes {
431451
logger.Info("ImagePrefetch is ready", "name", imgPrefetch.Name)
432452
imgPrefetchSSA.Status.WithConditions(
@@ -436,12 +456,6 @@ func (r *ImagePrefetchReconciler) updateStatus(ctx context.Context, imgPrefetch
436456
WithReason("ImagePrefetchReady").
437457
WithMessage("All nodes have the desired image").
438458
WithLastTransitionTime(metav1.Now()),
439-
metav1apply.Condition().
440-
WithType(ofenv1.ConditionProgressing).
441-
WithStatus(metav1.ConditionFalse).
442-
WithReason("ImagePrefetchFinished").
443-
WithMessage("All nodes have the desired image").
444-
WithLastTransitionTime(metav1.Now()),
445459
)
446460
result = ctrl.Result{}
447461
} else {
@@ -452,29 +466,23 @@ func (r *ImagePrefetchReconciler) updateStatus(ctx context.Context, imgPrefetch
452466
WithReason("ImagePrefetchProgressing").
453467
WithMessage("Waiting for all nodes to pull the image").
454468
WithLastTransitionTime(metav1.Now()),
455-
metav1apply.Condition().
456-
WithType(ofenv1.ConditionProgressing).
457-
WithStatus(metav1.ConditionTrue).
458-
WithReason("ImagePrefetchProgressing").
459-
WithMessage("Waiting for all nodes to pull the image").
460-
WithLastTransitionTime(metav1.Now()),
461469
)
462470
}
463471

464472
if status.pullFailedNodes > 0 {
465473
imgPrefetchSSA.Status.WithConditions(
466474
metav1apply.Condition().
467-
WithType(ofenv1.ConditionImagePullFailed).
468-
WithStatus(metav1.ConditionTrue).
475+
WithType(ofenv1.ConditionNoImagePullFailed).
476+
WithStatus(metav1.ConditionFalse).
469477
WithReason("ImagePrefetchFailed").
470478
WithMessage("Some nodes failed to pull the image").
471479
WithLastTransitionTime(metav1.Now()),
472480
)
473481
} else {
474482
imgPrefetchSSA.Status.WithConditions(
475483
metav1apply.Condition().
476-
WithType(ofenv1.ConditionImagePullFailed).
477-
WithStatus(metav1.ConditionFalse).
484+
WithType(ofenv1.ConditionNoImagePullFailed).
485+
WithStatus(metav1.ConditionTrue).
478486
WithReason("NoImagePullFailed").
479487
WithMessage("No nodes have failed to pull the image").
480488
WithLastTransitionTime(metav1.Now()),

internal/controller/imageprefetch_controller_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,12 @@ var _ = Describe("ImagePrefetch Controller", Serial, func() {
441441
conditionImagePrefetchReady := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionReady)
442442
g.Expect(conditionImagePrefetchReady).NotTo(BeNil())
443443
g.Expect(conditionImagePrefetchReady.Status).To(Equal(metav1.ConditionFalse))
444-
conditionImagePrefetchProcessing := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionProgressing)
445-
g.Expect(conditionImagePrefetchProcessing).NotTo(BeNil())
446-
g.Expect(conditionImagePrefetchProcessing.Status).To(Equal(metav1.ConditionTrue))
447-
conditionImagePrefetchFailed := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionImagePullFailed)
448-
g.Expect(conditionImagePrefetchFailed).NotTo(BeNil())
449-
g.Expect(conditionImagePrefetchFailed.Status).To(Equal(metav1.ConditionFalse))
444+
ConditionNodeImageSetsCreated := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionNodeImageSetsCreated)
445+
g.Expect(ConditionNodeImageSetsCreated).NotTo(BeNil())
446+
g.Expect(ConditionNodeImageSetsCreated.Status).To(Equal(metav1.ConditionTrue))
447+
conditionNoImagePrefetchFailed := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionNoImagePullFailed)
448+
g.Expect(conditionNoImagePrefetchFailed).NotTo(BeNil())
449+
g.Expect(conditionNoImagePrefetchFailed.Status).To(Equal(metav1.ConditionTrue))
450450
}).Should(Succeed())
451451

452452
By("updating nodeImageSet's status to image pull failed")
@@ -481,12 +481,12 @@ var _ = Describe("ImagePrefetch Controller", Serial, func() {
481481
conditionImagePrefetchReady := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionReady)
482482
g.Expect(conditionImagePrefetchReady).NotTo(BeNil())
483483
g.Expect(conditionImagePrefetchReady.Status).To(Equal(metav1.ConditionFalse))
484-
conditionImagePrefetchProcessing := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionProgressing)
485-
g.Expect(conditionImagePrefetchProcessing).NotTo(BeNil())
486-
g.Expect(conditionImagePrefetchProcessing.Status).To(Equal(metav1.ConditionTrue))
487-
conditionImagePrefetchFailed := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionImagePullFailed)
488-
g.Expect(conditionImagePrefetchFailed).NotTo(BeNil())
489-
g.Expect(conditionImagePrefetchFailed.Status).To(Equal(metav1.ConditionTrue))
484+
conditionNodeImageSetsCreated := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionNodeImageSetsCreated)
485+
g.Expect(conditionNodeImageSetsCreated).NotTo(BeNil())
486+
g.Expect(conditionNodeImageSetsCreated.Status).To(Equal(metav1.ConditionTrue))
487+
conditionNoImagePrefetchFailed := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionNoImagePullFailed)
488+
g.Expect(conditionNoImagePrefetchFailed).NotTo(BeNil())
489+
g.Expect(conditionNoImagePrefetchFailed.Status).To(Equal(metav1.ConditionFalse))
490490
}).Should(Succeed())
491491

492492
By("updating nodeImageSet's status to image available")
@@ -525,12 +525,12 @@ var _ = Describe("ImagePrefetch Controller", Serial, func() {
525525
conditionImagePrefetchReady := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionReady)
526526
g.Expect(conditionImagePrefetchReady).NotTo(BeNil())
527527
g.Expect(conditionImagePrefetchReady.Status).To(Equal(metav1.ConditionTrue))
528-
conditionImagePrefetchProcessing := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionProgressing)
529-
g.Expect(conditionImagePrefetchProcessing).NotTo(BeNil())
530-
g.Expect(conditionImagePrefetchProcessing.Status).To(Equal(metav1.ConditionFalse))
531-
conditionImagePrefetchFailed := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionImagePullFailed)
532-
g.Expect(conditionImagePrefetchFailed).NotTo(BeNil())
533-
g.Expect(conditionImagePrefetchFailed.Status).To(Equal(metav1.ConditionFalse))
528+
conditionNodeImageSetsCreated := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionNodeImageSetsCreated)
529+
g.Expect(conditionNodeImageSetsCreated).NotTo(BeNil())
530+
g.Expect(conditionNodeImageSetsCreated.Status).To(Equal(metav1.ConditionTrue))
531+
conditionNoImagePrefetchFailed := meta.FindStatusCondition(imagePrefetch.Status.Conditions, ofenv1.ConditionNoImagePullFailed)
532+
g.Expect(conditionNoImagePrefetchFailed).NotTo(BeNil())
533+
g.Expect(conditionNoImagePrefetchFailed.Status).To(Equal(metav1.ConditionTrue))
534534
}).Should(Succeed())
535535

536536
By("cleaning up the ImagePrefetch resource")

0 commit comments

Comments
 (0)