Skip to content

Commit

Permalink
Clean up logging and move location of expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter committed Jun 29, 2024
1 parent 84858ce commit f4071e4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 64 deletions.
18 changes: 7 additions & 11 deletions flux_local/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,6 @@ async def kustomization_traversal(
_LOGGER.debug("Already visited %s", path)
continue
visited_paths.add(path)

_LOGGER.debug("BEFORE: %s", visit_ks)
if visit_ks is not None and visit_ks.postbuild_substitute_from:
_LOGGER.debug("Expand: %s", cluster_config)
values.expand_postbuild_substitute_reference(
visit_ks,
cluster_config,
)
_LOGGER.debug("AFTER: %s", visit_ks)

tasks.append(visit_kustomization(selector, builder, path, visit_ks))

# Find new kustomizations
Expand All @@ -543,6 +533,12 @@ async def kustomization_traversal(
if not (ks_path := adjust_ks_path(ks, selector)):
continue
ks.path = str(ks_path)
if ks.postbuild_substitute_from:
values.expand_postbuild_substitute_reference(
ks,
cluster_config,
)

path_queue.append((ks_path, ks))
response_kustomizations.append(ks)

Expand Down Expand Up @@ -746,7 +742,7 @@ async def update_kustomization(cluster: Cluster) -> None:
)
# Clear the cache to remove any previous builds that are
# missing the postbuild substitutions.
# builder.remove(kustomization)
builder.remove(kustomization)

build_tasks.append(
build_kustomization(
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/test_git_repo.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@
"Cluster 'tests/testdata/cluster'": dict({
"Build 'flux-system/apps'": dict({
'cmds': list([
'flux build tests/testdata/cluster/apps/prod (abs)',
"kustomize cfg grep 'kind=^(CustomResourceDefinition|Secret)$' --invert-match",
"kustomize cfg grep 'kind=^(ConfigMap|HelmRepository|HelmRelease|Secret|ClusterPolicy)$'",
]),
Expand Down
43 changes: 43 additions & 0 deletions tests/tool/__snapshots__/test_build.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,47 @@
annotations:
config.kubernetes.io/index: '2'
internal.config.kubernetes.io/index: '2'
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: apps
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: example-com-staging
annotations:
config.kubernetes.io/index: '3'
internal.config.kubernetes.io/index: '3'
spec:
commonName: example.com
dnsNames:
- example.com
- '*.example.com'
issuerRef:
kind: ClusterIssuer
name: letsencrypt-staging
secretName: example-com-staging-tls
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: apps
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: other-com-staging
annotations:
config.kubernetes.io/index: '4'
internal.config.kubernetes.io/index: '4'
spec:
commonName: other.com
dnsNames:
- other.com
- '*.other.com'
- example-value
issuerRef:
kind: ClusterIssuer
name: letsencrypt-staging
secretName: other-com-staging-tls

---
apiVersion: kustomize.toolkit.fluxcd.io/v1
Expand Down Expand Up @@ -2811,6 +2852,8 @@
---
apiVersion: v1
data:
SECRET_DOMAIN: example.com
SECRET_DOMAIN2: other.com
cluster_label: example-value
kind: ConfigMap
metadata:
Expand Down
114 changes: 61 additions & 53 deletions tests/tool/__snapshots__/test_diff_ks.ambr
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
# serializer version: 1
# name: test_diff_ks[apps]
'''
--- tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/example-com-staging

+++ tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/example-com-staging

@@ -0,0 +1,18 @@

+---
+apiVersion: cert-manager.io/v1
+kind: Certificate
+metadata:
+ labels:
+ kustomize.toolkit.fluxcd.io/name: apps
+ kustomize.toolkit.fluxcd.io/namespace: flux-system
+ name: example-com-staging
+spec:
+ commonName: example.com
+ dnsNames:
+ - example.com
+ - '*.example.com'
+ issuerRef:
+ kind: ClusterIssuer
+ name: letsencrypt-staging
+ secretName: example-com-staging-tls
+
--- tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/other-com-staging

+++ tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/other-com-staging

@@ -0,0 +1,19 @@

+---
+apiVersion: cert-manager.io/v1
+kind: Certificate
+metadata:
+ labels:
+ kustomize.toolkit.fluxcd.io/name: apps
+ kustomize.toolkit.fluxcd.io/namespace: flux-system
+ name: other-com-staging
+spec:
+ commonName: other.com
+ dnsNames:
+ - other.com
+ - '*.other.com'
+ - example-value
+ issuerRef:
+ kind: ClusterIssuer
+ name: letsencrypt-staging
+ secretName: other-com-staging-tls
+

'''
''
# ---
# name: test_diff_ks[ks-external]
''
Expand Down Expand Up @@ -121,7 +70,7 @@
- values:
- ingress:
- additionalLabels:
- cluster_label: null
- cluster_label: example-value
- className: nginx
- enabled: true
- hosts:
Expand Down Expand Up @@ -157,6 +106,65 @@
- name: podinfo-config
- namespace: podinfo
-
- kustomization_path: tests/testdata/cluster/apps/prod
kind: Certificate
namespace: flux-system
name: example-com-staging
diff: |-
--- tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/example-com-staging

+++ tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/example-com-staging

@@ -1,18 +0,0 @@

----
-apiVersion: cert-manager.io/v1
-kind: Certificate
-metadata:
- labels:
- kustomize.toolkit.fluxcd.io/name: apps
- kustomize.toolkit.fluxcd.io/namespace: flux-system
- name: example-com-staging
-spec:
- commonName: example.com
- dnsNames:
- - example.com
- - '*.example.com'
- issuerRef:
- kind: ClusterIssuer
- name: letsencrypt-staging
- secretName: example-com-staging-tls
-
- kustomization_path: tests/testdata/cluster/apps/prod
kind: Certificate
namespace: flux-system
name: other-com-staging
diff: |-
--- tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/other-com-staging

+++ tests/testdata/cluster/apps/prod Kustomization: flux-system/apps Certificate: flux-system/other-com-staging

@@ -1,19 +0,0 @@

----
-apiVersion: cert-manager.io/v1
-kind: Certificate
-metadata:
- labels:
- kustomize.toolkit.fluxcd.io/name: apps
- kustomize.toolkit.fluxcd.io/namespace: flux-system
- name: other-com-staging
-spec:
- commonName: other.com
- dnsNames:
- - other.com
- - '*.other.com'
- - example-value
- issuerRef:
- kind: ClusterIssuer
- name: letsencrypt-staging
- secretName: other-com-staging-tls
-


'''
Expand Down

0 comments on commit f4071e4

Please sign in to comment.