Skip to content

Commit 7d2eb30

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

File tree

4 files changed

+143
-15
lines changed

4 files changed

+143
-15
lines changed

api/internal/builtins/HelmChartInflationGenerator.go

Lines changed: 11 additions & 7 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) {

go.work.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8
33
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
44
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
55
github.com/dustmop/soup v1.1.2-0.20190516214245-38228baa104e/go.mod h1:CgNC6SGbT+Xb8wGGvzilttZL1mc5sQ/5KkcxsZttMIk=
6+
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
67
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
78
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
89
github.com/go-openapi/spec v0.19.3 h1:0XRyw8kguri6Yw4SxhsQA/atC88yqrk0+G4YhI2wabc=
@@ -68,7 +69,6 @@ sigs.k8s.io/kustomize/api v0.8.9/go.mod h1:OTaWCS8krICmepGNRxSdhOuywXAl7AieML4y2
6869
sigs.k8s.io/kustomize/api v0.11.4/go.mod h1:k+8RsqYbgpkIrJ4p9jcdPqe8DprLxFUUO0yNOq8C+xI=
6970
sigs.k8s.io/kustomize/cmd/config v0.10.7/go.mod h1:ZTbW6xLlf2ohaOzyWbaRj+fxLbSRjsExCfXGijY4Xt4=
7071
sigs.k8s.io/kustomize/cmd/config v0.11.0/go.mod h1:vsC4WPJub39YAH1aMeuU5dzCwe2zY6EbEKDo0PddiIc=
71-
sigs.k8s.io/kustomize/cmd/config v0.11.2/go.mod h1:PCpHxyu10daTnbMfn3xhH1vppn7L8jsS3qpRKXb7Lkc=
7272
sigs.k8s.io/kustomize/kyaml v0.7.1/go.mod h1:ne3F9JPhW2wrVaLslxBsEe6MQJQ9YK5rUutrdhBWXwI=
7373
sigs.k8s.io/kustomize/kyaml v0.10.18/go.mod h1:h94DSoDbmnN4BTc6VTX7tGNGXZy29rbPo+R4jGMvA8U=
7474
sigs.k8s.io/kustomize/kyaml v0.13.6/go.mod h1:yHP031rn1QX1lr/Xd934Ri/xdVNG8BE2ECa78Ht/kEg=

plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) {
238238
return nil, err
239239
}
240240
if path, exists := p.chartExistsLocally(); !exists {
241-
if p.Repo == "" {
242-
return nil, fmt.Errorf(
243-
"no repo specified for pull, no chart found at '%s'", path)
244-
}
245241
if _, err := p.runHelmCommand(p.pullCommand()); err != nil {
246-
return nil, err
242+
return nil, fmt.Errorf("no chart found at '%s' and helm pull errored with: %v", path, err)
247243
}
248244
}
249245
if len(p.ValuesInline) > 0 {
@@ -287,8 +283,16 @@ func (p *plugin) pullCommand() []string {
287283
"pull",
288284
"--untar",
289285
"--untardir", p.absChartHome(),
290-
"--repo", p.Repo,
291-
p.Name}
286+
}
287+
if p.Repo != "" {
288+
if strings.Contains(p.Repo, "oci://") {
289+
args = append(args, fmt.Sprintf("%s/%s", strings.TrimRight(p.Repo, "/"), p.Name))
290+
} else {
291+
args = append(args, "--repo", p.Repo)
292+
}
293+
} else {
294+
args = append(args, p.Name)
295+
}
292296
if p.Version != "" {
293297
args = append(args, "--version", p.Version)
294298
}

0 commit comments

Comments
 (0)