Skip to content

Commit bbb5dbf

Browse files
authored
Merge pull request #29 from cybozu-go/add-imageprefetch-column
Refactor ImagePrefetch status conditions
2 parents 5de8217 + f8bc937 commit bbb5dbf

File tree

5 files changed

+74
-39
lines changed

5 files changed

+74
-39
lines changed

api/v1/imageprefetch_types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ 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
7575
// +kubebuilder:object:root=true
7676
// +kubebuilder:subresource:status
77+
// +kubebuilder:printcolumn:name="DesiredNodes",type="integer",JSONPath=".status.desiredNodes",description="The number of nodes that should have the images pre-downloaded"
78+
// +kubebuilder:printcolumn:name="ImagePulledNodes",type="integer",JSONPath=".status.imagePulledNodes",description="The number of nodes that have successfully pre-downloaded the images"
79+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
7780

7881
// ImagePrefetch is the Schema for the imageprefetches API
7982
type ImagePrefetch struct {

charts/ofen/templates/generated/crds/crds.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ spec:
2020
singular: imageprefetch
2121
scope: Namespaced
2222
versions:
23-
- name: v1
23+
- additionalPrinterColumns:
24+
- description: The number of nodes that should have the images pre-downloaded
25+
jsonPath: .status.desiredNodes
26+
name: DesiredNodes
27+
type: integer
28+
- description: The number of nodes that have successfully pre-downloaded the images
29+
jsonPath: .status.imagePulledNodes
30+
name: ImagePulledNodes
31+
type: integer
32+
- jsonPath: .metadata.creationTimestamp
33+
name: Age
34+
type: date
35+
name: v1
2436
schema:
2537
openAPIV3Schema:
2638
description: ImagePrefetch is the Schema for the imageprefetches API

config/crd/bases/ofen.cybozu.io_imageprefetches.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ spec:
1414
singular: imageprefetch
1515
scope: Namespaced
1616
versions:
17-
- name: v1
17+
- additionalPrinterColumns:
18+
- description: The number of nodes that should have the images pre-downloaded
19+
jsonPath: .status.desiredNodes
20+
name: DesiredNodes
21+
type: integer
22+
- description: The number of nodes that have successfully pre-downloaded the images
23+
jsonPath: .status.imagePulledNodes
24+
name: ImagePulledNodes
25+
type: integer
26+
- jsonPath: .metadata.creationTimestamp
27+
name: Age
28+
type: date
29+
name: v1
1830
schema:
1931
openAPIV3Schema:
2032
description: ImagePrefetch is the Schema for the imageprefetches API

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)