// 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) } // Copy the source chart to the workspace. We ruthlessly overwrite in // this case. dest := filepath.Join(home, WorkspaceChartPath, chartName) 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) } }
// 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(chartName, home, namespace string, force bool, dryRun bool) { 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 := filepath.Join(home, WorkspaceChartPath, 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, 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) } log.Info("Done") PrintREADME(chartName, home) }
// 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) { 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) } log.Info("Running `kubectl delete` ...") if err := deleteChart(c, namespace); err != nil { log.Die("Failed to completely delete chart: %s", err) } log.Info("Done") }