Skip to content

Commit b90d861

Browse files
committed
kustomize: Add support for OCI based helm repos
Signed-off-by: Jan-Otto Kröpke <[email protected]>
1 parent 9407e26 commit b90d861

File tree

3 files changed

+140
-4
lines changed

3 files changed

+140
-4
lines changed

api/internal/builtins/HelmChartInflationGenerator.go

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/krusty/helmchartinflationgenerator_test.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,97 @@ spec:
4646
type: ClusterIP
4747
`
4848

49+
const expectedHelmExternalDns = `
50+
apiVersion: apps/v1
51+
kind: Deployment
52+
metadata:
53+
labels:
54+
app.kubernetes.io/instance: test
55+
app.kubernetes.io/managed-by: Helm
56+
app.kubernetes.io/name: external-dns
57+
helm.sh/chart: external-dns-6.19.2
58+
name: test-external-dns
59+
namespace: default
60+
spec:
61+
replicas: 1
62+
selector:
63+
matchLabels:
64+
app.kubernetes.io/instance: test
65+
app.kubernetes.io/name: external-dns
66+
template:
67+
metadata:
68+
annotations: null
69+
labels:
70+
app.kubernetes.io/instance: test
71+
app.kubernetes.io/managed-by: Helm
72+
app.kubernetes.io/name: external-dns
73+
helm.sh/chart: external-dns-6.19.2
74+
spec:
75+
affinity:
76+
nodeAffinity: null
77+
podAffinity: null
78+
podAntiAffinity:
79+
preferredDuringSchedulingIgnoredDuringExecution:
80+
- podAffinityTerm:
81+
labelSelector:
82+
matchLabels:
83+
app.kubernetes.io/instance: test
84+
app.kubernetes.io/name: external-dns
85+
topologyKey: kubernetes.io/hostname
86+
weight: 1
87+
containers:
88+
- args:
89+
- --metrics-address=:7979
90+
- --log-level=info
91+
- --log-format=text
92+
- --policy=upsert-only
93+
- --provider=aws
94+
- --registry=txt
95+
- --interval=1m
96+
- --source=service
97+
- --source=ingress
98+
- --aws-api-retries=3
99+
- --aws-zone-type=
100+
- --aws-batch-change-size=1000
101+
env:
102+
- name: AWS_DEFAULT_REGION
103+
value: us-east-1
104+
envFrom: null
105+
image: docker.io/bitnami/external-dns:0.13.4-debian-11-r14
106+
imagePullPolicy: IfNotPresent
107+
livenessProbe:
108+
failureThreshold: 2
109+
httpGet:
110+
path: /healthz
111+
port: http
112+
initialDelaySeconds: 10
113+
periodSeconds: 10
114+
successThreshold: 1
115+
timeoutSeconds: 5
116+
name: external-dns
117+
ports:
118+
- containerPort: 7979
119+
name: http
120+
readinessProbe:
121+
failureThreshold: 6
122+
httpGet:
123+
path: /healthz
124+
port: http
125+
initialDelaySeconds: 5
126+
periodSeconds: 10
127+
successThreshold: 1
128+
timeoutSeconds: 5
129+
resources:
130+
limits: {}
131+
requests: {}
132+
volumeMounts: null
133+
securityContext:
134+
fsGroup: 1001
135+
runAsUser: 1001
136+
serviceAccountName: default
137+
volumes: null
138+
`
139+
49140
func TestHelmChartInflationGeneratorOld(t *testing.T) {
50141
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
51142
defer th.Reset()
@@ -84,6 +175,35 @@ helmCharts:
84175
th.AssertActualEqualsExpected(m, expectedHelm)
85176
}
86177

178+
func TestHelmChartInflationGeneratorWithOciRepository(t *testing.T) {
179+
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
180+
defer th.Reset()
181+
if err := th.ErrIfNoHelm(); err != nil {
182+
t.Skip("skipping: " + err.Error())
183+
}
184+
185+
th.WriteK(th.GetRoot(), `
186+
helmCharts:
187+
- name: external-dns
188+
repo: oci://registry-1.docker.io/bitnamicharts/
189+
version: 6.19.2
190+
releaseName: test
191+
valuesInline:
192+
crd:
193+
create: false
194+
rbac:
195+
create: false
196+
serviceAccount:
197+
create: false
198+
service:
199+
enabled: false
200+
201+
`)
202+
203+
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
204+
th.AssertActualEqualsExpected(m, expectedHelmExternalDns)
205+
}
206+
87207
// Last mile helm - show how kustomize puts helm charts into different
88208
// namespaces with different customizations.
89209
func TestHelmChartProdVsDev(t *testing.T) {

plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,16 @@ func (p *plugin) pullCommand() []string {
287287
"pull",
288288
"--untar",
289289
"--untardir", p.absChartHome(),
290-
"--repo", p.Repo,
291-
p.Name}
290+
}
291+
if p.Repo != "" {
292+
if strings.Contains(p.Repo, "oci://") {
293+
args = append(args, fmt.Sprintf("%s/%s", strings.TrimRight(p.Repo, "/"), p.Name))
294+
} else {
295+
args = append(args, "--repo", p.Repo)
296+
}
297+
} else {
298+
args = append(args, p.Name)
299+
}
292300
if p.Version != "" {
293301
args = append(args, "--version", p.Version)
294302
}

0 commit comments

Comments
 (0)