Check rendered kustomize output in the deploy policy (M9.8f review)
The policy check now renders every overlay with pinned, checksum-verified kustomize v5.8.1 (ADR-0088) and validates effective namespaces, session/input/ listener environment and arguments, ports, Services, quotas, policies, Ingresses and Secrets, so inline/JSON patches and namespace changes cannot bypass it. Route enabling is gated on an ADR-0087 amendment with tested server windows, route addresses must be RFC 1918 or explicitly approved, and the Local health-check node port is documented with its enabling evidence. Self-test grows to 33 cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,7 @@ case "$suite" in
|
||||
pattern="$common|$native|tests/|$postgres_tools|third_party/mbedtls/|tools/prepare-mbedtls\.cmake|tools/mbedtls-pin\.cmake|deploy/docker/Dockerfile"
|
||||
;;
|
||||
deploy)
|
||||
pattern="$common|deploy/|tools/ops/|tools/backup/|tools/ci/deploy-policy-(check|selftest)\.py|tools/ci/monitoring-check\.sh|tools/ci/ops-lib-check\.sh"
|
||||
pattern="$common|deploy/|tools/ops/|tools/backup/|tools/ci/deploy-policy-(check|selftest)\.py|tools/ci/prepare-kustomize\.sh|tools/ci/monitoring-check\.sh|tools/ci/ops-lib-check\.sh"
|
||||
;;
|
||||
server-image)
|
||||
pattern="$common|$native|migrations/|tools/prepare-postgres\.sh|tools/ci/server-image-smoke\.sh|deploy/docker/Dockerfile"
|
||||
|
||||
@@ -28,10 +28,31 @@ environment-isolation or World0-protection invariant is broken:
|
||||
- the dev session route (ADR-0087): loopback listener everywhere except the
|
||||
evolution-dev route component; that component is the only LoadBalancer and the
|
||||
only Service on the session port, narrowly shaped, and it cannot be enabled while
|
||||
markers are unresolved or before server-enforced session windows exist.
|
||||
markers are unresolved or before server-enforced session windows exist;
|
||||
- rendered output (ADR-0088): every overlay is built with the pinned kustomize and
|
||||
the effective objects are checked (namespaces, listener/session/input environment,
|
||||
arguments, ports, Services, quotas, policies, Ingresses, Secrets), so inline or
|
||||
JSON patches and namespace transformations cannot bypass the source checks.
|
||||
"""
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
# Enabling the dev session route needs ADR-0087 to be amended with the implemented
|
||||
# session-window argument contract and runtime expiry tests (expiry during a session,
|
||||
# restart after expiry, delayed application, extend/close races, clock movement,
|
||||
# synthetic inputs stopping while commits drain). Until then this stays False; a
|
||||
# string such as --session-window in a manifest is not proof of enforcement.
|
||||
ROUTE_ENABLING_PERMITTED = False
|
||||
# Addresses the route may use: RFC 1918 plus internal ranges the maintainer has
|
||||
# explicitly approved in ADR-0087 (none yet; the cluster LAN 172.10.0.0/16 is not
|
||||
# RFC 1918 and needs that approval before use).
|
||||
APPROVED_INTERNAL = []
|
||||
INTERNAL = [ipaddress.ip_network(n) for n in ('10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16')] + \
|
||||
[ipaddress.ip_network(n) for n in APPROVED_INTERNAL]
|
||||
|
||||
|
||||
def internal(network):
|
||||
return any(network.version == r.version and network.subnet_of(r) for r in INTERNAL)
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -315,7 +336,9 @@ for path, doc in objects:
|
||||
check(len(route_ranges) >= 1, f'{path}: loadBalancerSourceRanges must name the permitted CIDRs')
|
||||
if not vip.startswith('REPLACE'):
|
||||
try:
|
||||
check(ipaddress.ip_address(vip).is_private, f'{path}: the VIP must be an internal address')
|
||||
address = ipaddress.ip_address(vip)
|
||||
check(internal(ipaddress.ip_network(f'{address}/{address.max_prefixlen}')),
|
||||
f'{path}: the VIP must be an internal address (RFC 1918 or approved in ADR-0087)')
|
||||
except ValueError:
|
||||
check(False, f'{path}: the VIP must be one IP address')
|
||||
for cidr in route_ranges:
|
||||
@@ -323,7 +346,7 @@ for path, doc in objects:
|
||||
continue
|
||||
try:
|
||||
network = ipaddress.ip_network(cidr)
|
||||
check(network.is_private and network.prefixlen >= (16 if network.version == 4 else 48),
|
||||
check(internal(network) and network.prefixlen >= (16 if network.version == 4 else 48),
|
||||
f'{path}: {cidr} must be a private range no wider than /16 (IPv6 /48)')
|
||||
except ValueError:
|
||||
check(False, f'{path}: {cidr} is not a CIDR')
|
||||
@@ -354,11 +377,9 @@ if route_enabled:
|
||||
for name in os.listdir(os.path.join(ROOT, ROUTE)):
|
||||
with open(os.path.join(ROOT, ROUTE, name), encoding='utf-8') as handle:
|
||||
check('REPLACE' not in handle.read(), f'{ROUTE}{name}: unresolved REPLACE marker with the route enabled')
|
||||
base_script = ' '.join(' '.join(c.get('args', [])) for p, d in objects
|
||||
if p == 'deploy/kubernetes/region/base/deployment.yaml' and d['kind'] == 'Deployment'
|
||||
for c in d['spec']['template']['spec']['containers'])
|
||||
check('--session-window' in base_script,
|
||||
'the dev session route needs server-enforced session windows (--session-window, ADR-0087)')
|
||||
check(ROUTE_ENABLING_PERMITTED,
|
||||
'the dev session route cannot be enabled until ADR-0087 records the implemented, tested '
|
||||
'server-enforced session windows')
|
||||
dev_quota = [d.get('spec', {}).get('hard', {}).get('services.loadbalancers') for p, d in objects
|
||||
if d['kind'] == 'ResourceQuota' and p.startswith(f'{platform}/dev/')]
|
||||
check(dev_quota == ['1'], 'the dev quota must allow exactly one LoadBalancer for the route')
|
||||
@@ -541,7 +562,123 @@ for tool, args, component in generators:
|
||||
f'{tool}: component {component} must be admitted by the database egress policy')
|
||||
check(pod['metadata'].get('namespace') == 'evolution-dev', f'{tool}: renders into its environment')
|
||||
|
||||
|
||||
# ADR-0088: the effective configuration is what kustomize renders. Every overlay is
|
||||
# built with the pinned binary and its output checked, independent of how patches,
|
||||
# components or namespace transformations produced it.
|
||||
def kustomize_binary():
|
||||
with open(os.path.join(ROOT, 'tools', 'ci', 'prepare-kustomize.sh'), encoding='utf-8') as f:
|
||||
version = re.search(r'^version=(v[0-9.]+)$', f.read(), re.M).group(1)
|
||||
candidates = [os.environ.get('KUSTOMIZE', ''),
|
||||
os.path.join(ROOT, '.cache', 'tools', f'kustomize-{version}', 'kustomize'),
|
||||
shutil.which('kustomize') or '']
|
||||
for candidate in candidates:
|
||||
if candidate and os.path.isfile(candidate):
|
||||
reported = subprocess.run([candidate, 'version'], capture_output=True, text=True).stdout.strip()
|
||||
if reported == version:
|
||||
return candidate
|
||||
return None
|
||||
|
||||
|
||||
SUPPORTED_KEYS = {'apiVersion', 'kind', 'namespace', 'resources', 'components', 'patches', 'images',
|
||||
'labels', 'commonAnnotations', 'commonLabels', 'configMapGenerator', 'generatorOptions'}
|
||||
for path, ds in manifests.items():
|
||||
if path.endswith('kustomization.yaml') and ds:
|
||||
unsupported = set(ds[0]) - SUPPORTED_KEYS
|
||||
check(not unsupported, f'{path}: unsupported kustomize features {sorted(unsupported)} (ADR-0088)')
|
||||
EXPECTED_NAMESPACE = {'deploy/kubernetes/dev': 'evolution-dev', 'deploy/kubernetes/stage': 'evolution-stage',
|
||||
'deploy/kubernetes/monitoring': 'aevolution-monitoring'}
|
||||
for env in ('dev', 'stage', 'world0'):
|
||||
for component in ('platform', 'region', 'stores'):
|
||||
EXPECTED_NAMESPACE[f'deploy/kubernetes/{component}/{env}'] = f'evolution-{env}'
|
||||
EXPECTED_NAMESPACE['deploy/kubernetes/platform/monitoring'] = 'aevolution-monitoring'
|
||||
CLUSTER_KINDS = {'Namespace', 'StorageClass', 'ValidatingAdmissionPolicy', 'ValidatingAdmissionPolicyBinding',
|
||||
'ClusterRole', 'ClusterRoleBinding', 'PersistentVolume'}
|
||||
binary = kustomize_binary()
|
||||
check(binary is not None, 'the pinned kustomize is required: run tools/ci/prepare-kustomize.sh (ADR-0088)')
|
||||
renders = {}
|
||||
if binary:
|
||||
for path, ds in sorted(manifests.items()):
|
||||
if not path.endswith('kustomization.yaml') or not ds or ds[0].get('kind') == 'Component':
|
||||
continue
|
||||
overlay = os.path.dirname(path)
|
||||
result = subprocess.run([binary, 'build', os.path.join(ROOT, overlay)], capture_output=True, text=True)
|
||||
check(result.returncode == 0, f'{overlay}: kustomize build failed: {result.stderr.strip()[:300]}')
|
||||
if result.returncode == 0:
|
||||
renders[overlay] = [d for d in yaml.safe_load_all(result.stdout) if isinstance(d, dict)]
|
||||
for overlay, docs in renders.items():
|
||||
expected = EXPECTED_NAMESPACE.get(overlay)
|
||||
route_services = [d for d in docs if d['kind'] == 'Service' and d['metadata']['name'] == 'evo-region-session']
|
||||
route_active = bool(route_services)
|
||||
for doc in docs:
|
||||
kind, name = doc['kind'], doc['metadata'].get('name', '')
|
||||
namespace = doc['metadata'].get('namespace')
|
||||
where = f'{overlay} (rendered) {kind}/{name}'
|
||||
if expected and kind not in CLUSTER_KINDS:
|
||||
check(namespace == expected, f'{where}: renders into {namespace}, expected {expected}')
|
||||
check(kind != 'Secret', f'{where}: rendered Secrets never come from Git')
|
||||
if kind == 'Deployment' and name == 'evo-region':
|
||||
pod = doc['spec']['template']['spec']
|
||||
for container in pod.get('containers', []) + pod.get('initContainers', []):
|
||||
env = {v.get('name'): v.get('value') for v in container.get('env', [])}
|
||||
text = ' '.join(container.get('command', []) + container.get('args', []))
|
||||
if container.get('name') == 'evo-server':
|
||||
check(env.get('REGION_SESSION') == '' and env.get('REGION_INPUTS') == '',
|
||||
f'{where}: sessions and synthetic inputs stay off in Git')
|
||||
listen = '0.0.0.0:7400' if route_active else '127.0.0.1:7400'
|
||||
check(env.get('REGION_SESSION_LISTEN') == listen,
|
||||
f'{where}: REGION_SESSION_LISTEN must be {listen} (route {"on" if route_active else "off"})')
|
||||
check(text.count('--session-listen') == 1 and '--session-listen "$REGION_SESSION_LISTEN"' in text,
|
||||
f'{where}: one session listener, addressed only by REGION_SESSION_LISTEN')
|
||||
else:
|
||||
check('--session-listen' not in text and '--synthetic-inputs' not in text,
|
||||
f'{where}: only evo-server may listen for sessions')
|
||||
ports = sorted((p.get('name'), p.get('containerPort')) for p in container.get('ports', []))
|
||||
allowed = [('ops', 9100), ('session', 7400)] if route_active else [('ops', 9100)]
|
||||
if container.get('name') == 'evo-server':
|
||||
check(ports == sorted(allowed), f'{where}: container ports must be {allowed}')
|
||||
if kind == 'Service':
|
||||
spec = doc['spec']
|
||||
session = any(p.get('port') == 7400 or p.get('targetPort') in (7400, 'session')
|
||||
for p in spec.get('ports', []))
|
||||
if name == 'evo-region-session':
|
||||
check(namespace == 'evolution-dev' and spec.get('type') == 'LoadBalancer'
|
||||
and spec.get('externalTrafficPolicy') == 'Local'
|
||||
and spec.get('allocateLoadBalancerNodePorts') is False
|
||||
and spec.get('ports') == [{'name': 'session', 'port': 7400, 'targetPort': 'session',
|
||||
'protocol': 'TCP'}],
|
||||
f'{where}: the route keeps its reviewed shape in evolution-dev')
|
||||
else:
|
||||
check(spec.get('type', 'ClusterIP') == 'ClusterIP' and not session,
|
||||
f'{where}: only the route may be a LoadBalancer or expose the session port')
|
||||
if kind == 'Ingress':
|
||||
check('7400' not in yaml.safe_dump(doc) and 'session' not in yaml.safe_dump(doc),
|
||||
f'{where}: the dev session is never an Ingress')
|
||||
if kind == 'NetworkPolicy':
|
||||
for rule in doc['spec'].get('ingress', []):
|
||||
if any(p.get('port') == 7400 for p in rule.get('ports', [])):
|
||||
ranges = route_services[0]['spec'].get('loadBalancerSourceRanges', []) if route_services else []
|
||||
blocks = [peer.get('ipBlock', {}) for peer in rule.get('from', [])]
|
||||
check(name == 'evo-region-session-ingress' and route_active and blocks
|
||||
and all(set(b) == {'cidr'} for b in blocks) and len(blocks) == len(rule.get('from', []))
|
||||
and sorted(b['cidr'] for b in blocks) == sorted(ranges),
|
||||
f'{where}: only the route policy admits TCP 7400, from exactly its source ranges')
|
||||
if kind == 'ResourceQuota':
|
||||
hard = doc['spec'].get('hard', {})
|
||||
check(hard.get('services.nodeports') == '0', f'{where}: node ports stay forbidden')
|
||||
limit = ('0', '1') if namespace == 'evolution-dev' and route_enabled else ('0',)
|
||||
check(hard.get('services.loadbalancers') in limit,
|
||||
f'{where}: LoadBalancers only in evolution-dev with the enabled route')
|
||||
if route_active:
|
||||
check(overlay in ('deploy/kubernetes/region/dev', 'deploy/kubernetes/dev'),
|
||||
f'{overlay}: renders the dev session route outside evolution-dev')
|
||||
check(ROUTE_ENABLING_PERMITTED,
|
||||
f'{overlay}: renders the dev session route, which cannot be enabled until ADR-0087 records '
|
||||
'the implemented, tested server-enforced session windows')
|
||||
check('REPLACE' not in yaml.safe_dump_all(docs), f'{overlay}: unresolved REPLACE marker in the rendered route')
|
||||
|
||||
for message in failures:
|
||||
print('FAIL', message)
|
||||
print(f'deploy policy: {len(objects)} objects in {len(manifests)} files, {len(failures)} failures')
|
||||
print(f'deploy policy: {len(objects)} objects in {len(manifests)} files, '
|
||||
f'{sum(len(d) for d in renders.values())} rendered objects in {len(renders)} overlays, {len(failures)} failures')
|
||||
sys.exit(1 if failures else 0)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""M9.8f fail-closed tests for deploy-policy-check.py (ADR-0087). Needs Python 3 and
|
||||
PyYAML only. Copies the manifests and the tools the check runs into a temporary tree,
|
||||
applies one unsafe change at a time and requires the check to fail with the expected
|
||||
message; the unmodified copy must pass.
|
||||
"""M9.8f fail-closed tests for deploy-policy-check.py (ADR-0087, ADR-0088). Needs
|
||||
Python 3, PyYAML and the pinned kustomize (tools/ci/prepare-kustomize.sh). Copies the
|
||||
manifests and the tools the check runs into a temporary tree, applies one unsafe change
|
||||
at a time and requires the check to fail with the expected message; the unmodified copy
|
||||
must pass. Includes inline strategic-merge and JSON patches and namespace changes, which
|
||||
only the rendered-output checks can see.
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
@@ -41,6 +43,26 @@ def write(tree, path, text):
|
||||
f.write(text)
|
||||
|
||||
|
||||
def inline_patch(tree, path, patch, target=None):
|
||||
"""Appends an inline patch (strategic merge, or JSON 6902 with a target)."""
|
||||
import yaml
|
||||
full = os.path.join(tree, path)
|
||||
with open(full, encoding='utf-8') as f:
|
||||
data = yaml.safe_load(f)
|
||||
entry = {'patch': patch}
|
||||
if target:
|
||||
entry['target'] = target
|
||||
data.setdefault('patches', []).append(entry)
|
||||
with open(full, 'w', encoding='utf-8') as f:
|
||||
yaml.safe_dump(data, f, sort_keys=False)
|
||||
|
||||
|
||||
def env_patch(name, value):
|
||||
return ('apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: evo-region\nspec:\n template:\n'
|
||||
' spec:\n containers:\n - name: evo-server\n env:\n'
|
||||
f' - {{name: {name}, value: "{value}"}}\n')
|
||||
|
||||
|
||||
def enable(tree):
|
||||
append(tree, DEV, 'components:\n - ../dev-session-route\n')
|
||||
|
||||
@@ -59,7 +81,47 @@ def quota_one(tree):
|
||||
CASES = [
|
||||
('enabling with unresolved markers', lambda t: enable(t), 'unresolved REPLACE marker'),
|
||||
('enabling before server-enforced windows', lambda t: (enable(t), resolve(t), quota_one(t)),
|
||||
'server-enforced session windows'),
|
||||
'cannot be enabled until ADR-0087'),
|
||||
('non-RFC 1918 VIP without approval', lambda t: edit(t, ROUTE + 'service.yaml', 'REPLACE-dev-session-vip',
|
||||
'172.10.1.210'), 'internal address'),
|
||||
# Review M9.8f P1: inline/JSON patches and namespace changes, seen only when rendered.
|
||||
('reviewer reproduction (inline listener, sessions, inputs, ops port)', lambda t: (
|
||||
inline_patch(t, DEV, env_patch('REGION_SESSION_LISTEN', '0.0.0.0:7400')),
|
||||
inline_patch(t, DEV, env_patch('REGION_SESSION', 'dev')),
|
||||
inline_patch(t, DEV, env_patch('REGION_INPUTS', 'development-v1')),
|
||||
inline_patch(t, DEV, 'apiVersion: v1\nkind: Service\nmetadata:\n name: evo-region-ops\nspec:\n ports:\n'
|
||||
' - {name: session, port: 7400, targetPort: 7400, protocol: TCP}\n')),
|
||||
'REGION_SESSION_LISTEN must be 127.0.0.1:7400'),
|
||||
('inline patch: listener on the pod interface', lambda t: inline_patch(
|
||||
t, DEV, env_patch('REGION_SESSION_LISTEN', '0.0.0.0:7400')), 'REGION_SESSION_LISTEN must be 127.0.0.1:7400'),
|
||||
('inline patch: sessions on', lambda t: inline_patch(t, DEV, env_patch('REGION_SESSION', 'dev')),
|
||||
'sessions and synthetic inputs stay off'),
|
||||
('inline patch: synthetic inputs on', lambda t: inline_patch(
|
||||
t, 'deploy/kubernetes/dev/kustomization.yaml', env_patch('REGION_INPUTS', 'development-v1')),
|
||||
'sessions and synthetic inputs stay off'),
|
||||
('JSON patch: session port on the ops Service', lambda t: inline_patch(
|
||||
t, DEV, '- op: add\n path: /spec/ports/-\n value: {name: session, port: 7400, targetPort: 7400, protocol: TCP}\n',
|
||||
{'kind': 'Service', 'name': 'evo-region-ops'}), 'only the route may be a LoadBalancer'),
|
||||
('JSON patch: LoadBalancer ops Service', lambda t: inline_patch(
|
||||
t, 'deploy/kubernetes/stage/kustomization.yaml', '- op: replace\n path: /spec/type\n value: LoadBalancer\n',
|
||||
{'kind': 'Service', 'name': 'evo-region-ops'}), 'only the route may be a LoadBalancer'),
|
||||
('JSON patch: container port 7400', lambda t: inline_patch(
|
||||
t, DEV, '- op: add\n path: /spec/template/spec/containers/0/ports/-\n'
|
||||
' value: {name: session, containerPort: 7400, protocol: TCP}\n',
|
||||
{'kind': 'Deployment', 'name': 'evo-region'}), 'container ports must be'),
|
||||
('JSON patch: second listener argument', lambda t: inline_patch(
|
||||
t, DEV, '- op: add\n path: /spec/template/spec/containers/0/args/-\n value: --session-listen 0.0.0.0:7401\n',
|
||||
{'kind': 'Deployment', 'name': 'evo-region'}), 'one session listener'),
|
||||
('namespace transformation', lambda t: edit(t, DEV, 'namespace: evolution-dev', 'namespace: evolution-stage'),
|
||||
'expected evolution-dev'),
|
||||
('inline quota patch in stage', lambda t: inline_patch(
|
||||
t, 'deploy/kubernetes/platform/stage/kustomization.yaml',
|
||||
'apiVersion: v1\nkind: ResourceQuota\nmetadata:\n name: aevolution-quota\nspec:\n hard:\n'
|
||||
' services.loadbalancers: "1"\n'), 'LoadBalancers only in evolution-dev'),
|
||||
('secret generator', lambda t: append(t, DEV, 'secretGenerator:\n - name: leaked\n literals: [a=b]\n'),
|
||||
'unsupported kustomize features'),
|
||||
('helm chart inflation', lambda t: append(t, DEV, 'helmCharts:\n - name: x\n repo: https://example.invalid\n'),
|
||||
'unsupported kustomize features'),
|
||||
('enabling without the dev quota', lambda t: (enable(t), resolve(t)), 'exactly one LoadBalancer'),
|
||||
('route included by stage', lambda t: append(t, 'deploy/kubernetes/region/stage/kustomization.yaml',
|
||||
'components:\n - ../dev-session-route\n'),
|
||||
@@ -118,12 +180,27 @@ def copy_tree(target):
|
||||
for directory in ('deploy', 'tools/ops', 'tools/backup'):
|
||||
shutil.copytree(os.path.join(ROOT, directory), os.path.join(target, directory))
|
||||
os.makedirs(os.path.join(target, 'tools', 'ci'))
|
||||
shutil.copy(os.path.join(ROOT, 'tools', 'ci', 'deploy-policy-check.py'), os.path.join(target, 'tools', 'ci'))
|
||||
for name in ('deploy-policy-check.py', 'prepare-kustomize.sh'):
|
||||
shutil.copy(os.path.join(ROOT, 'tools', 'ci', name), os.path.join(target, 'tools', 'ci'))
|
||||
|
||||
|
||||
def pinned_kustomize():
|
||||
with open(os.path.join(ROOT, 'tools', 'ci', 'prepare-kustomize.sh'), encoding='utf-8') as f:
|
||||
version = re.search(r'^version=(v[0-9.]+)$', f.read(), re.M).group(1)
|
||||
for candidate in (os.environ.get('KUSTOMIZE', ''),
|
||||
os.path.join(ROOT, '.cache', 'tools', f'kustomize-{version}', 'kustomize'),
|
||||
shutil.which('kustomize') or ''):
|
||||
if candidate and os.path.isfile(candidate):
|
||||
return os.path.abspath(candidate)
|
||||
raise SystemExit('selftest: the pinned kustomize is required (tools/ci/prepare-kustomize.sh)')
|
||||
|
||||
|
||||
KUSTOMIZE = pinned_kustomize()
|
||||
|
||||
|
||||
def run(tree):
|
||||
result = subprocess.run([sys.executable, os.path.join(tree, 'tools', 'ci', 'deploy-policy-check.py')],
|
||||
capture_output=True, text=True)
|
||||
capture_output=True, text=True, env=dict(os.environ, KUSTOMIZE=KUSTOMIZE))
|
||||
return result.returncode, result.stdout + result.stderr
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
# M9.8f review: pinned kustomize for rendered deployment-policy checks (ADR-0088).
|
||||
# tools/ci/prepare-kustomize.sh [install-dir] (default .cache/tools/kustomize-<version>)
|
||||
# Explicit preparation only: downloads the official Linux amd64 release archive,
|
||||
# verifies the pinned SHA-256 and installs the single binary. Idempotent.
|
||||
set -euo pipefail
|
||||
version=v5.8.1
|
||||
sha256=029a7f0f4e1932c52a0476cf02a0fd855c0bb85694b82c338fc648dcb53a819d
|
||||
root="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
target="${1:-$root/.cache/tools/kustomize-$version}"
|
||||
if [ -x "$target/kustomize" ] && "$target/kustomize" version | grep -qx "$version"; then
|
||||
echo "kustomize $version: $target/kustomize"
|
||||
exit 0
|
||||
fi
|
||||
case "$(uname -s)/$(uname -m)" in
|
||||
Linux/x86_64) ;;
|
||||
*) echo "prepare-kustomize: only Linux x86_64 is pinned (got $(uname -s)/$(uname -m))" >&2; exit 2 ;;
|
||||
esac
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
archive="kustomize_${version}_linux_amd64.tar.gz"
|
||||
curl -fsSL --retry 3 -o "$work/$archive" \
|
||||
"https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$version/$archive"
|
||||
echo "$sha256 $work/$archive" | sha256sum -c --quiet -
|
||||
tar -xzf "$work/$archive" -C "$work" kustomize
|
||||
mkdir -p "$target"
|
||||
install -m 0755 "$work/kustomize" "$target/kustomize"
|
||||
"$target/kustomize" version | grep -qx "$version"
|
||||
echo "kustomize $version: $target/kustomize"
|
||||
Reference in New Issue
Block a user