pull/2819/merge
Matthew Fisher 8 years ago committed by GitHub
commit 5da4e2d459

@ -17,7 +17,6 @@ limitations under the License.
package main
import (
"errors"
"fmt"
"io"
"io/ioutil"
@ -69,7 +68,7 @@ func newLintCmd(out io.Writer) *cobra.Command {
return cmd
}
var errLintNoChart = errors.New("No chart found for linting (missing Chart.yaml)")
var errLintNoChart = fmt.Errorf("No chart found for linting (missing %s)", chartutil.ChartfileName)
func (l *lintCmd) run() error {
var lowestTolerance int
@ -142,7 +141,7 @@ func lintChart(path string) (support.Linter, error) {
}
// Guard: Error out of this is not a chart.
if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil {
if _, err := os.Stat(filepath.Join(chartPath, chartutil.ChartfileName)); err != nil {
return linter, errLintNoChart
}

@ -140,7 +140,7 @@ func (p *packageCmd) run() error {
}
if filepath.Base(path) != ch.Metadata.Name {
return fmt.Errorf("directory name (%s) and Chart.yaml name (%s) must match", filepath.Base(path), ch.Metadata.Name)
return fmt.Errorf("directory name (%s) and %s name (%s) must match", filepath.Base(path), chartutil.ChartfileName, ch.Metadata.Name)
}
if reqs, err := chartutil.LoadRequirements(ch); err == nil {

@ -17,7 +17,6 @@ limitations under the License.
package chartutil
import (
"errors"
"fmt"
"io/ioutil"
"os"
@ -73,14 +72,14 @@ func IsChartDir(dirName string) (bool, error) {
return false, fmt.Errorf("%q is not a directory", dirName)
}
chartYaml := filepath.Join(dirName, "Chart.yaml")
chartYaml := filepath.Join(dirName, ChartfileName)
if _, err := os.Stat(chartYaml); os.IsNotExist(err) {
return false, fmt.Errorf("no Chart.yaml exists in directory %q", dirName)
return false, fmt.Errorf("no %s exists in directory %q", ChartfileName, dirName)
}
chartYamlContent, err := ioutil.ReadFile(chartYaml)
if err != nil {
return false, fmt.Errorf("cannot read Chart.Yaml in directory %q", dirName)
return false, fmt.Errorf("cannot read %s in directory %q", ChartfileName, dirName)
}
chartContent, err := UnmarshalChartfile(chartYamlContent)
@ -88,10 +87,10 @@ func IsChartDir(dirName string) (bool, error) {
return false, err
}
if chartContent == nil {
return false, errors.New("chart metadata (Chart.yaml) missing")
return false, ErrChartMetadataMissing
}
if chartContent.Name == "" {
return false, errors.New("invalid chart (Chart.yaml): name must not be empty")
return false, ErrChartNameEmpty
}
return true, nil

@ -0,0 +1,30 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package chartutil
import (
"fmt"
)
var (
// ErrChartMetadataMissing is raised when a Chart.yaml is missing from a chart.
ErrChartMetadataMissing = fmt.Errorf("chart metadata (%s) missing", ChartfileName)
// ErrChartNameEmpty is raised when a name is not specified in a Chart.yaml.
ErrChartNameEmpty = fmt.Errorf("invalid chart (%s): name must not be empty", ChartfileName)
// ErrChartVersionEmpty is raised when a version is not specified in a Chart.yaml.
ErrChartVersionEmpty = fmt.Errorf("invalid chart (%s): version must not be empty", ChartfileName)
)

@ -99,7 +99,7 @@ func LoadArchive(in io.Reader) (*chart.Chart, error) {
// Normalize the path to the / delimiter
n = strings.Replace(n, delimiter, "/", -1)
if parts[0] == "Chart.yaml" {
if parts[0] == ChartfileName {
return nil, errors.New("chart yaml not in base directory")
}
@ -124,7 +124,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
subcharts := map[string][]*BufferedFile{}
for _, f := range files {
if f.Name == "Chart.yaml" {
if f.Name == ChartfileName {
m, err := UnmarshalChartfile(f.Data)
if err != nil {
return c, err
@ -132,16 +132,16 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
c.Metadata = m
} else if f.Name == "values.toml" {
return c, errors.New("values.toml is illegal as of 2.0.0-alpha.2")
} else if f.Name == "values.yaml" {
} else if f.Name == ValuesfileName {
c.Values = &chart.Config{Raw: string(f.Data)}
} else if strings.HasPrefix(f.Name, "templates/") {
} else if strings.HasPrefix(f.Name, TemplatesDir+"/") {
c.Templates = append(c.Templates, &chart.Template{Name: f.Name, Data: f.Data})
} else if strings.HasPrefix(f.Name, "charts/") {
} else if strings.HasPrefix(f.Name, ChartsDir+"/") {
if filepath.Ext(f.Name) == ".prov" {
c.Files = append(c.Files, &any.Any{TypeUrl: f.Name, Value: f.Data})
continue
}
cname := strings.TrimPrefix(f.Name, "charts/")
cname := strings.TrimPrefix(f.Name, ChartsDir+"/")
if strings.IndexAny(cname, "._") == 0 {
// Ignore charts/ that start with . or _.
continue
@ -156,10 +156,10 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
// Ensure that we got a Chart.yaml file
if c.Metadata == nil {
return c, errors.New("chart metadata (Chart.yaml) missing")
return c, ErrChartMetadataMissing
}
if c.Metadata.Name == "" {
return c, errors.New("invalid chart (Chart.yaml): name must not be empty")
return c, ErrChartNameEmpty
}
for n, files := range subcharts {

@ -101,7 +101,7 @@ icon: https://example.com/64x64.png
if err == nil {
t.Fatal("Expected err to be non-nil")
}
if err.Error() != "chart metadata (Chart.yaml) missing" {
if err != ErrChartMetadataMissing {
t.Errorf("Expected chart metadata missing error, got '%s'", err.Error())
}

@ -19,7 +19,6 @@ package chartutil
import (
"archive/tar"
"compress/gzip"
"errors"
"fmt"
"io/ioutil"
"os"
@ -103,14 +102,14 @@ func Save(c *chart.Chart, outDir string) (string, error) {
}
if c.Metadata == nil {
return "", errors.New("no Chart.yaml data")
return "", ErrChartMetadataMissing
}
cfile := c.Metadata
if cfile.Name == "" {
return "", errors.New("no chart name specified (Chart.yaml)")
return "", ErrChartNameEmpty
} else if cfile.Version == "" {
return "", errors.New("no chart version specified (Chart.yaml)")
return "", ErrChartVersionEmpty
}
filename := fmt.Sprintf("%s-%s.tgz", cfile.Name, cfile.Version)
@ -159,13 +158,13 @@ func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
if err != nil {
return err
}
if err := writeToTar(out, base+"/Chart.yaml", cdata); err != nil {
if err := writeToTar(out, base+"/"+ChartfileName, cdata); err != nil {
return err
}
// Save values.yaml
if c.Values != nil && len(c.Values.Raw) > 0 {
if err := writeToTar(out, base+"/values.yaml", []byte(c.Values.Raw)); err != nil {
if err := writeToTar(out, base+"/"+ValuesfileName, []byte(c.Values.Raw)); err != nil {
return err
}
}
@ -188,7 +187,7 @@ func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
// Save dependencies
for _, dep := range c.Dependencies {
if err := writeTarContents(out, dep, base+"/charts"); err != nil {
if err := writeTarContents(out, dep, base+"/"+ChartsDir); err != nil {
return err
}
}

@ -33,29 +33,28 @@ import (
// Chartfile runs a set of linter rules related to Chart.yaml file
func Chartfile(linter *support.Linter) {
chartFileName := "Chart.yaml"
chartPath := filepath.Join(linter.ChartDir, chartFileName)
chartPath := filepath.Join(linter.ChartDir, chartutil.ChartfileName)
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartYamlNotDirectory(chartPath))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartYamlNotDirectory(chartPath))
chartFile, err := chartutil.LoadChartfile(chartPath)
validChartFile := linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartYamlFormat(err))
validChartFile := linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartYamlFormat(err))
// Guard clause. Following linter rules require a parseable ChartFile
if !validChartFile {
return
}
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartName(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartNameDirMatch(linter.ChartDir, chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartName(chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartNameDirMatch(linter.ChartDir, chartFile))
// Chart metadata
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartVersion(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartEngine(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartMaintainer(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartSources(chartFile))
linter.RunLinterRule(support.InfoSev, chartFileName, validateChartIconPresence(chartFile))
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartIconURL(chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartVersion(chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartEngine(chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartMaintainer(chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartSources(chartFile))
linter.RunLinterRule(support.InfoSev, chartutil.ChartfileName, validateChartIconPresence(chartFile))
linter.RunLinterRule(support.ErrorSev, chartutil.ChartfileName, validateChartIconURL(chartFile))
}
func validateChartYamlNotDirectory(chartPath string) error {

@ -32,7 +32,7 @@ import (
// Templates lints the templates in the Linter.
func Templates(linter *support.Linter) {
path := "templates/"
path := chartutil.TemplatesDir + "/"
templatesPath := filepath.Join(linter.ChartDir, path)
templatesDirExist := linter.RunLinterRule(support.WarningSev, path, validateTemplatesDir(templatesPath))

@ -27,15 +27,14 @@ import (
// Values lints a chart's values.yaml file.
func Values(linter *support.Linter) {
file := "values.yaml"
vf := filepath.Join(linter.ChartDir, file)
fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(linter, vf))
vf := filepath.Join(linter.ChartDir, chartutil.ValuesfileName)
fileExists := linter.RunLinterRule(support.InfoSev, chartutil.ValuesfileName, validateValuesFileExistence(linter, vf))
if !fileExists {
return
}
linter.RunLinterRule(support.ErrorSev, file, validateValuesFile(linter, vf))
linter.RunLinterRule(support.ErrorSev, chartutil.ValuesfileName, validateValuesFile(linter, vf))
}
func validateValuesFileExistence(linter *support.Linter, valuesPath string) error {

Loading…
Cancel
Save