Skip to content

Commit ad10474

Browse files
committed
Remove deprecated ImagePolicy status fields
Removes the deprecated .status.latestImage and .status.observedPreviousImage fields from the v1beta2 ImagePolicy API in preparation for GA. These fields were deprecated in favor of the structured .status.latestRef and .status.observedPreviousRef fields which provide better separation of image name, tag, and digest information. Signed-off-by: cappyzawa <[email protected]>
1 parent f8af344 commit ad10474

File tree

6 files changed

+0
-179
lines changed

6 files changed

+0
-179
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">

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)