Skip to content

Commit

Permalink
v0.3.0: Major refactor for aliases, json logging, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua M. Dotson committed Jan 15, 2018
1 parent be93b87 commit 1853f71
Showing 18 changed files with 667 additions and 839 deletions.
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -34,25 +34,26 @@ Flags:
-a, --appsPath string apps path (default "./apps")
-c, --config string config file (you can instead set MULTIHELM_CONFIG)
-h, --help help for multihelm
-j, --json set logging to JSON format
Use "multihelm [command] --help" for more information about a command.
```

```
$ multihelm license
// Copyright © 2017 Cisco Systems, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Copyright © 2018 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

## Kubernetes Survival Handbook
@@ -178,3 +179,9 @@ multihelm destroy wordpress
# ^ destroy just these app(s),
# even if they are not in `minikube.yaml`
```

### Log to JSON!

```
multihelm status foo --json 2>&1 | jq --slurp
```
63 changes: 9 additions & 54 deletions cmd/apply.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Cisco Systems, Inc.
// Copyright © 2018 Cisco Systems, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,13 +15,8 @@
package cmd

import (
"fmt"

"github.com/codeskyblue/go-sh"
"github.com/spf13/cobra"
"github.com/spf13/viper"

log "github.com/sirupsen/logrus"
)

// applyCmd represents the apply command
@@ -32,15 +27,14 @@ var applyCmd = &cobra.Command{
apps, MultiHelm acts on all apps in your MultiHelm config.`,
Run: func(cmd *cobra.Command, args []string) {
lateInit("apply")
if len(args) > 0 {
for _, arg := range args {
apply(arg)
}
} else {
for _, arg := range viper.GetStringSlice("apps") {
apply(arg)
}
}

apps := getApps(args)

configFile := getConfigFile()
appsPath := getAppsPath()
printRendered := getPrintRendered()

apps.Apply(configFile, appsPath, printRendered)
},
}

@@ -50,42 +44,3 @@ func init() {
applyCmd.PersistentFlags().BoolP("printRendered", "p", false, "print rendered override values")
viper.BindPFlags(applyCmd.PersistentFlags())
}

func apply(app string) {

chart, overrideValues, err := render(app)
if err != nil {
log.WithFields(log.Fields{
"app": app,
"chart": chart,
}).Fatal("Render function failed for app.")
}

if viper.GetBool("printRendered") {
log.WithFields(log.Fields{
"app": app,
"chart": chart,
}).Info("Printing rendered override values for app.")
fmt.Print(string(overrideValues))
log.WithFields(log.Fields{
"app": app,
"chart": chart,
}).Info("Done printing rendered override values for app.")
}

cmd := []interface{}{
"upgrade", app, chart,
"--force",
"--install",
"--recreate-pods",
"--values", "-",
}

err = sh.Command("helm", cmd...).SetInput(string(overrideValues)).Run()
if err != nil {
log.WithFields(log.Fields{
"app": app,
"chart": chart,
}).Fatal("Failed running `helm upgrade` for app.")
}
}
41 changes: 7 additions & 34 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Cisco Systems, Inc.
// Copyright © 2018 Cisco Systems, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,11 +15,8 @@
package cmd

import (
"github.com/codeskyblue/go-sh"
"github.com/spf13/cobra"
"github.com/spf13/viper"

log "github.com/sirupsen/logrus"
)

// destroyCmd represents the destroy command
@@ -30,15 +27,12 @@ var destroyCmd = &cobra.Command{
apps, MultiHelm acts on all apps in your MultiHelm config.`,
Run: func(cmd *cobra.Command, args []string) {
lateInit("destroy")
if len(args) > 0 {
for _, arg := range args {
destroy(arg)
}
} else {
for _, arg := range viper.GetStringSlice("apps") {
destroy(arg)
}
}

apps := getApps(args)

purge := getPurge()

apps.Destroy(purge)
},
}

@@ -48,24 +42,3 @@ func init() {
destroyCmd.PersistentFlags().BoolP("purge", "p", false, "purge this app from Helm Tiller")
viper.BindPFlags(destroyCmd.PersistentFlags())
}

func destroy(app string) {
var cmd []interface{}

if viper.GetBool("purge") {
cmd = []interface{}{
"delete", "--purge", app,
}
} else {
cmd = []interface{}{
"delete", app,
}
}

err := sh.Command("helm", cmd...).Run()
if err != nil {
log.WithFields(log.Fields{
"app": app,
}).Fatal("Failed running `helm destroy` for app.")
}
}
Loading

0 comments on commit 1853f71

Please sign in to comment.