Skip to content
Snippets Groups Projects
Commit d15f26f0 authored by Angus Lees's avatar Angus Lees Committed by GitHub
Browse files

Merge pull request #64 from tomwilkie/diff-exit-code

Make kubecfg diff exit with non-zero code when a diff is found.
parents e515524e 64c0055c
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,8 @@ import (
const flagDiffStrategy = "diff-strategy"
var ErrDiffFound = fmt.Errorf("Differences found.")
func init() {
diffCmd.PersistentFlags().String(flagDiffStrategy, "all", "Diff strategy, all or subset.")
RootCmd.AddCommand(diffCmd)
......@@ -67,6 +69,7 @@ var diffCmd = &cobra.Command{
sort.Sort(utils.AlphabeticalOrder(objs))
diffFound := false
for _, obj := range objs {
desc := fmt.Sprintf("%s/%s", obj.GetKind(), fqName(obj))
log.Debugf("Fetching ", desc)
......@@ -85,9 +88,10 @@ var diffCmd = &cobra.Command{
}
fmt.Fprintln(out, "---")
fmt.Fprintf(out, "- live %s\n+ config %s", desc, desc)
fmt.Fprintf(out, "- live %s\n+ config %s\n", desc, desc)
if liveObj == nil {
fmt.Fprintf(out, "%s doesn't exist on server\n", desc)
diffFound = true
continue
}
......@@ -98,6 +102,7 @@ var diffCmd = &cobra.Command{
diff := gojsondiff.New().CompareObjects(liveObjObject, obj.Object)
if diff.Modified() {
diffFound = true
fcfg := formatter.AsciiFormatterConfig{
Coloring: istty(out),
}
......@@ -112,6 +117,9 @@ var diffCmd = &cobra.Command{
}
}
if diffFound {
return ErrDiffFound
}
return nil
},
}
......
......@@ -16,6 +16,8 @@
package main
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/ksonnet/kubecfg/cmd"
......@@ -32,7 +34,13 @@ func main() {
// errors, like invalid command line flags.
logFmt := cmd.NewLogFormatter(log.StandardLogger().Out)
log.SetFormatter(logFmt)
log.Error(err.Error())
log.Fatal(err.Error())
switch err {
case cmd.ErrDiffFound:
os.Exit(10)
default:
os.Exit(1)
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment