Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
893c3b61
Commit
893c3b61
authored
Jan 10, 2019
by
Axel Köhler
Committed by
Matthew Fisher
Jan 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add chart name check to lint (#3773)
Signed-off-by:
Axel Köhler
<
koehler.ax3l@gmail.com
>
parent
8015fc35
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
5 deletions
+30
-5
.gitignore
.gitignore
+2
-0
chartfile.go
pkg/lint/rules/chartfile.go
+10
-2
chartfile_test.go
pkg/lint/rules/chartfile_test.go
+13
-3
Chart.yaml
pkg/lint/rules/testdata/badnamechart/Chart.yaml
+4
-0
values.yaml
pkg/lint/rules/testdata/badnamechart/values.yaml
+1
-0
No files found.
.gitignore
View file @
893c3b61
...
...
@@ -11,3 +11,4 @@ rootfs/rudder
vendor/
*.exe
.idea/
*.iml
\ No newline at end of file
pkg/lint/rules/chartfile.go
View file @
893c3b61
...
...
@@ -46,7 +46,8 @@ func Chartfile(linter *support.Linter) {
return
}
linter
.
RunLinterRule
(
support
.
ErrorSev
,
chartFileName
,
validateChartName
(
chartFile
))
linter
.
RunLinterRule
(
support
.
ErrorSev
,
chartFileName
,
validateChartNamePresence
(
chartFile
))
linter
.
RunLinterRule
(
support
.
WarningSev
,
chartFileName
,
validateChartNameFormat
(
chartFile
))
linter
.
RunLinterRule
(
support
.
ErrorSev
,
chartFileName
,
validateChartNameDirMatch
(
linter
.
ChartDir
,
chartFile
))
// Chart metadata
...
...
@@ -74,13 +75,20 @@ func validateChartYamlFormat(chartFileError error) error {
return
nil
}
func
validateChartName
(
cf
*
chart
.
Metadata
)
error
{
func
validateChartName
Presence
(
cf
*
chart
.
Metadata
)
error
{
if
cf
.
Name
==
""
{
return
errors
.
New
(
"name is required"
)
}
return
nil
}
func
validateChartNameFormat
(
cf
*
chart
.
Metadata
)
error
{
if
strings
.
Contains
(
cf
.
Name
,
"."
)
{
return
errors
.
New
(
"name should be lower case letters and numbers. Words may be separated with dashes"
)
}
return
nil
}
func
validateChartNameDirMatch
(
chartDir
string
,
cf
*
chart
.
Metadata
)
error
{
if
cf
.
Name
!=
filepath
.
Base
(
chartDir
)
{
return
fmt
.
Errorf
(
"directory name (%s) and chart name (%s) must be the same"
,
filepath
.
Base
(
chartDir
),
cf
.
Name
)
...
...
pkg/lint/rules/chartfile_test.go
View file @
893c3b61
...
...
@@ -29,17 +29,20 @@ import (
)
const
(
badChartDir
=
"testdata/badchartfile"
goodChartDir
=
"testdata/goodone"
badChartDir
=
"testdata/badchartfile"
badNameChartDir
=
"testdata/badnamechart"
goodChartDir
=
"testdata/goodone"
)
var
(
badChartFilePath
=
filepath
.
Join
(
badChartDir
,
"Chart.yaml"
)
badNameChartFilePath
=
filepath
.
Join
(
badNameChartDir
,
"Chart.yaml"
)
goodChartFilePath
=
filepath
.
Join
(
goodChartDir
,
"Chart.yaml"
)
nonExistingChartFilePath
=
filepath
.
Join
(
os
.
TempDir
(),
"Chart.yaml"
)
)
var
badChart
,
chatLoadRrr
=
chartutil
.
LoadChartfile
(
badChartFilePath
)
var
badNameChart
,
_
=
chartutil
.
LoadChartfile
(
badNameChartFilePath
)
var
goodChart
,
_
=
chartutil
.
LoadChartfile
(
goodChartFilePath
)
// Validation functions Test
...
...
@@ -66,12 +69,19 @@ func TestValidateChartYamlFormat(t *testing.T) {
}
func
TestValidateChartName
(
t
*
testing
.
T
)
{
err
:=
validateChartName
(
badChart
)
err
:=
validateChartName
Presence
(
badChart
)
if
err
==
nil
{
t
.
Errorf
(
"validateChartName to return a linter error, got no error"
)
}
}
func
TestValidateChartNameFormat
(
t
*
testing
.
T
)
{
err
:=
validateChartNameFormat
(
badNameChart
)
if
err
==
nil
{
t
.
Errorf
(
"validateChartNameFormat to return a linter error, got no error"
)
}
}
func
TestValidateChartNameDirMatch
(
t
*
testing
.
T
)
{
err
:=
validateChartNameDirMatch
(
goodChartDir
,
goodChart
)
if
err
!=
nil
{
...
...
pkg/lint/rules/testdata/badnamechart/Chart.yaml
0 → 100644
View file @
893c3b61
name
:
bad.chart.name
description
:
A Helm chart for Kubernetes
version
:
0.1.0
icon
:
http://riverrun.io
pkg/lint/rules/testdata/badnamechart/values.yaml
0 → 100644
View file @
893c3b61
# Default values for badchartname.
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