From 79f3d2cb7437110d79de46befc5a230c1b94cd68 Mon Sep 17 00:00:00 2001 From: Bobby Brennan Date: Fri, 17 May 2019 13:44:19 +0000 Subject: [PATCH] use packr for config.yaml --- .circleci/config.yml | 2 ++ .goreleaser.yml | 1 + Dockerfile | 2 -- README.md | 2 +- config-full.yaml => examples/config-full.yaml | 0 config.yaml => examples/config.yaml | 0 main.go | 2 +- pkg/config/config.go | 10 +++++++++- 8 files changed, 14 insertions(+), 5 deletions(-) rename config-full.yaml => examples/config-full.yaml (100%) rename config.yaml => examples/config.yaml (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index eec97f81..ae1f4499 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,6 +92,8 @@ jobs: - *set_environment_variables - *docker_tag_release - *install_goreleaser + - run: go get -u github.com/gobuffalo/packr/v2/packr2 + - run: packr2 - run: goreleaser workflows: diff --git a/.goreleaser.yml b/.goreleaser.yml index 9e0d4f38..5e8b0132 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,6 +1,7 @@ builds: - env: - CGO_ENABLED=0 + binary: polaris archive: replacements: darwin: Darwin diff --git a/Dockerfile b/Dockerfile index 1264537f..df8218fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,4 @@ COPY --from=build-env /go/src/github.com/reactiveops/polaris/polaris . WORKDIR /opt/app -COPY --from=build-env /go/src/github.com/reactiveops/polaris/config.yaml ./config.yaml - CMD ["polaris"] diff --git a/README.md b/README.md index dbdfef5b..6e9f4bb3 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ helm upgrade --install polaris deploy/helm/polaris/ --namespace polaris --set we ## Configuration -Polaris supports a wide range of validations covering a number of Kubernetes best practices. Here's a sample configuration file that includes all currently supported checks. The [default configuration](https://github.com/reactiveops/polaris/blob/master/config.yaml) contains a number of those checks. This repository also includes a sample [full configuration file](https://github.com/reactiveops/polaris/blob/master/config-full.yaml) that enables all available checks. +Polaris supports a wide range of validations covering a number of Kubernetes best practices. Here's a sample configuration file that includes all currently supported checks. The [default configuration](https://github.com/reactiveops/polaris/blob/master/examples/config.yaml) contains a number of those checks. This repository also includes a sample [full configuration file](https://github.com/reactiveops/polaris/blob/master/examples/config-full.yaml) that enables all available checks. Each check can be assigned a `severity`. Only checks with a severity of `error` or `warning` will be validated. The results of these validations are visible on the dashboard. In the case of the validating webhook, only failures with a severity of `error` will result in a change being rejected. diff --git a/config-full.yaml b/examples/config-full.yaml similarity index 100% rename from config-full.yaml rename to examples/config-full.yaml diff --git a/config.yaml b/examples/config.yaml similarity index 100% rename from config.yaml rename to examples/config.yaml diff --git a/main.go b/main.go index af997db3..be5e4ddd 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,7 @@ func main() { webhookPort := flag.Int("webhook-port", 9876, "Port for the webhook webserver") auditOutputURL := flag.String("output-url", "", "Destination URL to send audit results") auditOutputFile := flag.String("output-file", "", "Destination file for audit results") - configPath := flag.String("config", "config.yaml", "Location of Polaris configuration file") + configPath := flag.String("config", "", "Location of Polaris configuration file") logLevel := flag.String("log-level", logrus.InfoLevel.String(), "Logrus log level") version := flag.Bool("version", false, "Prints the version of Polaris") disableWebhookConfigInstaller := flag.Bool("disable-webhook-config-installer", false, diff --git a/pkg/config/config.go b/pkg/config/config.go index dc68eee5..0ad3f59c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -20,6 +20,7 @@ import ( "io" "io/ioutil" + packr "github.com/gobuffalo/packr/v2" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/yaml" @@ -110,7 +111,14 @@ type SecurityCapabilityLists struct { // ParseFile parses config from a file. func ParseFile(path string) (Configuration, error) { - rawBytes, err := ioutil.ReadFile(path) + configBox := packr.New("Config", "../../examples") + var rawBytes []byte + var err error + if path == "" { + rawBytes, err = configBox.Find("config.yaml") + } else { + rawBytes, err = ioutil.ReadFile(path) + } if err != nil { return Configuration{}, err }