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
7edce9b8
Commit
7edce9b8
authored
May 11, 2016
by
vaikas-google
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate Chart.yaml version for semver, validate that values.toml parses if present
parent
62cb6ce4
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
138 additions
and
3 deletions
+138
-3
chartfile.go
pkg/chart/chartfile.go
+11
-1
chartfile_test.go
pkg/chart/chartfile_test.go
+18
-0
Chart.yaml
pkg/chart/testdata/badchartversion/Chart.yaml
+13
-0
chartfile.go
pkg/lint/chartfile.go
+1
-1
lint.go
pkg/lint/lint.go
+1
-0
lint_test.go
pkg/lint/lint_test.go
+57
-0
message.go
pkg/lint/message.go
+3
-1
message_test.go
pkg/lint/message_test.go
+5
-0
Chart.yaml
pkg/lint/testdata/goodone/Chart.yaml
+3
-0
goodone.yaml
pkg/lint/testdata/goodone/templates/goodone.yaml
+2
-0
values.toml
pkg/lint/testdata/goodone/values.toml
+1
-0
values.go
pkg/lint/values.go
+23
-0
No files found.
pkg/chart/chartfile.go
View file @
7edce9b8
...
@@ -19,6 +19,7 @@ package chart
...
@@ -19,6 +19,7 @@ package chart
import
(
import
(
"io/ioutil"
"io/ioutil"
"github.com/Masterminds/semver"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)
)
...
@@ -46,7 +47,16 @@ func LoadChartfile(filename string) (*Chartfile, error) {
...
@@ -46,7 +47,16 @@ func LoadChartfile(filename string) (*Chartfile, error) {
return
nil
,
err
return
nil
,
err
}
}
var
y
Chartfile
var
y
Chartfile
return
&
y
,
yaml
.
Unmarshal
(
b
,
&
y
)
err
=
yaml
.
Unmarshal
(
b
,
&
y
)
if
err
!=
nil
{
return
nil
,
err
}
// Validate that the Version is actually a valid semver version
_
,
err
=
semver
.
NewVersion
(
y
.
Version
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
y
,
nil
}
}
// Save saves a Chart.yaml file
// Save saves a Chart.yaml file
...
...
pkg/chart/chartfile_test.go
View file @
7edce9b8
...
@@ -20,6 +20,8 @@ import (
...
@@ -20,6 +20,8 @@ import (
"testing"
"testing"
)
)
const
badChart
=
"testdata/badchartversion/Chart.yaml"
func
TestLoadChartfile
(
t
*
testing
.
T
)
{
func
TestLoadChartfile
(
t
*
testing
.
T
)
{
f
,
err
:=
LoadChartfile
(
testfile
)
f
,
err
:=
LoadChartfile
(
testfile
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -39,3 +41,19 @@ func TestLoadChartfile(t *testing.T) {
...
@@ -39,3 +41,19 @@ func TestLoadChartfile(t *testing.T) {
t
.
Errorf
(
"Expected https://example.com/foo/bar, got %s"
,
f
.
Source
)
t
.
Errorf
(
"Expected https://example.com/foo/bar, got %s"
,
f
.
Source
)
}
}
}
}
func
TestLoadChartfileFailsWithInvalidVersion
(
t
*
testing
.
T
)
{
f
,
err
:=
LoadChartfile
(
badChart
)
if
err
==
nil
{
t
.
Errorf
(
"LoadChartFile didn't fail with invalid version"
)
return
}
if
err
.
Error
()
!=
"Invalid Semantic Version"
{
t
.
Errorf
(
"LoadChartFile didn't return the expected error"
)
return
}
if
f
!=
nil
{
t
.
Errorf
(
"LoadChartFile returned a chart despite error"
)
return
}
}
pkg/chart/testdata/badchartversion/Chart.yaml
0 → 100644
View file @
7edce9b8
name
:
frobnitz
description
:
This is a frobniz.
version
:
"
garbage"
keywords
:
-
bad bad chart file
maintainers
:
-
name
:
The Helm Team
email
:
helm@example.com
-
name
:
Someone Else
email
:
nobody@example.com
source
:
-
https://example.com/foo/bar
home
:
http://example.com
pkg/lint/chartfile.go
View file @
7edce9b8
...
@@ -13,7 +13,7 @@ func Chartfile(basepath string) (m []Message) {
...
@@ -13,7 +13,7 @@ func Chartfile(basepath string) (m []Message) {
path
:=
filepath
.
Join
(
basepath
,
"Chart.yaml"
)
path
:=
filepath
.
Join
(
basepath
,
"Chart.yaml"
)
if
fi
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
if
fi
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
m
=
append
(
m
,
Message
{
Severity
:
ErrorSev
,
Text
:
"
No Chart.yaml file
"
})
m
=
append
(
m
,
Message
{
Severity
:
ErrorSev
,
Text
:
"
Chart.yaml file: "
+
path
+
" does not exist
"
})
return
return
}
else
if
fi
.
IsDir
()
{
}
else
if
fi
.
IsDir
()
{
m
=
append
(
m
,
Message
{
Severity
:
ErrorSev
,
Text
:
"Chart.yaml is a directory."
})
m
=
append
(
m
,
Message
{
Severity
:
ErrorSev
,
Text
:
"Chart.yaml is a directory."
})
...
...
pkg/lint/lint.go
View file @
7edce9b8
...
@@ -4,5 +4,6 @@ package lint
...
@@ -4,5 +4,6 @@ package lint
func
All
(
basedir
string
)
[]
Message
{
func
All
(
basedir
string
)
[]
Message
{
out
:=
Chartfile
(
basedir
)
out
:=
Chartfile
(
basedir
)
out
=
append
(
out
,
Templates
(
basedir
)
...
)
out
=
append
(
out
,
Templates
(
basedir
)
...
)
out
=
append
(
out
,
Values
(
basedir
)
...
)
return
out
return
out
}
}
pkg/lint/lint_test.go
0 → 100644
View file @
7edce9b8
package
lint
import
(
"strings"
"testing"
)
const
badChartDir
=
"testdata/badchartversion"
const
badYamlFileDir
=
"testdata/albatross"
const
goodChartDir
=
"testdata/goodone"
func
TestBadChart
(
t
*
testing
.
T
)
{
m
:=
All
(
badChartDir
)
if
len
(
m
)
!=
3
{
t
.
Errorf
(
"All didn't fail with expected errors, got %#v"
,
m
)
}
// There should be INFO, WARNING and ERROR messages, check for them
var
i
,
w
,
e
=
false
,
false
,
false
for
_
,
msg
:=
range
m
{
if
msg
.
Severity
==
InfoSev
{
if
strings
.
Contains
(
msg
.
Text
,
"values.toml"
)
{
i
=
true
}
}
if
msg
.
Severity
==
WarningSev
{
if
strings
.
Contains
(
msg
.
Text
,
"No templates"
)
{
w
=
true
}
}
if
msg
.
Severity
==
ErrorSev
{
if
strings
.
Contains
(
msg
.
Text
,
"Chart.yaml does not exist"
)
{
e
=
true
}
}
}
if
!
i
||
!
w
||
!
e
{
t
.
Errorf
(
"Didn't find all the expected errors, got %#v"
,
m
)
}
}
func
TestInvalidYaml
(
t
*
testing
.
T
)
{
m
:=
All
(
badYamlFileDir
)
if
len
(
m
)
!=
1
{
t
.
Errorf
(
"All didn't fail with expected errors"
)
}
if
!
strings
.
Contains
(
m
[
0
]
.
Text
,
"deliberateSyntaxError"
)
{
t
.
Errorf
(
"All didn't have the error for deliberateSyntaxError"
)
}
}
func
TestGoodChart
(
t
*
testing
.
T
)
{
m
:=
All
(
goodChartDir
)
if
len
(
m
)
!=
0
{
t
.
Errorf
(
"All failed but shouldn't have: %#v"
,
m
)
}
}
pkg/lint/message.go
View file @
7edce9b8
...
@@ -8,6 +8,8 @@ type Severity int
...
@@ -8,6 +8,8 @@ type Severity int
const
(
const
(
// UnknownSev indicates that the severity of the error is unknown, and should not stop processing.
// UnknownSev indicates that the severity of the error is unknown, and should not stop processing.
UnknownSev
=
iota
UnknownSev
=
iota
// InfoSev indicates information, for example missing values.toml file
InfoSev
// WarningSev indicates that something does not meet code standards, but will likely function.
// WarningSev indicates that something does not meet code standards, but will likely function.
WarningSev
WarningSev
// ErrorSev indicates that something will not likely function.
// ErrorSev indicates that something will not likely function.
...
@@ -15,7 +17,7 @@ const (
...
@@ -15,7 +17,7 @@ const (
)
)
// sev matches the *Sev states.
// sev matches the *Sev states.
var
sev
=
[]
string
{
"INFO"
,
"WARNING"
,
"ERROR"
}
var
sev
=
[]
string
{
"
UNKNOWN"
,
"
INFO"
,
"WARNING"
,
"ERROR"
}
// Message is a linting output message
// Message is a linting output message
type
Message
struct
{
type
Message
struct
{
...
...
pkg/lint/message_test.go
View file @
7edce9b8
...
@@ -17,4 +17,9 @@ func TestMessage(t *testing.T) {
...
@@ -17,4 +17,9 @@ func TestMessage(t *testing.T) {
if
m
.
String
()
!=
"[WARNING] Bar"
{
if
m
.
String
()
!=
"[WARNING] Bar"
{
t
.
Errorf
(
"Unexpected output: %s"
,
m
.
String
())
t
.
Errorf
(
"Unexpected output: %s"
,
m
.
String
())
}
}
m
=
Message
{
InfoSev
,
"FooBar"
}
if
m
.
String
()
!=
"[INFO] FooBar"
{
t
.
Errorf
(
"Unexpected output: %s"
,
m
.
String
())
}
}
}
pkg/lint/testdata/goodone/Chart.yaml
0 → 100644
View file @
7edce9b8
name
:
goodone
description
:
good testing chart
version
:
199.44.12345-Alpha.1+cafe009
pkg/lint/testdata/goodone/templates/goodone.yaml
0 → 100644
View file @
7edce9b8
metadata
:
name
:
{{
.name | default "foo" | title
}}
pkg/lint/testdata/goodone/values.toml
0 → 100644
View file @
7edce9b8
name
=
"goodone here"
pkg/lint/values.go
0 → 100644
View file @
7edce9b8
package
lint
import
(
"os"
"github.com/kubernetes/helm/pkg/chart"
"path/filepath"
)
// Values lints a chart's values.toml file.
func
Values
(
basepath
string
)
(
messages
[]
Message
)
{
vf
:=
filepath
.
Join
(
basepath
,
"values.toml"
)
messages
=
[]
Message
{}
if
_
,
err
:=
os
.
Stat
(
vf
);
err
!=
nil
{
messages
=
append
(
messages
,
Message
{
Severity
:
InfoSev
,
Text
:
"No values.toml file"
})
return
}
_
,
err
:=
chart
.
ReadValuesFile
(
vf
)
if
err
!=
nil
{
messages
=
append
(
messages
,
Message
{
Severity
:
ErrorSev
,
Text
:
err
.
Error
()})
}
return
messages
}
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