diff --git a/api/v1/fluxinstance_types.go b/api/v1/fluxinstance_types.go index 1471281..e54e0c2 100644 --- a/api/v1/fluxinstance_types.go +++ b/api/v1/fluxinstance_types.go @@ -279,6 +279,11 @@ type FluxInstanceStatus struct { // +optional LastAppliedRevision string `json:"lastAppliedRevision,omitempty"` + // LastArtifactRevision is the digest of the last pulled + // distribution artifact. + // +optional + LastArtifactRevision string `json:"lastArtifactRevision,omitempty"` + // Components contains the container images used by the components. // +optional Components []ComponentImage `json:"components,omitempty"` diff --git a/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml b/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml index 41bc3aa..929d0c8 100644 --- a/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml +++ b/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml @@ -441,6 +441,11 @@ spec: LastAppliedRevision is the version and digest of the distribution config that was last reconcile. type: string + lastArtifactRevision: + description: |- + LastArtifactRevision is the digest of the last pulled + distribution artifact. + type: string lastAttemptedRevision: description: |- LastAttemptedRevision is the version and digest of the diff --git a/internal/controller/fluxinstance_controller.go b/internal/controller/fluxinstance_controller.go index afe3e24..fc11904 100644 --- a/internal/controller/fluxinstance_controller.go +++ b/internal/controller/fluxinstance_controller.go @@ -146,7 +146,7 @@ func (r *FluxInstanceReconciler) reconcile(ctx context.Context, }() // Fetch the distribution manifests. - manifestsDir, err := r.fetch(ctx, obj, tmpDir) + manifestsDir, artifactDigest, err := r.fetch(ctx, obj, tmpDir) if err != nil { msg := fmt.Sprintf("fetch failed: %s", err.Error()) conditions.MarkFalse(obj, @@ -202,6 +202,7 @@ func (r *FluxInstanceReconciler) reconcile(ctx context.Context, // Mark the object as ready. obj.Status.LastAppliedRevision = obj.Status.LastAttemptedRevision + obj.Status.LastArtifactRevision = artifactDigest msg = fmt.Sprintf("Reconciliation finished in %s", fmtDuration(reconcileStart)) conditions.MarkTrue(obj, meta.ReadyCondition, @@ -222,7 +223,7 @@ func (r *FluxInstanceReconciler) reconcile(ctx context.Context, // If the distribution artifact URL is not provided, // it falls back to the manifests stored in the container storage. func (r *FluxInstanceReconciler) fetch(ctx context.Context, - obj *fluxcdv1.FluxInstance, tmpDir string) (string, error) { + obj *fluxcdv1.FluxInstance, tmpDir string) (string, string, error) { log := ctrl.LoggerFrom(ctx) artifactURL := obj.Spec.Distribution.Artifact @@ -233,14 +234,14 @@ func (r *FluxInstanceReconciler) fetch(ctx context.Context, artifactDigest, err := builder.PullArtifact(ctxPull, artifactURL, tmpDir) if err != nil { - return "", err + return "", "", err } log.Info("fetched latest manifests", "url", artifactURL, "digest", artifactDigest) - return tmpDir, nil + return tmpDir, artifactDigest, nil } // Fall back to the manifests stored in container storage. - return r.StoragePath, nil + return r.StoragePath, "", nil } // build reads the distribution manifests from the local storage, diff --git a/internal/controller/fluxinstance_controller_test.go b/internal/controller/fluxinstance_controller_test.go index e26fbd7..d029434 100644 --- a/internal/controller/fluxinstance_controller_test.go +++ b/internal/controller/fluxinstance_controller_test.go @@ -6,6 +6,7 @@ package controller import ( "context" "fmt" + "strings" "testing" "time" @@ -77,6 +78,11 @@ func TestFluxInstanceReconciler_LifeCycle(t *testing.T) { checkInstanceReadiness(g, result) g.Expect(conditions.GetReason(result, meta.ReadyCondition)).To(BeIdenticalTo(meta.ReconciliationSucceededReason)) + // Check artifact digest. + lastArtifactRevision := result.Status.LastArtifactRevision + g.Expect(lastArtifactRevision).To(HavePrefix("sha256:")) + g.Expect(strings.TrimPrefix(lastArtifactRevision, "sha256:")).To(HaveLen(64)) + // Check if the inventory was updated. g.Expect(result.Status.Inventory.Entries).To(ContainElements( fluxcdv1.ResourceRef{ diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index 831938a..2516cc1 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -16,7 +16,6 @@ import ( "github.com/fluxcd/pkg/runtime/conditions" kcheck "github.com/fluxcd/pkg/runtime/conditions/check" "github.com/fluxcd/pkg/runtime/testenv" - "github.com/onsi/gomega" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -108,7 +107,7 @@ func logObject(t *testing.T, obj interface{}) { t.Log("object:\n", string(sts)) } -func checkInstanceReadiness(g *gomega.WithT, obj *fluxcdv1.FluxInstance) { +func checkInstanceReadiness(g *WithT, obj *fluxcdv1.FluxInstance) { statusCheck := kcheck.NewInProgressChecker(testClient) statusCheck.DisableFetch = true statusCheck.WithT(g).CheckErr(context.Background(), obj)