本文整理汇总了Golang中github.com/helm/helm/log.Die函数的典型用法代码示例。如果您正苦于以下问题:Golang Die函数的具体用法?Golang Die怎么用?Golang Die使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Die函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: fetch
func fetch(chartName, lname, homedir, chartpath string) {
src := helm.CacheDirectory(homedir, chartpath, chartName)
dest := helm.WorkspaceChartDirectory(homedir, lname)
fi, err := os.Stat(src)
if err != nil {
log.Warn("Oops. Looks like there was an issue finding the chart, %s, n %s. Running `helm update` to ensure you have the latest version of all Charts from Github...", lname, src)
Update(homedir)
fi, err = os.Stat(src)
if err != nil {
log.Die("Chart %s not found in %s", lname, src)
}
log.Info("Good news! Looks like that did the trick. Onwards and upwards!")
}
if !fi.IsDir() {
log.Die("Malformed chart %s: Chart must be in a directory.", chartName)
}
if err := os.MkdirAll(dest, 0755); err != nil {
log.Die("Could not create %q: %s", dest, err)
}
log.Debug("Fetching %s to %s", src, dest)
if err := helm.CopyDir(src, dest); err != nil {
log.Die("Failed copying %s to %s", src, dest)
}
if err := updateChartfile(src, dest, lname); err != nil {
log.Die("Failed to update Chart.yaml: %s", err)
}
}
开发者ID:2opremio,项目名称:helm,代码行数:32,代码来源:fetch.go
示例2: Uninstall
// Uninstall removes a chart from Kubernetes.
//
// Manifests are removed from Kubernetes in the following order:
//
// - Services (to shut down traffic)
// - Pods (which can be part of RCs)
// - ReplicationControllers
// - Volumes
// - Secrets
// - Namespaces
func Uninstall(chartName, home, namespace string, force bool) {
if !chartFetched(chartName, home) {
log.Info("No chart named %q in your workspace. Nothing to delete.", chartName)
return
}
cd := filepath.Join(home, WorkspaceChartPath, chartName)
c, err := chart.Load(cd)
if err != nil {
log.Die("Failed to load chart: %s", err)
}
if err := deleteChart(c, namespace, true); err != nil {
log.Die("Failed to list charts: %s", err)
}
if !force && !promptConfirm("Uninstall the listed objects?") {
log.Info("Aborted uninstall")
return
}
log.Info("Running `kubectl delete` ...")
if err := deleteChart(c, namespace, false); err != nil {
log.Die("Failed to completely delete chart: %s", err)
}
log.Info("Done")
}
开发者ID:fabric8io,项目名称:helm,代码行数:35,代码来源:uninstall.go
示例3: ensureHome
// ensureHome ensures that a HELM_HOME exists.
func ensureHome(home string) {
must := []string{home, filepath.Join(home, CachePath), filepath.Join(home, WorkspacePath), filepath.Join(home, CacheChartPath)}
for _, p := range must {
if fi, err := os.Stat(p); err != nil {
log.Debug("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)
}
}
refi := filepath.Join(home, Configfile)
if _, err := os.Stat(refi); err != nil {
log.Info("Creating %s", refi)
// Attempt to create a Repos.yaml
if err := ioutil.WriteFile(refi, []byte(config.DefaultConfigfile), 0755); err != nil {
log.Die("Could not create %s: %s", refi, err)
}
}
if err := os.Chdir(home); err != nil {
log.Die("Could not change to directory %q: %s", home, err)
}
}
开发者ID:fabric8io,项目名称:helm,代码行数:29,代码来源:update.go
示例4: Remove
// Remove removes a chart from the workdir.
//
// - chart is the source
// - homedir is the home directory for the user
// - force will remove installed charts from workspace
func Remove(chart, homedir string, force bool) {
chartPath := filepath.Join(homedir, WorkspaceChartPath, chart)
if _, err := os.Stat(chartPath); err != nil {
log.Die("Chart not found. %s", err)
}
var connectionFailure bool
// check if any chart manifests are installed
installed, err := checkManifests(chartPath)
if err != nil {
if strings.Contains(err.Error(), "unable to connect") {
connectionFailure = true
} else {
log.Die(err.Error())
}
}
if !force && connectionFailure {
log.Err("Could not determine if %s is installed. To remove the chart --force flag must be set.", chart)
} else if !force && len(installed) > 0 {
log.Err("Found %d installed manifests for %s. To remove a chart that has been installed the --force flag must be set.", len(installed), chart)
} else {
// remove local chart files
if err := os.RemoveAll(chartPath); err != nil {
log.Die("Could not remove chart. %s", err)
}
log.Info("All clear! You have successfully removed %s from your workspace.", chart)
}
}
开发者ID:fabric8io,项目名称:helm,代码行数:36,代码来源:remove.go
示例5: Uninstall
// Uninstall removes a chart from Kubernetes.
//
// Manifests are removed from Kubernetes in the order specified by
// chart.UninstallOrder. Any unknown types are removed before that sequence
// is run.
func Uninstall(chartName, home, namespace string, force bool, client kubectl.Runner) {
// This is a stop-gap until kubectl respects namespaces in manifests.
if namespace == "" {
log.Die("This command requires a namespace. Did you mean '-n default'?")
}
if !chartFetched(chartName, home) {
log.Info("No chart named %q in your workspace. Nothing to delete.", chartName)
return
}
cd := helm.WorkspaceChartDirectory(home, chartName)
c, err := chart.Load(cd)
if err != nil {
log.Die("Failed to load chart: %s", err)
}
if err := deleteChart(c, namespace, true, client); err != nil {
log.Die("Failed to list charts: %s", err)
}
if !force && !promptConfirm("Uninstall the listed objects?") {
log.Info("Aborted uninstall")
return
}
CheckKubePrereqs()
log.Info("Running `kubectl delete` ...")
if err := deleteChart(c, namespace, false, client); err != nil {
log.Die("Failed to completely delete chart: %s", err)
}
log.Info("Done")
}
开发者ID:colonelmo,项目名称:helm,代码行数:36,代码来源:uninstall.go
示例6: Template
// Template renders a template to an output file.
func Template(out, in, data string) {
var dest io.Writer
if out != "" {
f, err := os.Create(out)
if err != nil {
log.Die("Failed to open %s: %s", out, err)
}
defer func() {
if err := f.Close(); err != nil {
log.Err("Error closing file: %s", err)
}
}()
dest = f
} else {
dest = log.Stdout
}
var vals interface{}
if data != "" {
var err error
vals, err = openValues(data)
if err != nil {
log.Die("Error opening value file: %s", err)
}
}
tpl, err := ioutil.ReadFile(in)
if err != nil {
log.Die("Failed to read template file: %s", err)
}
if err := renderTemplate(dest, string(tpl), vals); err != nil {
log.Die("Failed: %s", err)
}
}
开发者ID:michelleN,项目名称:helm,代码行数:36,代码来源:template.go
示例7: Create
// Create a chart
//
// - chartName being created
// - homeDir is the helm home directory for the user
func Create(chartName, homeDir string) {
chart := newSkelChartfile(chartName)
chartDir := filepath.Join(homeDir, WorkspaceChartPath, chartName)
// create directories
if err := os.MkdirAll(filepath.Join(chartDir, "manifests"), 0755); err != nil {
log.Die("Could not create %q: %s", chartDir, err)
}
// create Chartfile.yaml
if err := chart.Save(filepath.Join(chartDir, "Chart.yaml")); err != nil {
log.Die("Could not create Chart.yaml: err", err)
}
// create README.md
if err := createReadme(chartDir, chart); err != nil {
log.Die("Could not create README.md: err", err)
}
// create example-pod
if err := createExampleManifest(chartDir); err != nil {
log.Die("Could not create example manifest: err", err)
}
log.Info("Created chart in %s", chartDir)
}
开发者ID:arschles,项目名称:helm-classic,代码行数:31,代码来源:create.go
示例8: 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)
}
}
开发者ID:fabric8io,项目名称:helm,代码行数:9,代码来源:update.go
示例9: DeleteRepo
// DeleteRepo deletes a repository.
func DeleteRepo(homedir, name string) {
cfg := mustConfig(homedir)
if err := cfg.Repos.Delete(name); err != nil {
log.Die("Failed to delete repository: %s", err)
}
if err := cfg.Save(""); err != nil {
log.Die("Deleted repo, but could not save settings: %s", err)
}
}
开发者ID:2opremio,项目名称:helm,代码行数:11,代码来源:repo.go
示例10: AddRepo
// AddRepo adds a repo to the list of repositories.
func AddRepo(homedir, name, repository string) {
cfg := mustConfig(homedir)
if err := cfg.Repos.Add(name, repository); err != nil {
log.Die(err.Error())
}
if err := cfg.Save(""); err != nil {
log.Die("Could not save configuration: %s", err)
}
}
开发者ID:michelleN,项目名称:helm,代码行数:11,代码来源:repo.go
示例11: Remove
// Remove removes a chart from the workdir.
//
// - chart is the source
// - homedir is the home directory for the user
func Remove(chart string, homedir string) {
chartPath := filepath.Join(homedir, WorkspaceChartPath, chart)
if _, err := os.Stat(chartPath); err != nil {
log.Die("Chart not found. %s", err)
}
if err := os.RemoveAll(chartPath); err != nil {
log.Die("%s", err)
}
log.Info("All clear! You have successfully removed %s from your workspace.", chart)
}
开发者ID:arschles,项目名称:helm-classic,代码行数:16,代码来源:remove.go
示例12: AddRepo
// AddRepo adds a repo to the list of repositories.
func AddRepo(homedir, name, repository string) {
cfg := mustConfig(homedir)
if err := cfg.Repos.Add(name, repository); err != nil {
log.Die(err.Error())
}
if err := cfg.Save(""); err != nil {
log.Die("Could not save configuration: %s", err)
}
log.Info("Hooray! Successfully added the repo.")
}
开发者ID:2opremio,项目名称:helm,代码行数:13,代码来源:repo.go
示例13: Update
// Update fetches the remote repo into the home directory.
func Update(home string) {
home, err := filepath.Abs(home)
if err != nil {
log.Die("Could not generate absolute path for %q: %s", home, err)
}
CheckLocalPrereqs(home)
rc := mustConfig(home).Repos
if err := rc.UpdateAll(); err != nil {
log.Die("Not all repos could be updated: %s", err)
}
log.Info("Done")
}
开发者ID:michelleN,项目名称:helm,代码行数:15,代码来源:update.go
示例14: AltInstall
// AltInstall allows loading a chart from the current directory.
//
// It does not directly support chart tables (repos).
func AltInstall(chartName, cachedir, home, namespace string, force bool, dryRun bool) {
// Make sure there is a chart in the cachedir.
if _, err := os.Stat(filepath.Join(cachedir, "Chart.yaml")); err != nil {
log.Die("Expected a Chart.yaml in %s: %s", cachedir, err)
}
// Make sure there is a manifests dir.
if fi, err := os.Stat(filepath.Join(cachedir, "manifests")); err != nil {
log.Die("Expected 'manifests/' in %s: %s", cachedir, err)
} else if !fi.IsDir() {
log.Die("Expected 'manifests/' to be a directory in %s: %s", cachedir, err)
}
dest := filepath.Join(home, WorkspaceChartPath, chartName)
if ok, err := isSamePath(dest, cachedir); err != nil || ok {
log.Die("Cannot read from and write to the same place: %s. %v", cachedir, err)
}
// Copy the source chart to the workspace. We ruthlessly overwrite in
// this case.
if err := copyDir(cachedir, dest); err != nil {
log.Die("Failed to copy %s to %s: %s", cachedir, dest, err)
}
// Load the chart.
c, err := chart.Load(dest)
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.")
}
}
msg := "Running `kubectl create -f` ..."
if dryRun {
msg = "Performing a dry run of `kubectl create -f` ..."
}
log.Info(msg)
if err := uploadManifests(c, namespace, dryRun); err != nil {
log.Die("Failed to upload manifests: %s", err)
}
}
开发者ID:arschles,项目名称:helm-classic,代码行数:58,代码来源:install.go
示例15: 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 ordered specified by InstallOrder.
func Install(chartName, home, namespace string, force bool, generate bool, exclude []string, client kubectl.Runner) {
ochart := chartName
r := mustConfig(home).Repos
table, chartName := r.RepoChart(chartName)
if !chartFetched(chartName, home) {
log.Info("No chart named %q in your workspace. Fetching now.", ochart)
fetch(chartName, chartName, home, table)
}
cd := helm.WorkspaceChartDirectory(home, chartName)
c, err := chart.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, helm.WorkspaceChartDirectory(home))
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.")
}
}
// Run the generator if -g is set.
if generate {
Generate(chartName, home, exclude)
}
CheckKubePrereqs()
log.Info("Running `kubectl create -f` ...")
if err := uploadManifests(c, namespace, client); err != nil {
log.Die("Failed to upload manifests: %s", err)
}
log.Info("Done")
PrintREADME(chartName, home)
}
开发者ID:colonelmo,项目名称:helm,代码行数:54,代码来源:install.go
示例16: Update
// Update fetches the remote repo into the home directory.
func Update(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)
rc := mustConfig(home).Repos
if err := rc.UpdateAll(); err != nil {
log.Die("Not all repos could be updated: %s", err)
}
log.Info("Done")
}
开发者ID:fabric8io,项目名称:helm,代码行数:17,代码来源:update.go
示例17: search
func search(term, base, table string, charts map[string]*chart.Chartfile) error {
dirs, err := filepath.Glob(base)
if err != nil {
return fmt.Errorf("No results found. %s", err)
} else if len(dirs) == 0 {
return errors.New("No results found.")
}
r, err := regexp.Compile(term)
if err != nil {
log.Die("Invalid expression %q: %s", term, err)
}
for _, dir := range dirs {
cname := filepath.Join(table, filepath.Base(dir))
chrt, err := chart.LoadChartfile(filepath.Join(dir, "Chart.yaml"))
if err != nil {
// This dir is not a chart. Skip it.
continue
} else if r.MatchString(chrt.Name) || r.MatchString(chrt.Description) {
charts[cname] = chrt
}
}
return nil
}
开发者ID:arschles,项目名称:helm-classic,代码行数:27,代码来源:search.go
示例18: Publish
// Publish a chart from the workspace to the cache directory
//
// - chartName being published
// - homeDir is the helm home directory for the user
// - force publishing even if the chart directory already exists
func Publish(chartName, homeDir, repo string, force bool) {
if repo == "" {
repo = "charts"
}
if !mustConfig(homeDir).Repos.Exists(repo) {
log.Err("Repo %s does not exist", repo)
log.Info("Available repositories")
ListRepos(homeDir)
return
}
src := helm.WorkspaceChartDirectory(homeDir, chartName)
dst := helm.CacheDirectory(homeDir, repo, chartName)
if _, err := os.Stat(dst); err == nil {
if force != true {
log.Info("chart already exists, use -f to force")
return
}
}
if err := helm.CopyDir(src, dst); err != nil {
log.Die("failed to publish directory: %v", err)
}
}
开发者ID:michelleN,项目名称:helm,代码行数:31,代码来源:publish.go
示例19: RepoName
// RepoName gets the name of the Git repo, or an empty string if none is found.
func RepoName(chartpath string) string {
wd, err := os.Getwd()
if err != nil {
log.Err("Could not get working directory: %s", err)
return ""
}
defer func() {
if err := os.Chdir(wd); err != nil {
log.Die("Unrecoverable error: %s", err)
}
}()
if err := os.Chdir(chartpath); err != nil {
log.Err("Could not find chartpath %s: %s", chartpath, err)
return ""
}
out, err := exec.Command("git", "config", "--get", "remote.origin.url").CombinedOutput()
if err != nil {
log.Err("Git failed to get the origin name: %s %s", err, string(out))
return ""
}
return strings.TrimSpace(string(out))
}
开发者ID:michelleN,项目名称:helm,代码行数:26,代码来源:chartfile.go
示例20: Fetch
// Fetch gets a chart from the source repo and copies to the workdir.
//
// - chartName 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
func Fetch(chartName, lname, homedir string) {
r := mustConfig(homedir).Repos
repository, chartName := r.RepoChart(chartName)
if lname == "" {
lname = chartName
}
fetch(chartName, lname, homedir, repository)
chartFilePath := helm.WorkspaceChartDirectory(homedir, lname, Chartfile)
cfile, err := chart.LoadChartfile(chartFilePath)
if err != nil {
log.Die("Source is not a valid chart. Missing Chart.yaml: %s", err)
}
deps, err := dependency.Resolve(cfile, helm.WorkspaceChartDirectory(homedir))
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)
}
}
log.Info("Fetched chart into workspace %s", helm.WorkspaceChartDirectory(homedir, lname))
log.Info("Done")
}
开发者ID:michelleN,项目名称:helm,代码行数:38,代码来源:fetch.go
注:本文中的github.com/helm/helm/log.Die函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论