Skip to content

Commit

Permalink
Add sync id and path to report
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed Jun 21, 2024
1 parent 2968dd2 commit 9c63cbc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
8 changes: 8 additions & 0 deletions api/v1/fluxreport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ type FluxReconcilerStats struct {

// FluxSyncStatus defines the observed state of the cluster sync.
type FluxSyncStatus struct {
// ID is the identifier of the sync.
// +required
ID string `json:"id"`

// Path is the kustomize path of the sync.
// +optional
Path string `json:"path,omitempty"`

// Ready is the readiness status of the sync.
// +required
Ready bool `json:"ready"`
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/fluxcd.controlplane.io_fluxreports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ spec:
SyncStatus is the status of the cluster sync
Source and Kustomization resources.
properties:
id:
description: ID is the identifier of the sync.
type: string
path:
description: Path is the kustomize path of the sync.
type: string
ready:
description: Ready is the readiness status of the sync.
type: boolean
Expand All @@ -164,6 +170,7 @@ spec:
description: Status is the status of the sync.
type: string
required:
- id
- ready
- status
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ metadata:
],
"sync": {
"ready": true,
"source": "https://github.com/controlplaneio-fluxcd/distribution.git",
"id": "kustomization/flux-system",
"path": "clusters/production",
"source": "https://github.com/my-org/my-fleet.git",
"status": "Applied revision: refs/heads/main@sha1:a90cd1ac35de01c175f7199315d3f4cd60195911"
}
}
Expand Down Expand Up @@ -179,7 +181,7 @@ spec:
displayName: FluxReport
kind: FluxReport
version: v1
description: Flux Report
description: Flux Report (Autogenerated)
install:
strategy: deployment
spec:
Expand Down
11 changes: 8 additions & 3 deletions docs/api/v1/fluxreport.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ spec:
totalSize: 78.1 KiB
sync:
ready: true
source: https://github.com/controlplaneio-fluxcd/distribution.git
id: kustomization/flux-system
path: clusters/production
source: https://github.com/my-org/my-fleet.git
status: 'Applied revision: refs/heads/main@sha1:a90cd1ac35de01c175f7199315d3f4cd60195911'
status:
conditions:
Expand Down Expand Up @@ -231,15 +233,18 @@ spec:

### Cluster sync status

The `.spec.sync` field contains information about the Flux sync status,
including the source URL, the applied revision, and the sync readiness status.
The `.spec.sync` field contains information about the cluster sync status,
including the Flux Kustomization name, source URL, the applied revision,
and the sync readiness status.

Example:

```yaml
spec:
sync:
ready: true
id: kustomization/flux-system
path: tests/v2.3/sources
source: https://github.com/controlplaneio-fluxcd/distribution.git
status: 'Applied revision: refs/heads/main@sha1:a90cd1ac35de01c175f7199315d3f4cd60195911'
```
Expand Down
1 change: 1 addition & 0 deletions internal/controller/fluxreport_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestFluxReportReconciler_Reconcile(t *testing.T) {
// Check reported sync.
g.Expect(report.Spec.SyncStatus).ToNot(BeNil())
g.Expect(report.Spec.SyncStatus.Source).To(Equal(instance.Spec.Sync.URL))
g.Expect(report.Spec.SyncStatus.ID).To(Equal("kustomization/" + ns.Name))

// Check ready condition.
g.Expect(conditions.GetReason(report, meta.ReadyCondition)).To(BeIdenticalTo(meta.SucceededReason))
Expand Down
9 changes: 9 additions & 0 deletions internal/reporter/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package reporter
import (
"context"
"fmt"
"strings"

"github.com/fluxcd/cli-utils/pkg/kstatus/status"
"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -44,10 +45,17 @@ func (r *FluxStatusReporter) getSyncStatus(ctx context.Context, crds []metav1.Gr
}

syncStatus := &fluxcdv1.FluxSyncStatus{
ID: fmt.Sprintf("%s/%s", strings.ToLower(syncKind), r.namespace),
Ready: false,
Status: "not initialized",
}

// Read spec.path from the sync object.
if path, found, _ := unstructured.NestedString(syncObj.Object, "spec", "path"); found {
syncStatus.Path = path
}

// Set sync readiness based on the Kustomization object conditions.
if obj, err := status.GetObjectWithConditions(syncObj.Object); err == nil {
for _, cond := range obj.Status.Conditions {
if cond.Type == meta.ReadyCondition {
Expand All @@ -57,6 +65,7 @@ func (r *FluxStatusReporter) getSyncStatus(ctx context.Context, crds []metav1.Gr
}
}

// Set source URL and readiness based on the source object conditions.
if sourceKind, found, _ := unstructured.NestedString(syncObj.Object, "spec", "sourceRef", "kind"); found {
sourceGVK := gvkFor(sourceKind, crds)
if sourceGVK == nil {
Expand Down

0 comments on commit 9c63cbc

Please sign in to comment.