Skip to content

Commit

Permalink
Add validation that HelmRepository is not nil when discovering throug…
Browse files Browse the repository at this point in the history
…h Get Profile
  • Loading branch information
nikimanoledaki committed Jan 31, 2022
1 parent cd450d3 commit 728b4b8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/services/profiles/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (s *ProfilesSvc) Add(ctx context.Context, gitProvider gitproviders.GitProvi
if err != nil {
return err
}
if availableProfile.HelmRepository == nil || availableProfile.HelmRepository.Name == "" || availableProfile.HelmRepository.Namespace == "" {
return fmt.Errorf("failed to discover HelmRepository's name and namespace")
}

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

Expand Down
42 changes: 42 additions & 0 deletions pkg/services/profiles/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ var _ = Describe("Add", func() {
Expect(err).To(MatchError("failed to make GET request to service weave-system/wego-app path \"/v1/profiles\": nope"))
})

It("fails if it's unable to discover the HelmRepository's name and namespace values", func() {
gitProviders.RepositoryExistsReturns(true, nil)
gitProviders.GetRepoFilesReturns(makeTestFiles(), nil)
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
return true, newFakeResponseWrapper(getRespWithoutHelmRepo()), nil
})
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError("failed to discover HelmRepository's name and namespace"))
})

It("fails if the config repo's filesystem could not be fetched", func() {
gitProviders.RepositoryExistsReturns(true, nil)
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
Expand Down Expand Up @@ -298,3 +309,34 @@ func makeTestFiles() []*gitprovider.CommitFile {
}
return commitFiles
}

func getRespWithoutHelmRepo() string {
return `{
"profiles": [
{
"name": "podinfo",
"home": "https://github.com/stefanprodan/podinfo",
"sources": [
"https://github.com/stefanprodan/podinfo"
],
"description": "Podinfo Helm chart for Kubernetes",
"keywords": [],
"maintainers": [
{
"name": "stefanprodan",
"email": "[email protected]",
"url": ""
}
],
"icon": "",
"annotations": {},
"kubeVersion": ">=1.19.0-0",
"availableVersions": [
"6.0.0",
"6.0.1"
]
}
]
}
`
}

0 comments on commit 728b4b8

Please sign in to comment.