Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
micahhausler committed Jan 16, 2017
0 parents commit 6aa3064
Show file tree
Hide file tree
Showing 19 changed files with 1,224 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Coverage output
coverage.out
profile.cov

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

# vim files
*.swp

# Pycharm/IDEA
.idea/
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Coverage
coverage.out

# Build artifacts
helm-value-store

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

.idea/

# Ignore vim files
*.swp
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sudo: false
language: go

go:
- 1.7
- tip

before_install:
- go get -u golang.org/x/tools/cmd/cover
- go get -u github.com/kardianos/govendor

script:
- make test
- make test-cover
- make build
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Skuid, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
REPO=helm-value-store
SHA = $(shell git rev-parse --short HEAD)
GO_PKGS=$$(go list ./... | grep -v vendor)

.PHONY: setup fmt test test-cover vendored clean

all: test build

setup:
go get golang.org/x/tools/cmd/cover
go get -u github.com/kardianos/govendor
go get -u github.com/golang/lint/golint

fmt:
go fmt $(GO_PKGS)

build: fmt
go build

test: fmt
go test -race $(GO_PKGS)

test-cover: fmt
go test -cover $(GO_PKGS)

vendored:
# Check if any dependencies are missing
test $$(govendor list +e |wc -l | awk '{print $$1}') -lt 1

clean:
rm ./$(REPO)
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# helm-value-store

A helm plugin for working with helm deployment values.

## Installation

### Prerequisite

You must have go installed

```bash
brew install go
mkdir -p ~/go/{src,bin,pkg}
export GOPATH=~/go
export PATH="$PATH:~/go/bin"

# Append GOPATH to profile
echo 'export GOPATH=~/go' | tee -a ~/.profile
echo 'export PATH="$PATH:~/go/bin"' | tee -a ~/.profile
```

### Install helm-value-store

```bash
go get github.com/skuid/helm-value-store
```

## Usage

```
$ helm-value-store
A tool loading/backing up AWS Dynamo demo data
Usage:
helm-value-store [command]
Available Commands:
install install a release
list list the releases
load load a json file of releases
version Print the version number
Use "helm-value-store [command] --help" for more information about a command.
```

## Development

Always, always, always run `go fmt ./...` before committing!

### Running the tests

```bash
go get golang.org/x/tools/cmd/cover

make test
```

See the html output of the coverage information

```bash
make test-cover
```

### Updating dependencies

```bash
go get -u github.com/kardianos/govendor

govendor add +external
```

### Linting

Perfect linting is not required, but it is helpful for new people coming to the code.

```
go get -u github.com/golang/lint/golint
golint ./
golint ./render
```

## License

MIT License (see [LICENSE](/LICENSE))
60 changes: 60 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cmd

import (
"fmt"
"os"
"text/template"

"github.com/skuid/helm-value-store/dynamo"
"github.com/spf13/cobra"
)

type installCmdArgs struct {
timeout int64
dryRun bool
table string
selector selectorSet
}

var installArgs = installCmdArgs{}

var installCmd = &cobra.Command{
Use: "install",
Short: "install a release",
Run: install,
}

var installTmpl *template.Template

func init() {
RootCmd.AddCommand(installCmd)
installCmd.Flags().StringVar(&installArgs.table, "table", "helm-charts", "Name of table")
installCmd.Flags().Int64Var(&installArgs.timeout, "timeout", 300, "time in seconds to wait for any individual kubernetes operation (like Jobs for hooks)")
installCmd.Flags().BoolVar(&installArgs.dryRun, "dry-run", false, "simulate an upgrade")
installCmd.Flags().VarP(&installArgs.selector, "selector", "s", `The selectors to use. Each selector should have the format "k=v".
Can be specified multiple times, or a comma-separated list.`)

var err error
installTmpl, err = template.New("InstallCmd").Parse(
"REGION={{.Labels.region}} ENV={{.Labels.environment}} helm install{{ if .Name }} --name {{.Name}}{{ end }}{{if .Namespace}} --namespace {{.Namespace}}{{end}}{{if .Version}} --version {{.Version}}{{end}} {{.Chart}} \n",
)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}

func install(cmd *cobra.Command, args []string) {
fmt.Println("Installing releases:")
fmt.Println("")

rs, err := dynamo.NewReleaseStore(installArgs.table)
exitOnErr(err)

releases, err := rs.List(installArgs.selector.ToMap())
exitOnErr(err)

for _, r := range releases {
installTmpl.Execute(os.Stdout, &r)
}
}
59 changes: 59 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cmd

import (
"fmt"
"os"
"strings"
"text/tabwriter"

"github.com/skuid/helm-value-store/dynamo"
"github.com/spf13/cobra"
)

type listCmdArgs struct {
table string
selector selectorSet
}

var listArgs = &listCmdArgs{}

var listCmd = &cobra.Command{
Use: "list",
Short: "list the releases",
Run: list,
}

func init() {
RootCmd.AddCommand(listCmd)
listCmd.Flags().StringVar(&listArgs.table, "table", "helm-charts", "Name of table")
listCmd.Flags().VarP(&listArgs.selector, "selector", "s", `The selectors to use. Each selector should have the format "k=v".
Can be specified multiple times, or a comma-separated list.`)
}

func list(cmd *cobra.Command, args []string) {
rs, err := dynamo.NewReleaseStore(listArgs.table)
exitOnErr(err)

releases, err := rs.List(listArgs.selector.ToMap())
exitOnErr(err)

w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
columns := []string{
"UniqueId", "Name", "Namespace", "Chart", "Version", "Labels",
}

fmt.Fprintln(w, strings.Join(columns, "\t"))

for _, release := range releases {
columns := []string{
release.UniqueID,
release.Name,
release.Namespace,
release.Chart,
release.Version,
fmt.Sprintf("%s", release.Labels),
}
fmt.Fprintln(w, strings.Join(columns, "\t"))
}
w.Flush()
}
Loading

0 comments on commit 6aa3064

Please sign in to comment.