Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Ijaz Ahmad
ksonnet
Commits
76929c8c
Unverified
Commit
76929c8c
authored
Jul 06, 2018
by
Bryan Liles
Committed by
GitHub
Jul 06, 2018
Browse files
Merge pull request #701 from bryanl/700-helm-hooks
Don't install helm charts with hooks
parents
c660e1ba
21aa21bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
pkg/registry/helm.go
pkg/registry/helm.go
+20
-0
pkg/registry/helm_test.go
pkg/registry/helm_test.go
+48
-0
No files found.
pkg/registry/helm.go
View file @
76929c8c
...
...
@@ -16,15 +16,18 @@
package
registry
import
(
"bytes"
"io/ioutil"
"net/url"
"path"
"path/filepath"
"strings"
"github.com/ksonnet/ksonnet/pkg/app"
"github.com/ksonnet/ksonnet/pkg/helm"
"github.com/ksonnet/ksonnet/pkg/parts"
"github.com/ksonnet/ksonnet/pkg/util/archive"
ksstrings
"github.com/ksonnet/ksonnet/pkg/util/strings"
"github.com/pkg/errors"
)
...
...
@@ -161,6 +164,11 @@ func (h *Helm) ResolveLibrary(partName string, partAlias string, version string,
name
:=
path
.
Join
(
chart
.
Name
,
"helm"
,
chart
.
Version
,
f
.
Name
)
if
containsHelmHook
(
name
,
b
)
{
// skip this file because it has a helm hook in it
return
nil
}
return
onFile
(
name
,
b
)
}
...
...
@@ -242,3 +250,15 @@ func (h *Helm) SetURI(uri string) error {
h
.
spec
.
URI
=
uri
return
nil
}
// containsHelmHook checks file contents for helm hooks. Helm hooks are denoted by
// `helm.sh/hook`.
func
containsHelmHook
(
name
string
,
b
[]
byte
)
bool
{
dir
:=
filepath
.
Dir
(
name
)
ext
:=
filepath
.
Ext
(
name
)
if
strings
.
Contains
(
dir
,
"templates"
)
&&
ksstrings
.
InSlice
(
ext
,
[]
string
{
".yaml"
,
".yml"
})
{
return
bytes
.
Contains
(
b
,
[]
byte
(
"helm.sh/hook"
))
}
return
false
}
pkg/registry/helm_test.go
View file @
76929c8c
...
...
@@ -333,6 +333,54 @@ func TestHelm_ValidateURI_invalid(t *testing.T) {
})
}
func
Test_containsHelmHook
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
name
string
path
string
b
[]
byte
expected
bool
}{
{
name
:
"contains helm hook"
,
path
:
"templates/file.yaml"
,
b
:
[]
byte
(
`"helm.sh/hook": test-success`
),
expected
:
true
,
},
{
name
:
"doesn't contain helm hook"
,
path
:
"templates/file.yaml"
,
b
:
[]
byte
(
`"other": test-success`
),
expected
:
false
,
},
{
name
:
"contains helm hook in directory under templates"
,
path
:
"templates/nested/file.yaml"
,
b
:
[]
byte
(
`"helm.sh/hook": test-success`
),
expected
:
true
,
},
{
name
:
"contains helm hook in directory"
,
path
:
"nested/file.yaml"
,
b
:
[]
byte
(
`"helm.sh/hook": test-success`
),
expected
:
false
,
},
{
name
:
"contains helm hook in directory under templates and not YAML"
,
path
:
"templates/file.txt"
,
b
:
[]
byte
(
`"helm.sh/hook": test-success`
),
expected
:
false
,
},
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
got
:=
containsHelmHook
(
tc
.
path
,
tc
.
b
)
assert
.
Equal
(
t
,
tc
.
expected
,
got
)
})
}
}
type
fakeHelmRepositoryClient
struct
{
entries
*
helm
.
Repository
entriesErr
error
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment