Skip to content

Commit 1d48f27

Browse files
authored
Merge pull request #803 from cappyzawa/feat/remove-imagepolicy-status-latestimage
Remove deprecated ImagePolicy status fields
2 parents f8af344 + 8352e23 commit 1d48f27

File tree

7 files changed

+4
-227
lines changed

7 files changed

+4
-227
lines changed

api/v1beta2/imagepolicy_types.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,6 @@ func (in *ImageRef) String() string {
166166

167167
// ImagePolicyStatus defines the observed state of ImagePolicy
168168
type ImagePolicyStatus struct {
169-
// LatestImage gives the first in the list of images scanned by
170-
// the image repository, when filtered and ordered according to
171-
// the policy.
172-
//
173-
// Deprecated: Replaced by the composite "latestRef" field.
174-
LatestImage string `json:"latestImage,omitempty"`
175-
// ObservedPreviousImage is the observed previous LatestImage. It is used
176-
// to keep track of the previous and current images.
177-
//
178-
// Deprecated: Replaced by the composite "observedPreviousRef" field.
179-
// +optional
180-
ObservedPreviousImage string `json:"observedPreviousImage,omitempty"`
181169
// LatestRef gives the first in the list of images scanned by
182170
// the image repository, when filtered and ordered according
183171
// to the policy.

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,6 @@ spec:
435435
- type
436436
type: object
437437
type: array
438-
latestImage:
439-
description: |-
440-
LatestImage gives the first in the list of images scanned by
441-
the image repository, when filtered and ordered according to
442-
the policy.
443-
444-
Deprecated: Replaced by the composite "latestRef" field.
445-
type: string
446438
latestRef:
447439
description: |-
448440
LatestRef gives the first in the list of images scanned by
@@ -465,13 +457,6 @@ spec:
465457
observedGeneration:
466458
format: int64
467459
type: integer
468-
observedPreviousImage:
469-
description: |-
470-
ObservedPreviousImage is the observed previous LatestImage. It is used
471-
to keep track of the previous and current images.
472-
473-
Deprecated: Replaced by the composite "observedPreviousRef" field.
474-
type: string
475460
observedPreviousRef:
476461
description: |-
477462
ObservedPreviousRef is the observed previous LatestRef. It is used

docs/api/v1beta2/image-reflector.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -372,34 +372,6 @@ reflection policy is set to &ldquo;Always&rdquo;.</p>
372372
<tbody>
373373
<tr>
374374
<td>
375-
<code>latestImage</code><br>
376-
<em>
377-
string
378-
</em>
379-
</td>
380-
<td>
381-
<p>LatestImage gives the first in the list of images scanned by
382-
the image repository, when filtered and ordered according to
383-
the policy.</p>
384-
<p>Deprecated: Replaced by the composite &ldquo;latestRef&rdquo; field.</p>
385-
</td>
386-
</tr>
387-
<tr>
388-
<td>
389-
<code>observedPreviousImage</code><br>
390-
<em>
391-
string
392-
</em>
393-
</td>
394-
<td>
395-
<em>(Optional)</em>
396-
<p>ObservedPreviousImage is the observed previous LatestImage. It is used
397-
to keep track of the previous and current images.</p>
398-
<p>Deprecated: Replaced by the composite &ldquo;observedPreviousRef&rdquo; field.</p>
399-
</td>
400-
</tr>
401-
<tr>
402-
<td>
403375
<code>latestRef</code><br>
404376
<em>
405377
<a href="#image.toolkit.fluxcd.io/v1beta2.ImageRef">

docs/spec/v1beta2/imagepolicies.md

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ kubectl apply -f imagepolicy.yaml
5252
2. Run `kubectl get imagepolicy` to see the ImagePolicy:
5353

5454
```console
55-
NAME LATESTIMAGE
56-
podinfo ghcr.io/stefanprodan/podinfo:5.1.4
55+
NAME IMAGE TAG READY STATUS AGE
56+
podinfo ghcr.io/stefanprodan/podinfo 5.1.4 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to 5.1.4 5m
5757
```
5858

59-
3. Run `kubectl describe imagepolicy podinfo` to see the [Latest Image](#latest-image)
60-
and [Conditions](#conditions) in the ImagePolicy's Status:
59+
3. Run `kubectl describe imagepolicy podinfo` to see the [Latest Ref](#latest-ref)
60+
and [Conditions](#conditions) in the ImagePolicy's Status:
6161

6262
```console
6363
Status:
@@ -68,7 +68,6 @@ Status:
6868
Reason: Succeeded
6969
Status: True
7070
Type: Ready
71-
Latest Image: ghcr.io/stefanprodan/podinfo:5.1.4
7271
Latest Ref:
7372
Digest: sha256:2d9a00b3981628a533ff43352193b1838b0a4bf6b0033444286f563205e51a2c
7473
Image: ghcr.io/stefanprodan/podinfo
@@ -356,49 +355,6 @@ specific ImagePolicy, e.g.
356355

357356
## ImagePolicy Status
358357

359-
### Latest Image
360-
361-
**Warning:** This field is deprecated in favor of `.status.latestRef.image` and will be
362-
removed in a future release.
363-
364-
The ImagePolicy reports the latest select image from the ImageRepository tags in
365-
`.status.latestImage` for the resource.
366-
367-
Example:
368-
369-
```yaml
370-
---
371-
apiVersion: image.toolkit.fluxcd.io/v1beta2
372-
kind: ImagePolicy
373-
metadata:
374-
name: <policy-name>
375-
status:
376-
latestImage: ghcr.io/stefanprodan/podinfo:5.1.4
377-
```
378-
379-
### Observed Previous Image
380-
381-
**Warning:** This field is deprecated in favor of `.status.observedPreviousRef.image`
382-
and will be removed in a future release.
383-
384-
The ImagePolicy reports the previously observed latest image in
385-
`.status.observedPreviousImage` for the resource. This is used by the
386-
ImagePolicy to determine an upgrade path of an ImagePolicy update. This field
387-
is reset when the ImagePolicy fails due to some reason to be able to distinguish
388-
between a failure recovery and a genuine latest image upgrade.
389-
390-
Example:
391-
392-
```yaml
393-
apiVersion: image.toolkit.fluxcd.io/v1beta2
394-
kind: ImagePolicy
395-
metadata:
396-
name: <policy-name>
397-
status:
398-
latestImage: ghcr.io/stefanprodan/podinfo:6.2.1
399-
observedPreviousImage: ghcr.io/stefanprodan/podinfo:5.1.4
400-
```
401-
402358
### Latest Ref
403359

404360
The ImagePolicy reports the latest selected image from the ImageRepository tags in

internal/controller/imagepolicy_controller.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"strings"
2423
"time"
2524

2625
"github.com/google/go-containerregistry/pkg/name"
@@ -243,28 +242,9 @@ func composeImagePolicyReadyMessage(obj *imagev1.ImagePolicy) string {
243242
return readyMsg
244243
}
245244

246-
// migrateImageToRef migrates the old status.LatestImage and
247-
// status.ObservedPreviousImage fields to the new status.LatestRef and
248-
// status.ObservedPreviousRef fields.
249-
func migrateImageToRef(imgWithTag string, ref **imagev1.ImageRef) {
250-
if *ref != nil || imgWithTag == "" {
251-
return
252-
}
253-
254-
idx := strings.LastIndex(imgWithTag, ":")
255-
*ref = &imagev1.ImageRef{
256-
Name: imgWithTag[:idx],
257-
Tag: imgWithTag[idx+1:],
258-
}
259-
}
260-
261245
func (r *ImagePolicyReconciler) reconcile(ctx context.Context, sp *patch.SerialPatcher, obj *imagev1.ImagePolicy) (result ctrl.Result, retErr error) {
262246
oldObj := obj.DeepCopy()
263247

264-
// Migrate old status fields to new ones.
265-
migrateImageToRef(obj.Status.LatestImage, &obj.Status.LatestRef)
266-
migrateImageToRef(obj.Status.ObservedPreviousImage, &obj.Status.ObservedPreviousRef)
267-
268248
// If there's no error and no requeue is requested, it's a success.
269249
isSuccess := func(res ctrl.Result, err error) bool {
270250
if err != nil || res.Requeue {
@@ -382,12 +362,6 @@ func (r *ImagePolicyReconciler) reconcile(ctx context.Context, sp *patch.SerialP
382362
// Compute ready message.
383363
readyMsg = composeImagePolicyReadyMessage(obj)
384364

385-
// Update deprecated status fields with the latest tag.
386-
obj.Status.LatestImage = repo.Spec.Image + ":" + latest
387-
if prev := obj.Status.ObservedPreviousRef; prev != nil {
388-
obj.Status.ObservedPreviousImage = prev.Name + ":" + prev.Tag
389-
}
390-
391365
// Let result finalizer compute the Ready condition.
392366
conditions.Delete(obj, meta.ReadyCondition)
393367

internal/controller/imagepolicy_controller_test.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -635,102 +635,6 @@ func TestImagePolicyReconciler_deleteBeforeFinalizer(t *testing.T) {
635635
g.Expect(err).NotTo(HaveOccurred())
636636
}
637637

638-
func TestImagePolicyReconciler_migrateImageToRef(t *testing.T) {
639-
g := NewWithT(t)
640-
641-
s := runtime.NewScheme()
642-
utilruntime.Must(imagev1.AddToScheme(s))
643-
utilruntime.Must(corev1.AddToScheme(s))
644-
645-
ns := &corev1.Namespace{
646-
ObjectMeta: metav1.ObjectMeta{
647-
Name: "imagepolicy-" + randStringRunes(5),
648-
},
649-
}
650-
651-
imageRepo := &imagev1.ImageRepository{
652-
ObjectMeta: metav1.ObjectMeta{
653-
Namespace: ns.Name,
654-
Name: "status-migration-test",
655-
},
656-
Spec: imagev1.ImageRepositorySpec{
657-
Image: "ghcr.io:443/stefanprodan/podinfo",
658-
},
659-
Status: imagev1.ImageRepositoryStatus{
660-
LastScanResult: &imagev1.ScanResult{
661-
TagCount: 3,
662-
LatestTags: []string{"1.0.0", "1.1.0", "2.0.0"},
663-
},
664-
Conditions: []metav1.Condition{
665-
{
666-
Type: meta.ReadyCondition,
667-
Status: metav1.ConditionTrue,
668-
},
669-
},
670-
},
671-
}
672-
imagePol := &imagev1.ImagePolicy{
673-
ObjectMeta: metav1.ObjectMeta{
674-
Namespace: ns.Name,
675-
Name: "status-migration-test",
676-
Generation: 1,
677-
Finalizers: []string{imagev1.ImageFinalizer},
678-
},
679-
Spec: imagev1.ImagePolicySpec{
680-
ImageRepositoryRef: meta.NamespacedObjectReference{
681-
Name: imageRepo.Name,
682-
},
683-
Policy: imagev1.ImagePolicyChoice{
684-
SemVer: &imagev1.SemVerPolicy{
685-
Range: "1.0",
686-
},
687-
},
688-
},
689-
Status: imagev1.ImagePolicyStatus{
690-
LatestImage: "ghcr.io:443/stefanprodan/podinfo:1.0.0",
691-
ObservedPreviousImage: "ghcr.io:443/stefanprodan/podinfo:0.9.0",
692-
},
693-
}
694-
695-
c := fake.NewClientBuilder().
696-
WithScheme(s).
697-
WithObjects(ns, imageRepo, imagePol).
698-
WithStatusSubresource(imagePol).
699-
Build()
700-
701-
r := &ImagePolicyReconciler{
702-
EventRecorder: record.NewFakeRecorder(32),
703-
Client: c,
704-
Database: &mockDatabase{TagData: imageRepo.Status.LastScanResult.LatestTags},
705-
AuthOptionsGetter: &registry.AuthOptionsGetter{Client: c},
706-
}
707-
res, err := r.Reconcile(context.Background(), ctrl.Request{
708-
NamespacedName: types.NamespacedName{
709-
Namespace: ns.Name,
710-
Name: imagePol.Name,
711-
},
712-
})
713-
714-
g.Expect(err).NotTo(HaveOccurred(), "reconciliation failed")
715-
g.Expect(res).To(Equal(ctrl.Result{}))
716-
717-
g.Expect(c.Get(context.Background(), client.ObjectKeyFromObject(imagePol), imagePol)).
718-
To(Succeed(), "failed getting image policy")
719-
720-
g.Expect(imagePol.Status.LatestImage).To(Equal("ghcr.io:443/stefanprodan/podinfo:1.0.0"), "unexpected latest image")
721-
g.Expect(imagePol.Status.LatestRef).To(Equal(&imagev1.ImageRef{
722-
Name: "ghcr.io:443/stefanprodan/podinfo",
723-
Tag: "1.0.0",
724-
Digest: "",
725-
}), "unexpected latest ref")
726-
g.Expect(imagePol.Status.ObservedPreviousImage).To(Equal("ghcr.io:443/stefanprodan/podinfo:0.9.0"), "unexpected observed previous image")
727-
g.Expect(imagePol.Status.ObservedPreviousRef).To(Equal(&imagev1.ImageRef{
728-
Name: "ghcr.io:443/stefanprodan/podinfo",
729-
Tag: "0.9.0",
730-
Digest: "",
731-
}), "unexpected observed previous ref")
732-
}
733-
734638
func TestImagePolicyReconciler_getImageRepository(t *testing.T) {
735639
testImageRepoName := "test-repo"
736640
testNamespace1 := "test-ns1" // Default namespace of ImagePolicy.

internal/controller/policy_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ func TestImagePolicyReconciler_calculateImageFromRepoTags(t *testing.T) {
231231
pol.Status.LatestRef != nil
232232
}, timeout, interval).Should(BeTrue())
233233
g.Expect(pol.Status.LatestRef.String()).To(Equal(imgRepo + tt.wantImageTag))
234-
g.Expect(pol.Status.ObservedPreviousImage).To(Equal(""),
235-
"single reconciliation should leave status.observedPreviousImage empty")
236234
g.Expect(pol.Status.ObservedPreviousRef).To(BeNil(),
237235
"single reconciliation should leave status.observedPreviousRef nil")
238236
} else {

0 commit comments

Comments
 (0)