Skip to content

Commit 0d202dc

Browse files
committed
Add latest discriminator in status
Signed-off-by: GregoireW <[email protected]>
1 parent 859821b commit 0d202dc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/v1beta2/imagepolicy_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ type ImagePolicyStatus struct {
113113
// the image repository, when filtered and ordered according to
114114
// the policy.
115115
LatestImage string `json:"latestImage,omitempty"`
116+
// Distribution of tags scanned by the image repository
116117
// +optional
117118
Distribution map[string]ImageAndAttributes `json:"distribution,omitempty"`
119+
// Discriminator of the latest image.
120+
// +optional
121+
LatestDiscriminator string `json:"latestDiscriminator,omitempty"`
122+
// len of the distribution map. Statistics only.
118123
NbDistribution int `json:"nbDistribution,omitempty"`
119124
// +optional
120125
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

config/crd/bases/image.toolkit.fluxcd.io_imagepolicies.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,16 @@ spec:
584584
- image
585585
- tag
586586
type: object
587+
description: Distribution of tags scanned by the image repository
587588
type: object
589+
latestDiscriminator:
590+
description: Discriminator of the latest image.
591+
type: string
588592
latestImage:
589593
description: LatestImage gives the first in the list of images scanned by the image repository, when filtered and ordered according to the policy.
590594
type: string
591595
nbDistribution:
596+
description: len of the distribution map. Statistics only.
592597
type: integer
593598
observedGeneration:
594599
format: int64

controllers/imagepolicy_controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (r *ImagePolicyReconciler) nonDiscriminated(ctx context.Context, req ctrl.R
176176

177177
pol.Status.Distribution = nil
178178
pol.Status.NbDistribution = 0
179+
pol.Status.LatestDiscriminator = ""
179180

180181
if policer != nil {
181182
var tags []string
@@ -249,6 +250,7 @@ func (r *ImagePolicyReconciler) nonDiscriminated(ctx context.Context, req ctrl.R
249250
func (r *ImagePolicyReconciler) discriminated(ctx context.Context, req ctrl.Request, policer policy.Policer, repo imagev1.ImageRepository, pol imagev1.ImagePolicy) (ctrl.Result, error) {
250251
distribution := map[string]imagev1.ImageAndAttributes{}
251252
latest := ""
253+
latestDiscriminator := ""
252254
var err error
253255

254256
listAttributes := []string{ pol.Spec.FilterTags.Discriminator, pol.Spec.FilterTags.Extract }
@@ -283,8 +285,8 @@ func (r *ImagePolicyReconciler) discriminated(ctx context.Context, req ctrl.Requ
283285
newer, err := policer.Latest(extractedList)
284286

285287
if err == nil {
286-
img := distribution[distribByExtracted[newer]]
287-
latest = img.Tag
288+
latestDiscriminator = distribByExtracted[newer]
289+
latest = distribution[latestDiscriminator].Tag
288290
}
289291
}
290292
}
@@ -330,6 +332,7 @@ func (r *ImagePolicyReconciler) discriminated(ctx context.Context, req ctrl.Requ
330332
pol.Status.Distribution = distribution
331333
pol.Status.NbDistribution = len(distribution)
332334
pol.Status.LatestImage = repo.Spec.Image + ":" + latest
335+
pol.Status.LatestDiscriminator = latestDiscriminator
333336
imagev1.SetImagePolicyReadiness(
334337
&pol,
335338
metav1.ConditionTrue,

0 commit comments

Comments
 (0)