Skip to content

Commit

Permalink
Merge pull request #7 from shivjm/improve-logging
Browse files Browse the repository at this point in the history
Improve logging
  • Loading branch information
shivjm authored Aug 28, 2022
2 parents d631ce7 + 6390dbe commit 23ac549
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: Build and publish to ghcr.io

on:
- push
- pull_request

env:
image: ghcr.io/shivjm/helm-kubeconform-action
go: "1.16.5"
helm: "v3.7.0"
go: "1.18.3"
helm: "v3.9.4"
schema: "master"
kubeconform: "v0.4.11"
kubeconform: "v0.4.14"

jobs:
docker:
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ supplying the environment variables yourself:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
Expand All @@ -40,7 +38,7 @@ supplying the environment variables yourself:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate and validate releases
uses: docker://ghcr.io/shivjm/helm-kubeconform-action:v0.1.0
uses: docker://ghcr.io/shivjm/helm-kubeconform-action:v0.2.0
env:
ADDITIONAL_SCHEMA_PATHS: |
schemas/{{ .ResourceKind }}.json
Expand All @@ -58,11 +56,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0

- name: Generate and validate releases
uses: shivjm/helm-kubeconform-action@v0.1.0
uses: shivjm/helm-kubeconform-action@v0.2.0
with:
additionalSchemaPaths: |
schemas/{{ .ResourceKind }}.json
Expand Down
17 changes: 15 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ inputs:
strict:
description: "Whether to run Kubeconform in strict mode"
default: "true"
required: false
additionalSchemaPaths:
description: "Newline-separated list of paths to look for schemas under, including filename template"
default: ""
required: false
chartsDirectory:
description: "Directory to search for chart directories under"
default: "charts"
required: true
kubernetesVersion:
description: "Specify the version of kubernetes to validated in Kubeconform"
description: "Version of Kubernetes to validate manifests against"
default: "master"
required: false
logLevel:
description: "Only show log messages at or above level (defined by zerolog)"
default: "debug"
required: false
logJson:
description: "Produce JSON log messages"
default: "false"
required: false
runs:
using: "docker"
image: "Dockerfile"
Expand All @@ -28,4 +39,6 @@ runs:
CHARTS_DIRECTORY: "${{ inputs.chartsDirectory }}"
HELM_UPDATE_DEPENDENCIES: "true"
KUBERNETES_VERSION: "${{ inputs.kubernetesVersion }}"
args: [ ]
LOG_LEVEL: "${{ inputs.logLevel }}"
LOG_JSON: "${{ inputs.logJson }}"
args: []
23 changes: 22 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ type Config struct {
Strict bool `env:"KUBECONFORM_STRICT" envDefault:"true"`
AdditionalSchemaPaths []Path `env:"ADDITIONAL_SCHEMA_PATHS" envSeparator:"\n"`
ChartsDirectory Path `env:"CHARTS_DIRECTORY"`
KubernetesVersion string `env:"KUBERNETES_VERSION"`
KubernetesVersion string `env:"KUBERNETES_VERSION" envDefault:"master"`
Kubeconform Path `env:"KUBECONFORM"`
Helm Path `env:"HELM"`
UpdateDependencies bool `env:"HELM_UPDATE_DEPENDENCIES"`
LogLevel string `env:"LOG_LEVEL" envDefault:"debug"`
LogJson bool `env:"LOG_JSON" envDefault:"true"`
}

func main() {
Expand All @@ -50,12 +52,29 @@ func main() {
return
}

if !cfg.LogJson {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
}

level, err := zerolog.ParseLevel(cfg.LogLevel)

if err != nil {
log.Fatal().Stack().Err(err).Msgf("%+v\n", err)
return
}

zerolog.SetGlobalLevel(level)

log.Trace().Msgf("Config: %s", cfg)

additionalSchemaPaths := []string{}

for _, path := range cfg.AdditionalSchemaPaths {
additionalSchemaPaths = append(additionalSchemaPaths, path.path)
}

log.Trace().Msgf("Additional schema paths: %s", additionalSchemaPaths)

feErr := run(cfg, additionalSchemaPaths, cfg.UpdateDependencies)

if feErr != nil {
Expand Down Expand Up @@ -209,6 +228,8 @@ func kubeconformArgs(strict bool, additionalSchemaPaths []string, kubernetesVers
args = append(args, location)
}

log.Trace().Msgf("Arguments: %s", args)

return args
}

Expand Down

0 comments on commit 23ac549

Please sign in to comment.