From 6009ee67fa702c8f292756e5fef16a2e15a36f6a Mon Sep 17 00:00:00 2001 From: Bader Boland Date: Mon, 10 Feb 2020 08:27:08 -0500 Subject: [PATCH] Cleanup code --- cmd/polaris/audit.go | 12 +++++------- cmd/polaris/dashboard.go | 2 +- cmd/polaris/root.go | 6 +++--- cmd/polaris/version.go | 4 ++-- cmd/polaris/webhook.go | 2 +- docs/usage.md | 4 ++-- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cmd/polaris/audit.go b/cmd/polaris/audit.go index 46ecb1b6..943e35c5 100644 --- a/cmd/polaris/audit.go +++ b/cmd/polaris/audit.go @@ -22,11 +22,11 @@ import ( "net/http" "os" - "github.com/spf13/cobra" - "github.com/sirupsen/logrus" - "github.com/fairwindsops/polaris/pkg/validator" conf "github.com/fairwindsops/polaris/pkg/config" "github.com/fairwindsops/polaris/pkg/kube" + "github.com/fairwindsops/polaris/pkg/validator" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" "sigs.k8s.io/yaml" ) @@ -36,7 +36,6 @@ var auditOutputURL string var auditOutputFile string var auditOutputFormat string - func init() { rootCmd.AddCommand(auditCmd) auditCmd.PersistentFlags().StringVar(&auditPath, "audit-path", "", "If specified, audits one or more YAML files instead of a cluster.") @@ -54,9 +53,9 @@ var auditCmd = &cobra.Command{ Long: `Runs a one-time audit.`, Run: func(cmd *cobra.Command, args []string) { if displayName != "" { - c.DisplayName = displayName + config.DisplayName = displayName } - + auditData := runAndReportAudit(c, auditPath, auditOutputFile, auditOutputURL, auditOutputFormat) summary := auditData.GetSummary() @@ -71,7 +70,6 @@ var auditCmd = &cobra.Command{ }, } - func runAndReportAudit(c conf.Configuration, auditPath string, outputFile string, outputURL string, outputFormat string) validator.AuditData { // Create a kubernetes client resource provider k, err := kube.CreateResourceProvider(auditPath) diff --git a/cmd/polaris/dashboard.go b/cmd/polaris/dashboard.go index cd86471e..3385bd74 100644 --- a/cmd/polaris/dashboard.go +++ b/cmd/polaris/dashboard.go @@ -45,7 +45,7 @@ var dashboardCmd = &cobra.Command{ Long: `Runs the webserver for Polaris dashboard.`, Run: func(cmd *cobra.Command, args []string) { if displayName != "" { - c.DisplayName = displayName + config.DisplayName = displayName } var auditDataPtr *validator.AuditData diff --git a/cmd/polaris/root.go b/cmd/polaris/root.go index d0a0b194..1b1dbbff 100644 --- a/cmd/polaris/root.go +++ b/cmd/polaris/root.go @@ -44,7 +44,7 @@ func init() { flag.Parse() pflag.CommandLine.AddGoFlagSet(flag.CommandLine) } -var c conf.Configuration +var config conf.Configuration var rootCmd = &cobra.Command{ Use: "polaris", @@ -58,14 +58,14 @@ var rootCmd = &cobra.Command{ logrus.SetLevel(parsedLevel) } - c, err = conf.ParseFile(configPath) + config, err = conf.ParseFile(configPath) if err != nil { logrus.Errorf("Error parsing config at %s: %v", configPath, err) os.Exit(1) } if disallowExemptions { - c.DisallowExemptions = true + config.DisallowExemptions = true } }, diff --git a/cmd/polaris/version.go b/cmd/polaris/version.go index 9d2b537d..22dcbe21 100644 --- a/cmd/polaris/version.go +++ b/cmd/polaris/version.go @@ -26,8 +26,8 @@ func init() { var versionCmd = &cobra.Command{ Use: "version", - Short: "Prints the current version of the tool.", - Long: `Prints the current version.`, + Short: "Prints the current version.", + Long: `Prints the current version of the tool.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Polaris version:" + version + " Commit:" + commit) }, diff --git a/cmd/polaris/webhook.go b/cmd/polaris/webhook.go index f31f2a17..91d426f1 100644 --- a/cmd/polaris/webhook.go +++ b/cmd/polaris/webhook.go @@ -102,7 +102,7 @@ var webhookCmd = &cobra.Command{ // Should only register controllers that are configured to be scanned logrus.Debug("Registering webhooks to the webhook server") var webhooks []webhook.Webhook - for index, controllerToScan := range c.ControllersToScan { + for index, controllerToScan := range config.ControllersToScan { for innerIndex, supportedAPIType := range controllerToScan.ListSupportedAPIVersions() { webhookName := strings.ToLower(fmt.Sprintf("%s-%d-%d", controllerToScan, index, innerIndex)) hook := fwebhook.NewWebhook(webhookName, mgr, fwebhook.Validator{Config: c}, supportedAPIType) diff --git a/docs/usage.md b/docs/usage.md index 72198035..da46f83d 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -95,7 +95,7 @@ kubectl port-forward --namespace polaris svc/polaris-dashboard 8080:80 ``` ### Helm ```bash -helm repo add fairwinds-stable https://charts.fairwinds.com/stable +helm repo add fairwinds-stable https://charts.fairwindsops.com/stable helm upgrade --install polaris fairwinds-stable/polaris --namespace polaris kubectl port-forward --namespace polaris svc/polaris-dashboard 8080:80 ``` @@ -119,7 +119,7 @@ kubectl apply -f https://github.com/fairwindsops/polaris/releases/latest/downloa ### Helm ```bash -helm repo add fairwindsops-stable https://charts.fairwinds.com/stable +helm repo add fairwindsops-stable https://charts.fairwindsops.com/stable helm upgrade --install polaris fairwindsops-stable/polaris --namespace polaris \ --set webhook.enable=true --set dashboard.enable=false ```