本文整理匯總了Golang中github.com/helm/helm/util.WorkspaceChartDirectory函數的典型用法代碼示例。如果您正苦於以下問題:Golang WorkspaceChartDirectory函數的具體用法?Golang WorkspaceChartDirectory怎麽用?Golang WorkspaceChartDirectory使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WorkspaceChartDirectory函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestLintEmptyChartYaml
func TestLintEmptyChartYaml(t *testing.T) {
tmpHome := test.CreateTmpHome()
test.FakeUpdate(tmpHome)
chartName := "badChart"
Create(chartName, tmpHome)
badChartYaml, _ := yaml.Marshal(make(map[string]string))
chartYaml := util.WorkspaceChartDirectory(tmpHome, chartName, Chartfile)
os.Remove(chartYaml)
ioutil.WriteFile(chartYaml, badChartYaml, 0644)
output := test.CaptureOutput(func() {
Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
})
test.ExpectContains(t, output, "Chart.yaml has a name field : false")
test.ExpectContains(t, output, "Chart.yaml has a version field : false")
test.ExpectContains(t, output, "Chart.yaml has a description field : false")
test.ExpectContains(t, output, "Chart.yaml has a maintainers field : false")
test.ExpectContains(t, output, fmt.Sprintf("Chart [%s] has failed some necessary checks", chartName))
}
示例2: 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")
}
示例3: 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)
}
示例4: createWithChart
func createWithChart(chart *chart.Chartfile, chartName, homeDir string) {
chartDir := helm.WorkspaceChartDirectory(homeDir, 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, Chartfile)); 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)
}
示例5: 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)
}
}
示例6: TestLintMissingReadme
func TestLintMissingReadme(t *testing.T) {
tmpHome := test.CreateTmpHome()
test.FakeUpdate(tmpHome)
chartName := "badChart"
Create(chartName, tmpHome)
os.Remove(filepath.Join(util.WorkspaceChartDirectory(tmpHome, chartName), "README.md"))
output := test.CaptureOutput(func() {
Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
})
test.ExpectContains(t, output, "README.md is present and not empty : false")
}
示例7: 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)
}
}
示例8: 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")
}
示例9: lint
func lint(c *cli.Context) {
home := home(c)
all := c.Bool("all")
if all {
action.LintAll(home)
return
}
minArgs(c, 1, "lint")
a := c.Args()
chartNameOrPath := a[0]
fromHome := util.WorkspaceChartDirectory(home, chartNameOrPath)
fromAbs := filepath.Clean(chartNameOrPath)
_, err := os.Stat(fromAbs)
if err == nil {
action.Lint(fromAbs)
} else {
action.Lint(fromHome)
}
}
示例10: TestLintMissingChartYaml
func TestLintMissingChartYaml(t *testing.T) {
tmpHome := test.CreateTmpHome()
test.FakeUpdate(tmpHome)
chartName := "badChart"
Create(chartName, tmpHome)
os.Remove(filepath.Join(util.WorkspaceChartDirectory(tmpHome, chartName), Chartfile))
output := test.CaptureOutput(func() {
Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
})
test.ExpectContains(t, output, "Chart.yaml is present : false")
test.ExpectContains(t, output, "Chart [badChart] has failed some necessary checks.")
}
示例11: TestLintMissingManifestDirectory
func TestLintMissingManifestDirectory(t *testing.T) {
tmpHome := test.CreateTmpHome()
test.FakeUpdate(tmpHome)
chartName := "brokeChart"
Create(chartName, tmpHome)
os.RemoveAll(filepath.Join(util.WorkspaceChartDirectory(tmpHome, chartName), "manifests"))
output := test.CaptureOutput(func() {
Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
})
test.ExpectMatches(t, output, "Manifests directory is present : false")
test.ExpectContains(t, output, "Chart ["+chartName+"] has failed some necessary checks")
}
示例12: chartFetched
// Check by chart directory name whether a chart is fetched into the workspace.
//
// This does NOT check the Chart.yaml file.
func chartFetched(chartName, home string) bool {
p := helm.WorkspaceChartDirectory(home, chartName, Chartfile)
log.Debug("Looking for %q", p)
if fi, err := os.Stat(p); err != nil || fi.IsDir() {
log.Debug("No chart: %s", err)
return false
}
return true
}
示例13: 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 := util.WorkspaceChartDirectory(homeDir, chartName)
if _, err := os.Stat(chartDir); os.IsNotExist(err) {
log.Die("Could not find chart: %s", chartName)
}
openEditor(chartDir)
}
示例14: TestLintBadPath
func TestLintBadPath(t *testing.T) {
tmpHome := test.CreateTmpHome()
chartName := "badChart"
output := test.CaptureOutput(func() {
Lint(util.WorkspaceChartDirectory(tmpHome, chartName))
})
msg := "Chart found at " + tmpHome + "/workspace/charts/" + chartName + " : false"
test.ExpectContains(t, output, msg)
}
示例15: TestFetch
func TestFetch(t *testing.T) {
tmpHome := test.CreateTmpHome()
test.FakeUpdate(tmpHome)
chartName := "kitchensink"
actual := test.CaptureOutput(func() {
Fetch(chartName, "", tmpHome)
})
workspacePath := util.WorkspaceChartDirectory(tmpHome, chartName)
test.ExpectContains(t, actual, "Fetched chart into workspace "+workspacePath)
}