Add flux tree to e2e tests

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
pull/2008/head
Stefan Prodan 3 years ago
parent 722962c138
commit d9bb4c631e
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF

@ -191,7 +191,14 @@ jobs:
/tmp/flux create kustomization flux-system \ /tmp/flux create kustomization flux-system \
--source=flux-system \ --source=flux-system \
--path=./clusters/staging --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 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 - name: flux check
run: | run: |
/tmp/flux check /tmp/flux check

@ -65,8 +65,6 @@ status:
v: v1 v: v1
- id: cert-manager_cert-manager_source.toolkit.fluxcd.io_HelmRepository - id: cert-manager_cert-manager_source.toolkit.fluxcd.io_HelmRepository
v: v1beta1 v: v1beta1
- id: cert-manager_cert-manager_helm.toolkit.fluxcd.io_HelmRelease
v: v2beta1
--- ---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization kind: Kustomization
@ -87,3 +85,4 @@ status:
reason: ReconciliationSucceeded reason: ReconciliationSucceeded
status: "True" status: "True"
type: Ready type: Ready
---

@ -1,6 +1,5 @@
Kustomization/{{ .fluxns }}/flux-system Kustomization/{{ .fluxns }}/flux-system
├── Kustomization/{{ .fluxns }}/infrastructure ├── Kustomization/{{ .fluxns }}/infrastructure
│ ├── HelmRepository/cert-manager/cert-manager │ └── HelmRepository/cert-manager/cert-manager
│ └── HelmRelease/cert-manager/cert-manager
└── GitRepository/{{ .fluxns }}/flux-system └── GitRepository/{{ .fluxns }}/flux-system

@ -6,7 +6,6 @@ Kustomization/{{ .fluxns }}/flux-system
├── Deployment/{{ .fluxns }}/source-controller ├── Deployment/{{ .fluxns }}/source-controller
├── Kustomization/{{ .fluxns }}/infrastructure ├── Kustomization/{{ .fluxns }}/infrastructure
│ ├── Namespace/cert-manager │ ├── Namespace/cert-manager
│ ├── HelmRepository/cert-manager/cert-manager │ └── HelmRepository/cert-manager/cert-manager
│ └── HelmRelease/cert-manager/cert-manager
└── GitRepository/{{ .fluxns }}/flux-system └── GitRepository/{{ .fluxns }}/flux-system

@ -33,6 +33,7 @@ import (
"github.com/fluxcd/pkg/ssa" "github.com/fluxcd/pkg/ssa"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/cli-utils/pkg/object" "sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
@ -126,13 +127,15 @@ func treeKustomization(ctx context.Context, tree tree.ObjMetadataTree, item *kus
return nil return nil
} }
compactGroup := "toolkit.fluxcd.io"
for _, entry := range item.Status.Inventory.Entries { for _, entry := range item.Status.Inventory.Entries {
objMetadata, err := object.ParseObjMetadata(entry.ID) objMetadata, err := object.ParseObjMetadata(entry.ID)
if err != nil { if err != nil {
return err return err
} }
if compact && !strings.Contains(objMetadata.GroupKind.Group, "toolkit.fluxcd.io") { if compact && !strings.Contains(objMetadata.GroupKind.Group, compactGroup) {
continue continue
} }
@ -156,11 +159,11 @@ func treeKustomization(ctx context.Context, tree tree.ObjMetadataTree, item *kus
return err return err
} }
for _, metadata := range objects { for _, obj := range objects {
if compact && !strings.Contains(objMetadata.GroupKind.Group, "toolkit.fluxcd.io") { if compact && !strings.Contains(obj.GroupKind.Group, compactGroup) {
continue continue
} }
ks.Add(metadata) ks.Add(obj)
} }
} }
@ -179,7 +182,6 @@ func treeKustomization(ctx context.Context, tree tree.ObjMetadataTree, item *kus
return err return err
} }
} }
} }
return nil return nil
@ -207,7 +209,12 @@ func getHelmReleaseInventory(ctx context.Context, objectKey client.ObjectKey, ku
} else if hr.Spec.TargetNamespace != "" { } else if hr.Spec.TargetNamespace != "" {
storageName = strings.Join([]string{hr.Spec.TargetNamespace, hr.Name}, "-") storageName = strings.Join([]string{hr.Spec.TargetNamespace, hr.Name}, "-")
} }
storageVersion := hr.Status.LastReleaseRevision storageVersion := hr.Status.LastReleaseRevision
// skip release if it failed to install
if storageVersion < 1 {
return nil, nil
}
storageKey := client.ObjectKey{ storageKey := client.ObjectKey{
Namespace: storageNamespace, Namespace: storageNamespace,
@ -216,6 +223,10 @@ func getHelmReleaseInventory(ctx context.Context, objectKey client.ObjectKey, ku
storageSecret := &corev1.Secret{} storageSecret := &corev1.Secret{}
if err := kubeClient.Get(ctx, storageKey, storageSecret); err != nil { 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) return nil, fmt.Errorf("failed to find the Helm storage object for HelmRelease '%s': %w", objectKey.String(), err)
} }

Loading…
Cancel
Save