Skip to content

Commit

Permalink
Change placeholder values to avoid invalid yaml parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter committed Jun 29, 2024
1 parent ca50383 commit 4481414
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ repos:
rev: v4.6.0
hooks:
- id: trailing-whitespace
exclude: '^tests/.*/__snapshots__/.*.ambr$'
- id: end-of-file-fixer
- id: check-yaml
exclude: '^tests/testdata/cluster8/apps/.*\.yaml$'
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.4.2
Expand Down
2 changes: 1 addition & 1 deletion flux_local/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
SECRET_KIND = "Secret"
CONFIG_MAP_KIND = "ConfigMap"
DEFAULT_NAMESPACE = "flux-system"
VALUE_PLACEHOLDER = "!!PLACEHOLDER!!"
VALUE_PLACEHOLDER = "..PLACEHOLDER.."
VALUE_B64_PLACEHOLDER = base64.b64encode(VALUE_PLACEHOLDER.encode())
HELM_REPOSITORY = "HelmRepository"
GIT_REPOSITORY = "GitRepository"
Expand Down
19 changes: 18 additions & 1 deletion tests/__snapshots__/test_values.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,24 @@
'tag': '7.0.6',
}),
'tls': dict({
'crt': '!!PLACEHOLDER!!',
'crt': '..PLACEHOLDER..',
}),
})
# ---
# name: test_value_references.1
dict({
'apiServerProxyConfig': dict({
'mode': 'true',
}),
'oauth': dict({
'clientId': '..PLACEHOLDER..',
'clientSecret': '..PLACEHOLDER..',
}),
'operatorConfig': dict({
'defaultTags': list([
'tag:k8s',
]),
'hostname': 'tailscale-operator',
}),
})
# ---
17 changes: 11 additions & 6 deletions tests/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ async def test_value_references(snapshot: SnapshotAssertion) -> None:
assert len(manifest.clusters[0].kustomizations) == 2
ks = manifest.clusters[0].kustomizations[0]
assert ks.name == "apps"
assert len(ks.helm_releases) == 1
assert len(ks.helm_releases) == 2
hr = ks.helm_releases[0]
assert hr.name == "podinfo"
assert hr.values == snapshot
hr = ks.helm_releases[1]
assert hr.name == "tailscale-operator"
assert hr.values == snapshot


def test_values_references_with_values_key() -> None:
Expand Down Expand Up @@ -138,7 +141,6 @@ def test_values_references_with_missing_values_key() -> None:
}



def test_values_references_with_missing_secret() -> None:
"""Test for expanding a value reference with a missing secret."""
hr = HelmRelease(
Expand Down Expand Up @@ -170,7 +172,7 @@ def test_values_references_with_missing_secret() -> None:
assert updated_hr.values == {
"test": "test",
"target": {
"path": "!!PLACEHOLDER!!",
"path": "..PLACEHOLDER..",
},
}

Expand Down Expand Up @@ -435,8 +437,8 @@ def test_values_references_secret() -> None:
assert updated_hr.values == {
"test": "test",
"target": {
"path1": "!!PLACEHOLDER!!",
"path2": "!!PLACEHOLDER!!",
"path1": "..PLACEHOLDER..",
"path2": "..PLACEHOLDER..",
},
}

Expand Down Expand Up @@ -569,4 +571,7 @@ def test_cluster_config() -> None:
config = ks_cluster_config([ks1, ks2])
# Ensure can be called repeatedly
assert len(list(config.secrets)) == 2
assert [ s.name for s in config.secrets ] == ['test-values-secret','other-values-secret']
assert [s.name for s in config.secrets] == [
"test-values-secret",
"other-values-secret",
]
1 change: 1 addition & 0 deletions tests/testdata/cluster8/apps/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ resources:
- podinfo.yaml
- podinfo-values.yaml
- podinfo-tls-values.yaml
- tailscale.yaml
44 changes: 44 additions & 0 deletions tests/testdata/cluster8/apps/tailscale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/source.toolkit.fluxcd.io/helmrepository_v1.json
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: tailscale
namespace: flux-system
spec:
interval: 30m
url: https://pkgs.tailscale.com/helmcharts
timeout: 3m
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: tailscale-operator
namespace: network
spec:
interval: 30m
chart:
spec:
chart: tailscale-operator
version: 1.68.1
interval: 30m
sourceRef:
kind: HelmRepository
name: tailscale
namespace: flux-system
values:
operatorConfig:
hostname: "tailscale-operator"
defaultTags:
- "tag:k8s"
apiServerProxyConfig:
mode: "true"
valuesFrom:
- kind: Secret
name: tailscale-operator
valuesKey: client_id
targetPath: oauth.clientId
- kind: Secret
name: tailscale-operator
valuesKey: client_secret
targetPath: oauth.clientSecret
Loading

0 comments on commit 4481414

Please sign in to comment.