Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bader Boland committed Feb 10, 2020
1 parent ddbf2e8 commit 6009ee6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
12 changes: 5 additions & 7 deletions cmd/polaris/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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.")
Expand All @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/polaris/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/polaris/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}

},
Expand Down
4 changes: 2 additions & 2 deletions cmd/polaris/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/polaris/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
```
Expand Down

0 comments on commit 6009ee6

Please sign in to comment.