Skip to content

Commit

Permalink
fix lint errors; add tests to CI fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei-led committed Apr 19, 2021
1 parent 2a62976 commit 593b55b
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: decide on tag
id: decide_tag
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test
on:
push:
branches:
- '*'
tags:
- '*'
paths-ignore:
- 'docs/**'
- 'deploy/**'
- '*.md'
pull_request:
branches:
- '*'
env:
GOPROXY: https://proxy.golang.org
CGO_ENABLED: 0
jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- name: Lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.39
golangci-lint run --timeout=5m -v -c .golangci.yaml ./cmd/...
- name: Test
run: |
go test -v ./cmd/...
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ linters-settings:
misspell:
locale: US
lll:
line-length: 140
line-length: 160
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM golang:1.16-alpine AS builder

# curl git bash
RUN apk add --no-cache curl git bash make
COPY --from=golangci/golangci-lint:v1.24-alpine /usr/bin/golangci-lint /usr/bin
COPY --from=golangci/golangci-lint:v1.39-alpine /usr/bin/golangci-lint /usr/bin

#
# ----- Build and Test Image -----
Expand Down
11 changes: 6 additions & 5 deletions cmd/secrets-init-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import (
"strings"

"github.com/doitintl/kube-secrets-init/cmd/secrets-init-webhook/registry"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"

whhttp "github.com/slok/kubewebhook/v2/pkg/http"
whlogrus "github.com/slok/kubewebhook/v2/pkg/log/logrus"
metrics "github.com/slok/kubewebhook/v2/pkg/metrics/prometheus"
whmodel "github.com/slok/kubewebhook/v2/pkg/model"
wh "github.com/slok/kubewebhook/v2/pkg/webhook"
"github.com/slok/kubewebhook/v2/pkg/webhook/mutating"
"github.com/urfave/cli"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -92,7 +90,7 @@ func serveMetrics(addr string) {
}
}

func handlerFor(config mutating.WebhookConfig, recorder *metrics.Recorder, logger *log.Logger) http.Handler {
func handlerFor(config mutating.WebhookConfig, recorder wh.MetricsRecorder, logger *log.Logger) http.Handler {
webhook, err := mutating.NewWebhook(config)
if err != nil {
logger.WithError(err).Fatal("error creating webhook")
Expand Down Expand Up @@ -397,7 +395,10 @@ func before(c *cli.Context) error {
func (mw *mutatingWebhook) secretsMutator(ctx context.Context, ar *whmodel.AdmissionReview, obj metav1.Object) (*mutating.MutatorResult, error) {
switch v := obj.(type) {
case *corev1.Pod:
mw.mutatePod(v, ar.Namespace, ar.DryRun)
err := mw.mutatePod(v, ar.Namespace, ar.DryRun)
if err != nil {
return nil, errors.Wrapf(err, "failed to mutate pod: %s", v.Name)
}
return &mutating.MutatorResult{MutatedObject: v}, nil
default:
return &mutating.MutatorResult{}, nil
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect
github.com/heroku/docker-registry-client v0.0.0-20190909225348-afc9e1acc3d5
github.com/opencontainers/image-spec v1.0.1
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.10.0
github.com/sirupsen/logrus v1.8.1
github.com/slok/kubewebhook/v2 v2.0.0
Expand Down
Loading

0 comments on commit 593b55b

Please sign in to comment.