|
|
|
@ -19,30 +19,33 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/version"
|
|
|
|
|
"k8s.io/client-go/discovery"
|
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver"
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
fakedisc "k8s.io/client-go/discovery/fake"
|
|
|
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
|
|
|
"k8s.io/helm/cmd/helm/require"
|
|
|
|
|
"k8s.io/helm/pkg/action"
|
|
|
|
|
"k8s.io/helm/pkg/chart/loader"
|
|
|
|
|
"k8s.io/helm/pkg/chartutil"
|
|
|
|
|
"k8s.io/helm/pkg/engine"
|
|
|
|
|
"k8s.io/helm/pkg/hapi/release"
|
|
|
|
|
util "k8s.io/helm/pkg/releaseutil"
|
|
|
|
|
"k8s.io/helm/pkg/tiller"
|
|
|
|
|
"k8s.io/helm/pkg/storage"
|
|
|
|
|
"k8s.io/helm/pkg/storage/driver"
|
|
|
|
|
"k8s.io/helm/pkg/tiller/environment"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const defaultDirectoryPermission = 0755
|
|
|
|
|
//const defaultDirectoryPermission = 0755
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
whitespaceRegex = regexp.MustCompile(`^\s*$`)
|
|
|
|
|
//whitespaceRegex = regexp.MustCompile(`^\s*$`)
|
|
|
|
|
|
|
|
|
|
// defaultKubeVersion is the default value of --kube-version flag
|
|
|
|
|
defaultKubeVersion = fmt.Sprintf("%s.%s", chartutil.DefaultKubeVersion.Major, chartutil.DefaultKubeVersion.Minor)
|
|
|
|
@ -130,13 +133,6 @@ func (o *templateOptions) run(out io.Writer) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// verify that output-dir exists if provided
|
|
|
|
|
if o.outputDir != "" {
|
|
|
|
|
if _, err := os.Stat(o.outputDir); os.IsNotExist(err) {
|
|
|
|
|
return errors.Errorf("output-dir '%s' does not exist", o.outputDir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get combined values and create config
|
|
|
|
|
config, err := o.mergedValues()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -162,14 +158,48 @@ func (o *templateOptions) run(out io.Writer) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options := chartutil.ReleaseOptions{
|
|
|
|
|
Name: o.releaseName,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := chartutil.ProcessDependencies(c, config); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MPB: It appears that we can now do everything we need with an install
|
|
|
|
|
// dry-run using the Kubernetes mock
|
|
|
|
|
disc, err := createFakeDiscovery(o.kubeVersion)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
customConfig := &action.Configuration{
|
|
|
|
|
// Add mock objects in here so it doesn't use Kube API server
|
|
|
|
|
Releases: storage.Init(driver.NewMemory()),
|
|
|
|
|
KubeClient: &environment.PrintingKubeClient{Out: ioutil.Discard},
|
|
|
|
|
Discovery: disc,
|
|
|
|
|
Log: func(format string, v ...interface{}) {
|
|
|
|
|
fmt.Fprintf(out, format, v...)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
inst := action.NewInstall(customConfig)
|
|
|
|
|
inst.DryRun = true
|
|
|
|
|
inst.Replace = true // Skip running the name check
|
|
|
|
|
inst.ReleaseName = o.releaseName
|
|
|
|
|
rel, err := inst.Run(c, config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if o.showNotes {
|
|
|
|
|
fmt.Fprintln(out, rel.Info.Notes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if o.outputDir != "" {
|
|
|
|
|
return o.writeAsFiles(rel)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintln(out, rel.Manifest)
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
// Set up engine.
|
|
|
|
|
renderer := engine.New()
|
|
|
|
|
|
|
|
|
@ -252,10 +282,38 @@ func (o *templateOptions) run(out io.Writer) error {
|
|
|
|
|
fmt.Fprintln(out, m.Content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *templateOptions) writeAsFiles(rel *release.Release) error {
|
|
|
|
|
if _, err := os.Stat(o.outputDir); os.IsNotExist(err) {
|
|
|
|
|
return errors.Errorf("output-dir '%s' does not exist", o.outputDir)
|
|
|
|
|
}
|
|
|
|
|
// At one point we parsed out the returned manifest and created multiple files.
|
|
|
|
|
// I'm not totally sure what the use case was for that.
|
|
|
|
|
filename := filepath.Join(o.outputDir, rel.Name+".yaml")
|
|
|
|
|
return ioutil.WriteFile(filename, []byte(rel.Manifest), 0644)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// createFakeDiscovery creates a discovery client and seeds it with mock data.
|
|
|
|
|
func createFakeDiscovery(verStr string) (discovery.DiscoveryInterface, error) {
|
|
|
|
|
disc := fake.NewSimpleClientset().Discovery()
|
|
|
|
|
if verStr != "" {
|
|
|
|
|
kv, err := semver.NewVersion(verStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return disc, errors.Wrap(err, "could not parse a kubernetes version")
|
|
|
|
|
}
|
|
|
|
|
disc.(*fakedisc.FakeDiscovery).FakedServerVersion = &version.Info{
|
|
|
|
|
Major: fmt.Sprintf("%d", kv.Major()),
|
|
|
|
|
Minor: fmt.Sprintf("%d", kv.Minor()),
|
|
|
|
|
GitVersion: fmt.Sprintf("v%d.%d.0", kv.Major(), kv.Minor()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return disc, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write the <data> to <output-dir>/<name>
|
|
|
|
|
/*
|
|
|
|
|
func writeToFile(out io.Writer, outputDir, name, data string) error {
|
|
|
|
|
outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator))
|
|
|
|
|
|
|
|
|
@ -278,6 +336,7 @@ func writeToFile(out io.Writer, outputDir, name, data string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check if the directory exists to create file. creates if don't exists
|
|
|
|
|
func ensureDirectoryForFile(file string) error {
|
|
|
|
|
baseDir := path.Dir(file)
|
|
|
|
@ -287,3 +346,4 @@ func ensureDirectoryForFile(file string) error {
|
|
|
|
|
|
|
|
|
|
return os.MkdirAll(baseDir, defaultDirectoryPermission)
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|