Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lastArtifactRevision to FluxInstance status #124

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1/fluxinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions internal/controller/fluxinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/fluxinstance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package controller
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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{
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Loading