本文整理汇总了Golang中github.com/deis/helm/helm/log.Die函数的典型用法代码示例。如果您正苦于以下问题:Golang Die函数的具体用法?Golang Die怎么用?Golang Die使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Die函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Install
// Install loads a chart into Kubernetes.
//
// If the chart is not found in the workspace, it is fetched and then installed.
//
// During install, manifests are sent to Kubernetes in the following order:
//
// - Namespaces
// - Secrets
// - Volumes
// - Services
// - Pods
// - ReplicationControllers
func Install(chart, home, namespace string, force bool) {
if !chartInstalled(chart, home) {
log.Info("No installed chart named %q. Installing now.", chart)
fetch(chart, chart, home)
}
cd := filepath.Join(home, WorkspaceChartPath, chart)
c, err := model.Load(cd)
if err != nil {
log.Die("Failed to load chart: %s", err)
}
// Give user the option to bale if dependencies are not satisfied.
nope, err := dependency.Resolve(c.Chartfile, filepath.Join(home, WorkspaceChartPath))
if err != nil {
log.Warn("Failed to check dependencies: %s", err)
if !force {
log.Die("Re-run with --force to install anyway.")
}
} else if len(nope) > 0 {
log.Warn("Unsatisfied dependencies:")
for _, d := range nope {
log.Msg("\t%s %s", d.Name, d.Version)
}
if !force {
log.Die("Stopping install. Re-run with --force to install anyway.")
}
}
if err := uploadManifests(c, namespace); err != nil {
log.Die("Failed to upload manifests: %s", err)
}
PrintREADME(chart, home)
}
示例2: Edit
// Edit charts using the shell-defined $EDITOR
//
// - chartName being edited
// - homeDir is the helm home directory for the user
func Edit(chartName, homeDir string) {
chartDir := path.Join(homeDir, "workspace", "charts", chartName)
// enumerate chart files
files, err := listChart(chartDir)
if err != nil {
log.Die("could not list chart: %v", err)
}
// join chart with YAML delimeters
contents, err := joinChart(chartDir, files)
if err != nil {
log.Die("could not join chart data: %v", err)
}
// write chart to temporary file
f, err := ioutil.TempFile(os.TempDir(), "helm-edit")
if err != nil {
log.Die("could not open tempfile: %v", err)
}
defer os.Remove(f.Name())
f.Write(contents.Bytes())
f.Close()
openEditor(f.Name())
saveChart(chartDir, f.Name())
}
示例3: ensurePrereqs
// ensurePrereqs verifies that Git and Kubectl are both available.
func ensurePrereqs() {
if _, err := exec.LookPath("git"); err != nil {
log.Die("Could not find 'git' on $PATH: %s", err)
}
if _, err := exec.LookPath("kubectl"); err != nil {
log.Die("Could not find 'kubectl' on $PATH: %s", err)
}
}
示例4: saveChart
// saveChart reads a delimited chart and write out its parts
// to the workspace directory
func saveChart(chartDir string, filename string) error {
// read the serialized chart file
contents, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
chartData := make(map[string][]byte)
// use a regular expression to read file paths and content
match := delimeterRegexp.FindAllSubmatch(contents, -1)
for _, m := range match {
chartData[string(m[1])] = m[2]
}
// save edited chart data to the workspace
for k, v := range chartData {
fp := path.Join(chartDir, k)
if err := ioutil.WriteFile(fp, v, 0644); err != nil {
log.Die("could not write chart file", err)
}
}
return nil
}
示例5: Update
// Update fetches the remote repo into the home directory.
func Update(repo, home string) {
home, err := filepath.Abs(home)
if err != nil {
log.Die("Could not generate absolute path for %q: %s", home, err)
}
// Basically, install if this is the first run.
ensurePrereqs()
ensureHome(home)
gitrepo := filepath.Join(home, CachePath)
git := ensureRepo(repo, gitrepo)
if err := gitUpdate(git); err != nil {
log.Die("Failed to update from Git: %s", err)
}
}
示例6: Fetch
// Fetch gets a chart from the source repo and copies to the workdir.
//
// - chart is the source
// - lname is the local name for that chart (chart-name); if blank, it is set to the chart.
// - homedir is the home directory for the user
// - ns is the namespace for this package. If blank, it is set to the DefaultNS.
func Fetch(chart, lname, homedir string) {
if lname == "" {
lname = chart
}
fetch(chart, lname, homedir)
cfile, err := model.LoadChartfile(filepath.Join(homedir, WorkspaceChartPath, chart, "Chart.yaml"))
if err != nil {
log.Die("Source is not a valid chart. Missing Chart.yaml: %s", err)
}
deps, err := dependency.Resolve(cfile, filepath.Join(homedir, WorkspaceChartPath))
if err != nil {
log.Warn("Could not check dependencies: %s", err)
return
}
if len(deps) > 0 {
log.Warn("Unsatisfied dependencies:")
for _, d := range deps {
log.Msg("\t%s %s", d.Name, d.Version)
}
}
PrintREADME(lname, homedir)
}
示例7: Uninstall
func Uninstall(chart, home, namespace string) {
if !chartInstalled(chart, home) {
log.Info("No installed chart named %q. Nothing to delete.", chart)
return
}
cd := filepath.Join(home, WorkspaceChartPath, chart)
c, err := model.Load(cd)
if err != nil {
log.Die("Failed to load chart: %s", err)
}
if err := deleteChart(c, namespace); err != nil {
log.Die("Failed to completely delete chart: %s", err)
}
}
示例8: ensureHome
// ensureHome ensures that a HELM_HOME exists.
func ensureHome(home string) {
if fi, err := os.Stat(home); err != nil {
log.Info("Creating %s", home)
for _, p := range helmpaths {
pp := filepath.Join(home, p)
if err := os.MkdirAll(pp, 0755); err != nil {
log.Die("Could not create %q: %s", pp, err)
}
}
} else if !fi.IsDir() {
log.Die("%s must be a directory.", home)
}
if err := os.Chdir(home); err != nil {
log.Die("Could not change to directory %q: %s", home, err)
}
}
示例9: Target
// Target displays information about the cluster
func Target() {
if _, err := exec.LookPath("kubectl"); err != nil {
log.Die("Could not find 'kubectl' on $PATH: %s", err)
}
c, _ := exec.Command("kubectl", "cluster-info").Output()
fmt.Println(string(c))
}
示例10: Create
// Create a chart
//
// - chartName being created
// - homeDir is the helm home directory for the user
func Create(chartName, homeDir string) {
skeletonDir, _ := filepath.Abs("skel")
if fi, err := os.Stat(skeletonDir); err != nil {
log.Die("Could not find %s: %s", skeletonDir, err)
} else if !fi.IsDir() {
log.Die("Malformed skeleton: %s: Must be a directory.", skeletonDir)
}
chartDir := path.Join(homeDir, "workspace", "charts", chartName)
// copy skeleton to chart directory
if err := copyDir(skeletonDir, chartDir); err != nil {
log.Die("failed to copy skeleton directory: %v", err)
}
}
示例11: ensureRepo
// ensureRepo ensures that the repo exists and is checked out.
func ensureRepo(repo, home string) *vcs.GitRepo {
if err := os.Chdir(home); err != nil {
log.Die("Could not change to directory %q: %s", home, err)
}
git, err := vcs.NewGitRepo(repo, home)
if err != nil {
log.Die("Could not get repository %q: %s", repo, err)
}
if !git.CheckLocal() {
log.Info("Cloning repo into %q. Please wait.", home)
if err := git.Get(); err != nil {
log.Die("Could not create repository in %q: %s", home, err)
}
}
return git
}
示例12: fetch
func fetch(chart, lname, homedir string) {
src := filepath.Join(homedir, CacheChartPath, chart)
dest := filepath.Join(homedir, WorkspaceChartPath, lname)
if fi, err := os.Stat(src); err != nil {
} else if !fi.IsDir() {
log.Die("Malformed chart %s: Chart must be in a directory.", chart)
}
if err := os.MkdirAll(dest, 0755); err != nil {
log.Die("Could not create %q: %s", dest, err)
}
log.Info("Fetching %s to %s", src, dest)
if err := copyDir(src, dest); err != nil {
log.Die("Failed copying %s to %s", src, dest)
}
}
示例13: info
func info(c *cli.Context) {
a := c.Args()
if len(a) == 0 {
log.Die("Info requires at least a Chart name")
}
action.Info(c.Args()[0], home(c))
}
示例14: ensureHome
// ensureHome ensures that a HELM_HOME exists.
func ensureHome(home string) {
must := []string{home, filepath.Join(home, CachePath), filepath.Join(home, WorkspacePath)}
for _, p := range must {
if fi, err := os.Stat(p); err != nil {
log.Info("Creating %s", p)
if err := os.MkdirAll(p, 0755); err != nil {
log.Die("Could not create %q: %s", p, err)
}
} else if !fi.IsDir() {
log.Die("%s must be a directory.", home)
}
}
if err := os.Chdir(home); err != nil {
log.Die("Could not change to directory %q: %s", home, err)
}
}
示例15: minArgs
// minArgs checks to see if the right number of args are passed.
//
// If not, it prints an error and quits.
func minArgs(c *cli.Context, i int, name string) {
if len(c.Args()) < i {
m := "arguments"
if i == 1 {
m = "argument"
}
log.Err("Expected %d %s", i, m)
cli.ShowCommandHelp(c, name)
log.Die("")
}
}