-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a86e57
commit 618a356
Showing
12 changed files
with
780 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: | ||
go build github.com/harbur/tide/cmd/tide | ||
|
||
cross: | ||
mkdir -p build | ||
gox --os windows --os linux --os darwin --arch 386 --arch amd64 github.com/harbur/tide/cmd/tide | ||
mv tide_{darwin,linux,windows}_* build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const applyDesc = ` | ||
This command applys a chart archive. | ||
The apply argument must be either a relative | ||
path to a chart directory or the name of a | ||
chart in the current working directory. | ||
` | ||
|
||
var applyCmd = &cobra.Command{ | ||
Use: "apply [CHART]", | ||
Short: "apply a chart archive.", | ||
Long: applyDesc, | ||
RunE: runApply, | ||
} | ||
|
||
func runApply(cmd *cobra.Command, args []string) error { | ||
log.SetOutput(ioutil.Discard) | ||
setupInstallEnv(args) | ||
manifest, _ := readManifest(installArg) | ||
execute("apply", manifest) | ||
return nil | ||
} | ||
|
||
func setupApplyEnv(args []string) { | ||
if len(args) > 0 { | ||
installArg = args[0] | ||
} else { | ||
fatalf("This command needs at least one argument, the name of the chart.") | ||
} | ||
|
||
} | ||
|
||
func init() { | ||
applyCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose apply") | ||
RootCommand.AddCommand(applyCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/kubernetes/helm/cmd/tiller/environment" | ||
chartutil "github.com/kubernetes/helm/pkg/chart" | ||
|
||
"github.com/kubernetes/helm/pkg/helm" | ||
) | ||
|
||
var env = environment.New() | ||
|
||
func readManifest(installArg string) (string, error) { | ||
chfi, err := chartutil.LoadChart(installArg) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
chpb, err := helm.ChartToProto(chfi) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
vals, err := helm.ValuesToProto(chfi) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
overrides := map[string]interface{}{ | ||
"Release": map[string]interface{}{ | ||
"Name": "name", | ||
"Time": "ts", | ||
"Namespace": "s.env.Namespace", | ||
"Service": "Tide", | ||
}, | ||
"Chart": "req.Chart.Metadata", | ||
} | ||
|
||
files, err := env.EngineYard.Default().Render(chpb, vals, overrides) | ||
|
||
b := bytes.NewBuffer(nil) | ||
for name, file := range files { | ||
// Ignore empty documents because the Kubernetes library can't handle | ||
// them. | ||
if len(file) > 0 { | ||
b.WriteString("\n---\n# Source: " + name + "\n") | ||
b.WriteString(file) | ||
} | ||
} | ||
|
||
manifest := b.String() | ||
return manifest, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
// "bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
func execute(command string, manifest string) { | ||
cmd := exec.Command("kubectl", command, "-f", "-") | ||
|
||
stdin, err := cmd.StdinPipe() | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
|
||
if err = cmd.Start(); err != nil { | ||
fmt.Println("An error occured: ", err) | ||
} | ||
|
||
io.WriteString(stdin, manifest) | ||
stdin.Close() | ||
cmd.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const installDesc = ` | ||
This command installs a chart archive. | ||
The install argument must be either a relative | ||
path to a chart directory or the name of a | ||
chart in the current working directory. | ||
` | ||
|
||
// install flags & args | ||
var ( | ||
// installArg is the name or relative path of the chart to install | ||
installArg string | ||
// verbose enables verbose output | ||
verbose bool | ||
) | ||
|
||
var installCmd = &cobra.Command{ | ||
Use: "install [CHART]", | ||
Short: "install a chart archive.", | ||
Long: installDesc, | ||
RunE: runInstall, | ||
} | ||
|
||
func runInstall(cmd *cobra.Command, args []string) error { | ||
log.SetOutput(ioutil.Discard) | ||
setupInstallEnv(args) | ||
manifest, _ := readManifest(installArg) | ||
execute("create", manifest) | ||
return nil | ||
} | ||
|
||
func setupInstallEnv(args []string) { | ||
if len(args) > 0 { | ||
installArg = args[0] | ||
} else { | ||
fatalf("This command needs at least one argument, the name of the chart.") | ||
} | ||
} | ||
|
||
func fatalf(format string, args ...interface{}) { | ||
fmt.Printf("fatal: %s\n", fmt.Sprintf(format, args...)) | ||
os.Exit(0) | ||
} | ||
|
||
func init() { | ||
installCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose install") | ||
RootCommand.AddCommand(installCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const renderDesc = ` | ||
This command renders a chart archive. | ||
The render argument must be either a relative | ||
path to a chart directory or the name of a | ||
chart in the current working directory. | ||
` | ||
|
||
var renderCmd = &cobra.Command{ | ||
Use: "render [CHART]", | ||
Short: "render a chart archive.", | ||
Long: renderDesc, | ||
RunE: runRender, | ||
} | ||
|
||
func runRender(cmd *cobra.Command, args []string) error { | ||
log.SetOutput(ioutil.Discard) | ||
setupInstallEnv(args) | ||
manifest, _ := readManifest(installArg) | ||
fmt.Printf("%s\n", manifest) | ||
return nil | ||
} | ||
|
||
func setupRenderEnv(args []string) { | ||
if len(args) > 0 { | ||
installArg = args[0] | ||
} else { | ||
fatalf("This command needs at least one argument, the name of the chart.") | ||
} | ||
} | ||
|
||
func init() { | ||
renderCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose render") | ||
RootCommand.AddCommand(renderCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var stdout = os.Stdout | ||
var helmHome string | ||
|
||
// flagVerbose is a signal that the user wants additional output. | ||
var flagVerbose bool | ||
|
||
var globalUsage = `The Kubernetes package renderer | ||
Tide is a standalone CLI tool to render Kubernetes packages with the Helm format. | ||
It is a stateless tool, which uses the current directory to render the templates | ||
and either outputs them for further usage (e.g. pipeline with kubectl or other | ||
scripting methods) or installs them directly to Kubernetes. | ||
Common actions from this point on include: | ||
- tide search: search for charts | ||
- tide fetch: download a chart to your local directory to view | ||
- tide install: upload the chart to Kubernetes | ||
- tide list: list releases of charts | ||
` | ||
|
||
// RootCommand is the top-level command for Helm. | ||
var RootCommand = &cobra.Command{ | ||
Use: "tide", | ||
Short: "The Kubernetes package renderer.", | ||
Long: globalUsage, | ||
} | ||
|
||
func init() { | ||
RootCommand.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "enable verbose output") | ||
} | ||
|
||
func main() { | ||
RootCommand.Execute() | ||
} | ||
|
||
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error { | ||
if actualNum != expectedNum { | ||
arg := "arguments" | ||
if expectedNum == 1 { | ||
arg = "argument" | ||
} | ||
return fmt.Errorf("This command needs %v %s: %s", expectedNum, arg, strings.Join(requiredArgs, ", ")) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const uninstallDesc = ` | ||
This command uninstalls a chart archive. | ||
The uninstall argument must be either a relative | ||
path to a chart directory or the name of a | ||
chart in the current working directory. | ||
` | ||
|
||
var uninstallCmd = &cobra.Command{ | ||
Use: "uninstall [CHART]", | ||
Short: "uninstall a chart archive.", | ||
Long: uninstallDesc, | ||
RunE: runUninstall, | ||
} | ||
|
||
func runUninstall(cmd *cobra.Command, args []string) error { | ||
log.SetOutput(ioutil.Discard) | ||
setupInstallEnv(args) | ||
manifest, _ := readManifest(installArg) | ||
execute("delete", manifest) | ||
return nil | ||
} | ||
|
||
func setupUninstallEnv(args []string) { | ||
if len(args) > 0 { | ||
installArg = args[0] | ||
} else { | ||
fatalf("This command needs at least one argument, the name of the chart.") | ||
} | ||
|
||
} | ||
|
||
func init() { | ||
uninstallCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose render") | ||
RootCommand.AddCommand(uninstallCmd) | ||
} |
Oops, something went wrong.