Skip to content

Commit

Permalink
fix(*): resolve go linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreese committed Oct 10, 2016
1 parent 72dd427 commit f71230c
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 307 deletions.
2 changes: 1 addition & 1 deletion _proto/hapi/services/tiller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ service ReleaseService {
rpc GetReleaseStatus(GetReleaseStatusRequest) returns (GetReleaseStatusResponse) {
}

// GetReleaseContent retrieves the release content (chart + value) for the specifed release.
// GetReleaseContent retrieves the release content (chart + value) for the specified release.
rpc GetReleaseContent(GetReleaseContentRequest) returns (GetReleaseContentResponse) {
}

Expand Down
5 changes: 0 additions & 5 deletions cmd/helm/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ import (
"k8s.io/helm/pkg/chartutil"
)

const (
reqLock = "requirements.lock"
reqYaml = "requirements.yaml"
)

const dependencyDesc = `
Manage the dependencies of a chart.
Expand Down
4 changes: 0 additions & 4 deletions cmd/helm/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ Example usage:
$ helm repo add [NAME] [REPO_URL]
`

type repoCmd struct {
out io.Writer
}

func newRepoCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "repo [FLAGS] add|remove|list|index|update [ARGS]",
Expand Down
2 changes: 1 addition & 1 deletion cmd/helm/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (i *Index) All() []*Result {
// If regexp is true, the term is treated as a regular expression. Otherwise,
// term is treated as a literal string.
func (i *Index) Search(term string, threshold int, regexp bool) ([]*Result, error) {
if regexp == true {
if regexp {
return i.SearchRegexp(term, threshold)
}
return i.SearchLiteral(term, threshold), nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/tiller/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ kind: Job
metadata:
name: first
labels:
doesnt: matter
doesnot: matter
annotations:
"helm.sh/hook": pre-install
`,
Expand Down
7 changes: 0 additions & 7 deletions cmd/tiller/release_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"google.golang.org/grpc/metadata"

"github.com/ghodss/yaml"
"github.com/technosophos/moniker"
ctx "golang.org/x/net/context"
"k8s.io/kubernetes/pkg/api/unversioned"
Expand Down Expand Up @@ -702,12 +701,6 @@ func (s *releaseServer) renderResources(ch *chart.Chart, values chartutil.Values
return hooks, b, notes, nil
}

// validateYAML checks to see if YAML is well-formed.
func validateYAML(data string) error {
b := map[string]interface{}{}
return yaml.Unmarshal([]byte(data), b)
}

func (s *releaseServer) recordRelease(r *release.Release, reuse bool) {
if reuse {
if err := s.env.Releases.Update(r); err != nil {
Expand Down
9 changes: 4 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import:
version: 1.1.0
- package: github.com/technosophos/moniker
- package: github.com/golang/protobuf
version: 8616e8ee5e20a1704615e6c8d7afcdac06087a67
version: df1d3ca07d2d07bba352d5b73c4313b4e2a6203e
subpackages:
- proto
- ptypes/any
Expand Down
3 changes: 3 additions & 0 deletions pkg/chartutil/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ func TestCoalesceValues(t *testing.T) {
tvals := &chart.Config{Raw: testCoalesceValuesYaml}

v, err := CoalesceValues(c, tvals)
if err != nil {
t.Fatal(err)
}
j, _ := json.MarshalIndent(v, "", " ")
t.Logf("Coalesced Values: %s", string(j))

Expand Down
5 changes: 1 addition & 4 deletions pkg/ignore/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ func Parse(file io.Reader) (*Rules, error) {
return r, err
}
}
if err := s.Err(); err != nil {
return r, err
}
return r, nil
return r, s.Err()
}

// Len returns the number of patterns in this rule set.
Expand Down
7 changes: 2 additions & 5 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,8 @@ func updateResource(target *resource.Info, currentObj runtime.Object) error {

// send patch to server
helper := resource.NewHelper(target.Client, target.Mapping)
if _, err = helper.Patch(target.Namespace, target.Name, api.StrategicMergePatchType, patch); err != nil {
return err
}

return nil
_, err = helper.Patch(target.Namespace, target.Name, api.StrategicMergePatchType, patch)
return err
}

func watchUntilReady(info *resource.Info) error {
Expand Down
10 changes: 3 additions & 7 deletions pkg/lint/rules/chartfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func validateChartVersion(cf *chart.Metadata) error {
}

c, err := semver.NewConstraint("> 0")
if err != nil {
return err
}
valid, msg := c.Validate(version)

if !valid && len(msg) > 0 {
Expand Down Expand Up @@ -149,10 +152,3 @@ func validateChartSources(cf *chart.Metadata) error {
}
return nil
}

func validateChartHome(cf *chart.Metadata) error {
if cf.Home != "" && !govalidator.IsRequestURL(cf.Home) {
return fmt.Errorf("invalid home URL '%s'", cf.Home)
}
return nil
}
21 changes: 0 additions & 21 deletions pkg/lint/rules/chartfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,27 +194,6 @@ func TestValidateChartSources(t *testing.T) {
}
}

func TestValidateChartHome(t *testing.T) {
var failTest = []string{"RiverRun", "john@winterfell", "riverrun.io"}
var successTest = []string{"", "http://riverrun.io", "https://riverrun.io", "https://riverrun.io/blackfish"}

for _, test := range failTest {
badChart.Home = test
err := validateChartHome(badChart)
if err == nil || !strings.Contains(err.Error(), "invalid home URL") {
t.Errorf("validateChartHome(%s) to return \"invalid home URL\", got no error", test)
}
}

for _, test := range successTest {
badChart.Home = test
err := validateChartHome(badChart)
if err != nil {
t.Errorf("validateChartHome(%s) to return no error, got %s", test, err.Error())
}
}
}

func TestChartfile(t *testing.T) {
linter := support.Linter{ChartDir: badChartDir}
Chartfile(&linter)
Expand Down
29 changes: 1 addition & 28 deletions pkg/lint/rules/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/Masterminds/sprig"
Expand Down Expand Up @@ -121,32 +120,6 @@ func validateTemplatesDir(templatesPath string) error {
return nil
}

// Validates that go template tags include the quote pipelined function
// i.e {{ .Foo.bar }} -> {{ .Foo.bar | quote }}
// {{ .Foo.bar }}-{{ .Foo.baz }} -> "{{ .Foo.bar }}-{{ .Foo.baz }}"
func validateQuotes(templateContent string) error {
// {{ .Foo.bar }}
r, _ := regexp.Compile(`(?m)(:|-)\s+{{[\w|\.|\s|\']+}}\s*$`)
functions := r.FindAllString(templateContent, -1)

for _, str := range functions {
if match, _ := regexp.MatchString("quote", str); !match {
result := strings.Replace(str, "}}", " | quote }}", -1)
return fmt.Errorf("wrap substitution functions in quotes or use the sprig \"quote\" function: %s -> %s", str, result)
}
}

// {{ .Foo.bar }}-{{ .Foo.baz }} -> "{{ .Foo.bar }}-{{ .Foo.baz }}"
r, _ = regexp.Compile(`(?m)({{(\w|\.|\s|\')+}}(\s|-)*)+\s*$`)
functions = r.FindAllString(templateContent, -1)

for _, str := range functions {
result := strings.Replace(str, str, fmt.Sprintf("\"%s\"", str), -1)
return fmt.Errorf("wrap substitution functions in quotes: %s -> %s", str, result)
}
return nil
}

func validateAllowedExtension(fileName string) error {
ext := filepath.Ext(fileName)
validExtensions := []string{".yaml", ".tpl", ".txt"}
Expand Down Expand Up @@ -179,7 +152,7 @@ func validateNoMissingValues(templatesPath string, chartValues chartutil.Values,
var buf bytes.Buffer
var emptyValues []string

// 2 - Extract every function and execute them agains the loaded values
// 2 - Extract every function and execute them against the loaded values
// Supported {{ .Chart.Name }}, {{ .Chart.Name | quote }}
r, _ := regexp.Compile(`{{[\w|\.|\s|\|\"|\']+}}`)
functions := r.FindAllString(string(templateContent), -1)
Expand Down
32 changes: 0 additions & 32 deletions pkg/lint/rules/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,6 @@ func TestValidateAllowedExtension(t *testing.T) {
}
}

func TestValidateQuotes(t *testing.T) {
// add `| quote` lint error
var failTest = []string{"foo: {{.Release.Service }}", "foo: {{.Release.Service }}", "- {{.Release.Service }}", "foo: {{default 'Never' .restart_policy}}", "- {{.Release.Service }} "}

for _, test := range failTest {
err := validateQuotes(test)
if err == nil || !strings.Contains(err.Error(), "use the sprig \"quote\" function") {
t.Errorf("validateQuotes('%s') to return \"use the sprig \"quote\" function:\", got no error.", test)
}
}

var successTest = []string{"foo: {{.Release.Service | quote }}", "foo: {{.Release.Service | quote }}", "- {{.Release.Service | quote }}", "foo: {{default 'Never' .restart_policy | quote }}", "foo: \"{{ .Release.Service }}\"", "foo: \"{{ .Release.Service }} {{ .Foo.Bar }}\"", "foo: \"{{ default 'Never' .Release.Service }} {{ .Foo.Bar }}\"", "foo: {{.Release.Service | squote }}"}

for _, test := range successTest {
err := validateQuotes(test)
if err != nil {
t.Errorf("validateQuotes('%s') to return not error and got \"%s\"", test, err.Error())
}
}

// Surrounding quotes
failTest = []string{"foo: {{.Release.Service }}-{{ .Release.Bar }}", "foo: {{.Release.Service }} {{ .Release.Bar }}", "- {{.Release.Service }}-{{ .Release.Bar }}", "- {{.Release.Service }}-{{ .Release.Bar }} {{ .Release.Baz }}", "foo: {{.Release.Service | default }}-{{ .Release.Bar }}"}

for _, test := range failTest {
err := validateQuotes(test)
if err == nil || !strings.Contains(err.Error(), "wrap substitution functions in quotes") {
t.Errorf("validateQuotes('%s') to return \"wrap substitution functions in quotes\", got no error", test)
}
}

}

func TestTemplateParsing(t *testing.T) {
linter := support.Linter{ChartDir: templateTestBasedir}
Templates(&linter)
Expand Down
33 changes: 17 additions & 16 deletions pkg/proto/hapi/chart/chart.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/proto/hapi/chart/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 20 additions & 19 deletions pkg/proto/hapi/chart/metadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f71230c

Please sign in to comment.