Skip to content

Commit

Permalink
get-manifests command and diff command RD-33 RD-31 (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Reed committed Dec 8, 2021
1 parent 28ed9cf commit 0e7e3d0
Show file tree
Hide file tree
Showing 16 changed files with 1,037 additions and 59 deletions.
46 changes: 43 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"gopkg.in/yaml.v3"
Expand All @@ -45,13 +46,16 @@ var (
createNamespaces bool
// inPlaceConvert contains the boolean flag to update the course file in place
inPlaceConvert bool
// noColor contains the boolean flag to disable color output
noColor bool
)

func init() {
rootCmd.PersistentFlags().BoolVarP(&runAll, "run-all", "a", false, "Install every release in the course file")
rootCmd.PersistentFlags().StringSliceVarP(&onlyRun, "only", "o", nil, "Only install this list of releases. Can be passed multiple times.")
rootCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Implies helm --dry-run --debug and skips any hooks")
rootCmd.PersistentFlags().BoolVar(&createNamespaces, "create-namespaces", true, "If true, allow reckoner to create namespaces.")
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "If true, don't colorize output.")

convertCmd.Flags().BoolVarP(&inPlaceConvert, "in-place", "i", false, "If specified, will update the file in place, otherwise outputs to stdout.")

Expand All @@ -61,6 +65,7 @@ func init() {
rootCmd.AddCommand(templateCmd)
rootCmd.AddCommand(diffCmd)
rootCmd.AddCommand(lintCmd)
rootCmd.AddCommand(getManifestsCmd)

klog.InitFlags(nil)
pflag.CommandLine.AddGoFlag(flag.CommandLine.Lookup("v"))
Expand Down Expand Up @@ -108,21 +113,51 @@ var templateCmd = &cobra.Command{
if err != nil {
klog.Fatal(err)
}
tmpl, err := client.Template()
tmpl, err := client.TemplateAll()
if err != nil {
klog.Fatal(err)
}
fmt.Println(tmpl)
},
}

var getManifestsCmd = &cobra.Command{
Use: "get-manifests",
Short: "get-manifests <course file>",
Long: "Gets the manifests currently in the cluster.",
PreRunE: validateArgs,
Run: func(cmd *cobra.Command, args []string) {
client, err := reckoner.NewClient(courseFile, version, runAll, onlyRun, false, true, false, courseSchema)
if err != nil {
color.Red(err.Error())
os.Exit(1)
}
manifests, err := client.GetManifests()
if err != nil {
color.Red(err.Error())
os.Exit(1)
}
fmt.Print(manifests)
},
}

var diffCmd = &cobra.Command{
Use: "diff",
Short: "diff <course file>",
Long: "Diffs the currently defined release and the one in the cluster",
PreRunE: validateArgs,
Run: func(cmd *cobra.Command, args []string) {
// TODO: Call Diff
client, err := reckoner.NewClient(courseFile, version, runAll, onlyRun, false, true, false, courseSchema)
if err != nil {
klog.Fatal(err)
}
if err := client.UpdateHelmRepos(); err != nil {
klog.Fatal(err)
}
err = client.Diff()
if err != nil {
klog.Fatal(err)
}
},
}

Expand Down Expand Up @@ -163,7 +198,10 @@ var convertCmd = &cobra.Command{
klog.Fatal(err)
}
defer f.Close()
f.Truncate(0)
err = f.Truncate(0)
if err != nil {
klog.Fatalf("failed to truncate course file \"%s\": %s", courseFile, err)
}
w = f
}
e := yaml.NewEncoder(w)
Expand All @@ -182,6 +220,8 @@ var convertCmd = &cobra.Command{
// file that exists
func validateArgs(cmd *cobra.Command, args []string) (err error) {
courseFile, err = reckoner.ValidateArgs(runAll, onlyRun, args)
color.NoColor = noColor
klog.V(3).Infof("colorize output: %v", !noColor)

return err
}
Expand Down
32 changes: 18 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ module github.com/fairwindsops/reckoner
go 1.17

require (
github.com/Masterminds/semver v1.5.0
github.com/spf13/cobra v1.1.3
github.com/Masterminds/semver/v3 v3.1.1
github.com/fatih/color v1.13.0
github.com/sergi/go-diff v1.1.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/thoas/go-funk v0.9.1
github.com/xeipuuv/gojsonschema v1.2.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.2
Expand All @@ -18,7 +20,7 @@ require (
)

require (
cloud.google.com/go v0.54.0 // indirect
cloud.google.com/go v0.81.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.1 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.5 // indirect
Expand All @@ -29,27 +31,29 @@ require (
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/go-logr/logr v0.3.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.1 // indirect
github.com/imdario/mergo v0.3.10 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
golang.org/x/text v0.3.4 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/klog/v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 0e7e3d0

Please sign in to comment.