diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 605de5d0..87681bc2 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -191,7 +191,14 @@ jobs: /tmp/flux create kustomization flux-system \ --source=flux-system \ --path=./clusters/staging + kubectl -n flux-system wait kustomization/infrastructure --for=condition=ready --timeout=5m kubectl -n flux-system wait kustomization/apps --for=condition=ready --timeout=5m + kubectl -n nginx wait helmrelease/nginx --for=condition=ready --timeout=5m + kubectl -n redis wait helmrelease/redis --for=condition=ready --timeout=5m + kubectl -n podinfo wait helmrelease/podinfo --for=condition=ready --timeout=5m + - name: flux tree + run: | + /tmp/flux tree kustomization flux-system | grep Service/podinfo - name: flux check run: | /tmp/flux check diff --git a/cmd/flux/testdata/tree/kustomizations.yaml b/cmd/flux/testdata/tree/kustomizations.yaml index a5739d6f..45055da2 100644 --- a/cmd/flux/testdata/tree/kustomizations.yaml +++ b/cmd/flux/testdata/tree/kustomizations.yaml @@ -65,8 +65,6 @@ status: v: v1 - id: cert-manager_cert-manager_source.toolkit.fluxcd.io_HelmRepository v: v1beta1 - - id: cert-manager_cert-manager_helm.toolkit.fluxcd.io_HelmRelease - v: v2beta1 --- apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 kind: Kustomization @@ -87,3 +85,4 @@ status: reason: ReconciliationSucceeded status: "True" type: Ready +--- diff --git a/cmd/flux/testdata/tree/tree-compact.golden b/cmd/flux/testdata/tree/tree-compact.golden index a635f6c8..d4e8a4f9 100644 --- a/cmd/flux/testdata/tree/tree-compact.golden +++ b/cmd/flux/testdata/tree/tree-compact.golden @@ -1,6 +1,5 @@ Kustomization/{{ .fluxns }}/flux-system ├── Kustomization/{{ .fluxns }}/infrastructure -│ ├── HelmRepository/cert-manager/cert-manager -│ └── HelmRelease/cert-manager/cert-manager +│ └── HelmRepository/cert-manager/cert-manager └── GitRepository/{{ .fluxns }}/flux-system diff --git a/cmd/flux/testdata/tree/tree.golden b/cmd/flux/testdata/tree/tree.golden index e2af2008..c5863ed1 100644 --- a/cmd/flux/testdata/tree/tree.golden +++ b/cmd/flux/testdata/tree/tree.golden @@ -6,7 +6,6 @@ Kustomization/{{ .fluxns }}/flux-system ├── Deployment/{{ .fluxns }}/source-controller ├── Kustomization/{{ .fluxns }}/infrastructure │ ├── Namespace/cert-manager -│ ├── HelmRepository/cert-manager/cert-manager -│ └── HelmRelease/cert-manager/cert-manager +│ └── HelmRepository/cert-manager/cert-manager └── GitRepository/{{ .fluxns }}/flux-system diff --git a/cmd/flux/tree_kustomization.go b/cmd/flux/tree_kustomization.go index 91c80873..d3d43ec6 100644 --- a/cmd/flux/tree_kustomization.go +++ b/cmd/flux/tree_kustomization.go @@ -33,6 +33,7 @@ import ( "github.com/fluxcd/pkg/ssa" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/cli-utils/pkg/object" "sigs.k8s.io/controller-runtime/pkg/client" @@ -126,13 +127,15 @@ func treeKustomization(ctx context.Context, tree tree.ObjMetadataTree, item *kus return nil } + compactGroup := "toolkit.fluxcd.io" + for _, entry := range item.Status.Inventory.Entries { objMetadata, err := object.ParseObjMetadata(entry.ID) if err != nil { return err } - if compact && !strings.Contains(objMetadata.GroupKind.Group, "toolkit.fluxcd.io") { + if compact && !strings.Contains(objMetadata.GroupKind.Group, compactGroup) { continue } @@ -156,11 +159,11 @@ func treeKustomization(ctx context.Context, tree tree.ObjMetadataTree, item *kus return err } - for _, metadata := range objects { - if compact && !strings.Contains(objMetadata.GroupKind.Group, "toolkit.fluxcd.io") { + for _, obj := range objects { + if compact && !strings.Contains(obj.GroupKind.Group, compactGroup) { continue } - ks.Add(metadata) + ks.Add(obj) } } @@ -179,7 +182,6 @@ func treeKustomization(ctx context.Context, tree tree.ObjMetadataTree, item *kus return err } } - } return nil @@ -207,7 +209,12 @@ func getHelmReleaseInventory(ctx context.Context, objectKey client.ObjectKey, ku } else if hr.Spec.TargetNamespace != "" { storageName = strings.Join([]string{hr.Spec.TargetNamespace, hr.Name}, "-") } + storageVersion := hr.Status.LastReleaseRevision + // skip release if it failed to install + if storageVersion < 1 { + return nil, nil + } storageKey := client.ObjectKey{ Namespace: storageNamespace, @@ -216,6 +223,10 @@ func getHelmReleaseInventory(ctx context.Context, objectKey client.ObjectKey, ku storageSecret := &corev1.Secret{} if err := kubeClient.Get(ctx, storageKey, storageSecret); err != nil { + // skip release if it has no storage + if apierrors.IsNotFound(err) { + return nil, nil + } return nil, fmt.Errorf("failed to find the Helm storage object for HelmRelease '%s': %w", objectKey.String(), err) }