mirror of
https://github.com/FairwindsOps/polaris.git
synced 2026-05-14 05:06:59 +00:00
Cleanup code
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user