Skip to content

Commit 30c6604

Browse files
author
nikimanoledaki
committed
Add validation that HelmRepository is not nil when discovering through Get Profile
1 parent aaaa875 commit 30c6604

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pkg/services/profiles/add.go

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func (s *ProfilesSvc) Add(ctx context.Context, gitProvider gitproviders.GitProvi
6060
if err != nil {
6161
return err
6262
}
63+
if availableProfile.HelmRepository == nil || availableProfile.HelmRepository.Name == "" || availableProfile.HelmRepository.Namespace == "" {
64+
return fmt.Errorf("failed to discover HelmRepository's name and namespace")
65+
}
6366

6467
newRelease := helm.MakeHelmRelease(availableProfile, opts.Cluster, opts.Namespace)
6568

pkg/services/profiles/add_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ var _ = Describe("Add", func() {
134134
Expect(err).To(MatchError("failed to make GET request to service weave-system/wego-app path \"/v1/profiles\": nope"))
135135
})
136136

137+
It("fails if it's unable to discover the HelmRepository's name and namespace values", func() {
138+
gitProviders.RepositoryExistsReturns(true, nil)
139+
gitProviders.GetRepoFilesReturns(makeTestFiles(), nil)
140+
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
141+
return true, newFakeResponseWrapper(getRespWithoutHelmRepo()), nil
142+
})
143+
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
144+
Expect(err).NotTo(BeNil())
145+
Expect(err).To(MatchError("failed to discover HelmRepository's name and namespace"))
146+
})
147+
137148
It("fails if the config repo's filesystem could not be fetched", func() {
138149
gitProviders.RepositoryExistsReturns(true, nil)
139150
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
@@ -298,3 +309,34 @@ func makeTestFiles() []*gitprovider.CommitFile {
298309
}
299310
return commitFiles
300311
}
312+
313+
func getRespWithoutHelmRepo() string {
314+
return `{
315+
"profiles": [
316+
{
317+
"name": "podinfo",
318+
"home": "https://github.com/stefanprodan/podinfo",
319+
"sources": [
320+
"https://github.com/stefanprodan/podinfo"
321+
],
322+
"description": "Podinfo Helm chart for Kubernetes",
323+
"keywords": [],
324+
"maintainers": [
325+
{
326+
"name": "stefanprodan",
327+
"email": "[email protected]",
328+
"url": ""
329+
}
330+
],
331+
"icon": "",
332+
"annotations": {},
333+
"kubeVersion": ">=1.19.0-0",
334+
"availableVersions": [
335+
"6.0.0",
336+
"6.0.1"
337+
]
338+
}
339+
]
340+
}
341+
`
342+
}

0 commit comments

Comments
 (0)