feat(helm): add 'helm inspect'

This basic version of helm inspect displays the Chart.yaml and
values.yaml files on STDOUT.

Closes #967
pull/970/head
Matt Butcher 8 years ago
parent 09c74ee8b4
commit c5cc02a611

@ -90,6 +90,7 @@ func newRootCmd(out io.Writer) *cobra.Command {
newStatusCmd(nil, out),
newInstallCmd(nil, out),
newDeleteCmd(nil, out),
newInspectCmd(nil, out),
)
return cmd
}

@ -0,0 +1,81 @@
/*
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 main
import (
"fmt"
"io"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm"
)
const inspectDesc = `
This command inspects a chart (directory, file, or URL) and displays information.
Inspect prints the contents of the Chart.yaml file and the values.yaml file.
`
type inspectCmd struct {
chartpath string
out io.Writer
client helm.Interface
}
func newInspectCmd(c helm.Interface, out io.Writer) *cobra.Command {
insp := &inspectCmd{
client: c,
out: out,
}
cc := &cobra.Command{
Use: "inspect [CHART]",
Short: "inspect a chart",
Long: installDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(1, len(args), "chart name"); err != nil {
return err
}
cp, err := locateChartPath(args[0])
if err != nil {
return err
}
insp.chartpath = cp
return insp.run()
},
}
return cc
}
func (i *inspectCmd) run() error {
chrt, err := chartutil.Load(i.chartpath)
if err != nil {
return err
}
cf, err := yaml.Marshal(chrt.Metadata)
if err != nil {
return err
}
fmt.Fprintln(i.out, string(cf))
fmt.Fprintln(i.out, "---")
fmt.Fprintln(i.out, chrt.Values.Raw)
return nil
}

@ -0,0 +1,63 @@
/*
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 main
import (
"bytes"
"io/ioutil"
"strings"
"testing"
)
func TestInspect(t *testing.T) {
b := bytes.NewBuffer(nil)
insp := &inspectCmd{
chartpath: "testdata/testcharts/alpine",
out: b,
}
insp.run()
// Load the data from the textfixture directly.
cdata, err := ioutil.ReadFile("testdata/testcharts/alpine/Chart.yaml")
if err != nil {
t.Fatal(err)
}
data, err := ioutil.ReadFile("testdata/testcharts/alpine/values.yaml")
if err != nil {
t.Fatal(err)
}
parts := strings.SplitN(b.String(), "---", 2)
if len(parts) != 2 {
t.Fatalf("Expected 2 parts, got %d", len(parts))
}
expect := []string{
strings.TrimSpace(string(cdata)),
strings.TrimSpace(string(data)),
}
// Problem: ghodss/yaml doesn't marshal into struct order. To solve, we
// have to carefully craft the Chart.yaml to match.
for i, got := range parts {
got = strings.TrimSpace(got)
if got != expect[i] {
t.Errorf("Expected\n%q\nGot\n%q\n", expect[i], got)
}
}
}

@ -1,6 +1,6 @@
name: alpine
description: Deploy a basic Alpine Linux pod
version: 0.1.0
home: https://k8s.io/helm
name: alpine
sources:
- https://github.com/kubernetes/helm
- https://github.com/kubernetes/helm
version: 0.1.0

Loading…
Cancel
Save