Skip to content

Commit

Permalink
Correctly handle kustomization namespace for flux test (#247)
Browse files Browse the repository at this point in the history
Issue #245

```
$ flux-local test -v --path tests/testdata/cluster5/ 
======================================= test session starts ========================================
collected 1 item                                                                                   

tests/testdata/cluster5/clusters/prod::flux-system::kustomization PASSED                     [100%]

======================================== 1 passed in 0.10s =========================================
```

```
$ flux-local test -v -A --path tests/testdata/cluster5/ 
======================================= test session starts ========================================
collected 3 items                                                                                  

tests/testdata/cluster5/clusters/prod::infra-configs::kustomization PASSED                   [ 33%]
tests/testdata/cluster5/clusters/prod::infra-controllers::kustomization PASSED               [ 66%]
tests/testdata/cluster5/clusters/prod::flux-system::kustomization PASSED                     [100%]

======================================== 3 passed in 0.30s =========================================
  • Loading branch information
allenporter authored Jun 30, 2023
1 parent e823bb3 commit 4fe641b
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 0 deletions.
1 change: 1 addition & 0 deletions flux_local/tool/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ async def run( # type: ignore[no-untyped-def]
# If a real file path, then clear so it is not a test nodeid filter
if test_path.startswith(".") or test_path.startswith("/"):
test_path = None
query.kustomization.namespace = query.cluster.namespace
query.kustomization.skip_crds = True
query.helm_release.enabled = enable_helm
query.helm_release.namespace = None
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/cluster5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This repo has kustomizations that are not in the flux-system namespace.
26 changes: 26 additions & 0 deletions tests/testdata/cluster5/clusters/prod/flux-system/gotk-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: flux-system
namespace: flux-system
spec:
interval: 1m0s
ref:
branch: main
secretRef:
name: flux-system
url: ssh://[email protected]/allenporter/flux-local
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: flux-system
namespace: flux-system
spec:
interval: 10m0s
path: ./tests/testdata/cluster5/clusters/prod
prune: true
sourceRef:
kind: GitRepository
name: flux-system
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- gotk-sync.yaml
33 changes: 33 additions & 0 deletions tests/testdata/cluster5/clusters/prod/infrastructure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: infra-controllers
namespace: controllers
spec:
interval: 1h
retryInterval: 1m
timeout: 5m
sourceRef:
kind: GitRepository
name: flux-system
path: ./tests/testdata/cluster5/infrastructure/controllers
prune: true
wait: true
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: infra-configs
namespace: configs
spec:
dependsOn:
- name: infra-controllers
interval: 1h
retryInterval: 1m
timeout: 5m
sourceRef:
kind: GitRepository
name: flux-system
path: ./tests/testdata/cluster5/infrastructure/configs
prune: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: test-allow-policy
annotations:
policies.kyverno.io/title: Test Allow Policy
policies.kyverno.io/description: >-
Policy that is expected to allow resources under test through since no
resources should have this annotation.
spec:
validationFailureAction: audit
background: true
rules:
- name: forbid-test-annotation
match:
resources:
kinds:
- ConfigMap
validate:
message: "Found test-annotation"
pattern:
metadata:
=(annotations):
X(flux-local/test-annotation): "null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 30m
provider: generic
timeout: 1m0s
url: https://charts.bitnami.com/bitnami
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 5m
type: oci
url: oci://ghcr.io/stefanprodan/charts
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: weave-charts
namespace: flux-system
spec:
interval: 120m
type: oci
url: oci://ghcr.io/weaveworks/charts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- cluster-policies.yaml
- helm-repositories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- metallb-release.yaml
- weave-gitops-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: metallb
namespace: metallb
spec:
chart:
spec:
chart: metallb
reconcileStrategy: ChartVersion
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
version: 4.1.14
install:
crds: CreateReplace
remediation:
retries: 3
interval: 5m
releaseName: metallb
upgrade:
crds: CreateReplace
values:
speaker:
secretName: "metallb-secret"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: weave-gitops
namespace: flux-system
spec:
interval: 60m
chart:
spec:
chart: weave-gitops
version: "4.0.22"
sourceRef:
kind: HelmRepository
name: weave-charts
interval: 12h

0 comments on commit 4fe641b

Please sign in to comment.