Skip to content

Commit efc4bd5

Browse files
committed
helm charts script for cert-manager
Signed-off-by: kunal-511 <[email protected]>
1 parent df79a5e commit efc4bd5

File tree

8 files changed

+259
-52
lines changed

8 files changed

+259
-52
lines changed
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
name: Verify Helm vs Kustomize Manifests
2+
23
on:
34
pull_request:
45
paths:
56
- tests/install_KinD_create_KinD_cluster_install_kustomize.sh
7+
- tests/helm_install.sh
68
- .github/workflows/helm_vs_kustomize_verification.yaml
79
- apps/spark/spark-operator/**
10+
- common/cert-manager/**
811
- experimental/helm/kubeflow/**
912
- experimental/helm/scripts/**
10-
- scripts/synchronize-spark-operator-manifests.sh
11-
- scripts/synchronize-spark-operator-helm-chart.sh
1213
- tests/helm_kustomize_compare_manifests.sh
1314
- tests/helm_kustomize_compare_manifests.py
1415

1516
jobs:
16-
verify-spark-operator:
17+
verify-components:
1718
runs-on: ubuntu-latest
18-
timeout-minutes: 10
19+
timeout-minutes: 15
20+
strategy:
21+
matrix:
22+
component: [spark-operator, cert-manager]
23+
fail-fast: false
24+
1925
steps:
2026
- name: Checkout
2127
uses: actions/checkout@v4
@@ -30,17 +36,16 @@ jobs:
3036
chmod +x tests/helm_install.sh
3137
./tests/helm_install.sh
3238
33-
- name: Run Helm vs Kustomize verification for Spark Operator
39+
- name: Run Helm vs Kustomize verification for ${{ matrix.component }}
3440
run: |
3541
chmod +x tests/helm_kustomize_compare_manifests.sh
36-
./tests/helm_kustomize_compare_manifests.sh spark-operator
42+
./tests/helm_kustomize_compare_manifests.sh ${{ matrix.component }}
3743
3844
- name: Upload artifacts on failure
3945
if: failure()
4046
uses: actions/upload-artifact@v4
4147
with:
42-
name: spark-operator-manifest-comparison-artifacts
48+
name: ${{ matrix.component }}-manifest-comparison-artifacts
4349
path: |
44-
/tmp/kustomize-spark-operator.yaml
45-
/tmp/helm-spark-operator.yaml
46-
50+
/tmp/kustomize-${{ matrix.component }}.yaml
51+
/tmp/helm-aio-${{ matrix.component }}.yaml

experimental/helm/kubeflow/values.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ trainingOperator:
2525
# Will be added when we sync training-operator
2626

2727
certManager:
28-
enabled: false
29-
# Will be added when we sync cert-manager
28+
enabled: true
29+
installCRDs: true
30+
global:
31+
leaderElection:
32+
namespace: kube-system
33+
startupapicheck:
34+
enabled: false
35+
# Kubeflow-specific settings
36+
kubeflowIssuer:
37+
enabled: true
38+
name: kubeflow-self-signing-issuer
3039

3140
istio:
3241
enabled: false

experimental/helm/scripts/patch-templates.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
import os
55
from pathlib import Path
66

7-
def patch_yaml_file(file_path):
8-
"""Patch a YAML file to add namespace and Istio labels"""
7+
def patch_yaml_file(file_path, component):
8+
"""Patch a YAML file to add conditional rendering and namespace"""
99
with open(file_path, 'r') as f:
1010
content = f.read()
1111

12-
if '{{- if .Values.sparkOperator.enabled }}' in content:
12+
component_map = {
13+
'spark-operator': 'sparkOperator.enabled',
14+
'cert-manager': 'certManager.enabled',
15+
}
16+
17+
condition = component_map.get(component, f'{component}.enabled')
18+
condition_check = f'{{{{- if .Values.{condition} }}}}'
19+
20+
if condition_check in content:
1321
return
1422

1523
try:
@@ -21,9 +29,16 @@ def patch_yaml_file(file_path):
2129
if 'metadata' in doc and doc.get('kind') in [
2230
'Deployment', 'Service', 'ServiceAccount', 'Role', 'RoleBinding'
2331
]:
24-
doc['metadata']['namespace'] = '{{ include "kubeflow.namespace" . }}'
32+
if not isinstance(doc['metadata'].get('namespace'), str) or '{{' not in doc['metadata'].get('namespace', ''):
33+
if component == 'cert-manager':
34+
if doc.get('kind') in ['Role', 'RoleBinding'] and 'leaderelection' in doc['metadata'].get('name', ''):
35+
doc['metadata']['namespace'] = 'kube-system'
36+
else:
37+
doc['metadata']['namespace'] = '{{ .Values.global.certManagerNamespace }}'
38+
else:
39+
doc['metadata']['namespace'] = '{{ include "kubeflow.namespace" . }}'
2540

26-
if doc.get('kind') == 'Deployment' and 'spec' in doc:
41+
if doc.get('kind') == 'Deployment' and 'spec' in doc and component == 'spark-operator':
2742
if 'template' in doc['spec'] and 'metadata' in doc['spec']['template']:
2843
template_meta = doc['spec']['template']['metadata']
2944
if 'labels' not in template_meta:
@@ -33,7 +48,7 @@ def patch_yaml_file(file_path):
3348
patched_docs.append(doc)
3449

3550
with open(file_path, 'w') as f:
36-
f.write('{{- if .Values.sparkOperator.enabled }}\n')
51+
f.write(f'{condition_check}\n')
3752
for doc in patched_docs:
3853
f.write('---\n')
3954
yaml.dump(doc, f, default_flow_style=False, sort_keys=False)
@@ -42,11 +57,16 @@ def patch_yaml_file(file_path):
4257
except Exception as e:
4358
print(f"Warning: Could not patch {file_path}: {e}")
4459
with open(file_path, 'w') as f:
45-
f.write('{{- if .Values.sparkOperator.enabled }}\n')
60+
f.write(f'{condition_check}\n')
4661
f.write(content)
4762
f.write('{{- end }}\n')
4863

4964
if __name__ == "__main__":
65+
if len(sys.argv) < 3:
66+
print("Usage: patch-templates.py <templates_dir> <component>")
67+
sys.exit(1)
68+
5069
templates_dir = sys.argv[1]
70+
component = sys.argv[2]
5171
for yaml_file in Path(templates_dir).rglob("*.yaml"):
52-
patch_yaml_file(str(yaml_file))
72+
patch_yaml_file(str(yaml_file), component)

experimental/helm/scripts/synchronize-all-charts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ CHART_DIR="$HELM_DIR/kubeflow"
99

1010
COMPONENTS=(
1111
"spark-operator"
12+
"cert-manager"
1213
# Add more components as we implement them
1314
# "training-operator"
14-
# "cert-manager"
1515
# "istio"
1616
# "oauth2-proxy"
1717
# "dex"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
# Script to sync Cert Manager templates for AIO Helm chart
3+
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
HELM_DIR="$(dirname "$SCRIPT_DIR")"
8+
CHART_DIR="$HELM_DIR/kubeflow"
9+
10+
COMPONENT="cert-manager"
11+
VERSION="v1.16.1"
12+
REPO="https://charts.jetstack.io"
13+
TEMPLATES_DIR="$CHART_DIR/templates/external/${COMPONENT}"
14+
NAMESPACE="cert-manager"
15+
16+
rm -rf "$TEMPLATES_DIR"
17+
mkdir -p "$TEMPLATES_DIR"
18+
19+
TEMP_DIR=$(mktemp -d)
20+
cd "$TEMP_DIR"
21+
22+
# Generate templates using same settings as existing Kustomize setup
23+
# Disable startupapicheck to match Kustomize manifests that don't include it
24+
helm template "$COMPONENT" "$COMPONENT" \
25+
--version "$VERSION" \
26+
--repo "$REPO" \
27+
--namespace "$NAMESPACE" \
28+
--include-crds \
29+
--set installCRDs=true \
30+
--set global.leaderElection.namespace="kube-system" \
31+
--set startupapicheck.enabled=false \
32+
--output-dir .
33+
34+
cp -r "$COMPONENT/templates/"* "$TEMPLATES_DIR/"
35+
36+
[ -d "$COMPONENT/crds" ] && {
37+
mkdir -p "$TEMPLATES_DIR/crds"
38+
cp -r "$COMPONENT/crds/"* "$TEMPLATES_DIR/crds/"
39+
}
40+
41+
python3 "$SCRIPT_DIR/patch-templates.py" "$TEMPLATES_DIR" "$COMPONENT"
42+
43+
# Add namespace template since cert-manager chart doesn't include it
44+
cat > "$TEMPLATES_DIR/namespace.yaml" << 'EOF'
45+
{{- if .Values.certManager.enabled }}
46+
apiVersion: v1
47+
kind: Namespace
48+
metadata:
49+
name: {{ .Values.global.certManagerNamespace }}
50+
labels:
51+
pod-security.kubernetes.io/enforce: restricted
52+
{{- end }}
53+
EOF
54+
55+
# Create kubeflow-issuer template
56+
mkdir -p "$TEMPLATES_DIR/kubeflow-issuer"
57+
cat > "$TEMPLATES_DIR/kubeflow-issuer/cluster-issuer.yaml" << 'EOF'
58+
{{- if .Values.certManager.enabled }}
59+
apiVersion: cert-manager.io/v1
60+
kind: ClusterIssuer
61+
metadata:
62+
name: kubeflow-self-signing-issuer
63+
labels:
64+
{{- include "kubeflow.labels" . | nindent 4 }}
65+
app.kubernetes.io/component: cert-manager
66+
app.kubernetes.io/name: cert-manager
67+
kustomize.component: cert-manager
68+
spec:
69+
selfSigned: {}
70+
{{- end }}
71+
EOF
72+
73+
cd "$CHART_DIR"
74+
rm -rf "$TEMP_DIR"
75+
76+
helm template kubeflow . --debug --dry-run > /dev/null
77+
78+
echo "Cert Manager templates synchronized successfully"

experimental/helm/scripts/synchronize-spark-operator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cp -r "$COMPONENT/templates/"* "$TEMPLATES_DIR/"
3737
cp -r "$COMPONENT/crds/"* "$TEMPLATES_DIR/crds/"
3838
}
3939

40-
python3 "$SCRIPT_DIR/patch-templates.py" "$TEMPLATES_DIR"
40+
python3 "$SCRIPT_DIR/patch-templates.py" "$TEMPLATES_DIR" "$COMPONENT"
4141

4242
cd "$CHART_DIR"
4343
rm -rf "$TEMP_DIR"

tests/helm_kustomize_compare_manifests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def clean_helm_metadata(obj):
1313
labels = metadata['labels']
1414
helm_specific_labels = [
1515
'helm.sh/chart',
16-
'app.kubernetes.io/managed-by'
16+
'app.kubernetes.io/managed-by',
17+
'app.kubernetes.io/instance',
18+
'app.kubernetes.io/version'
1719
]
1820
for label in helm_specific_labels:
1921
if label in labels:

0 commit comments

Comments
 (0)