Skip to content

Commit

Permalink
style: gofmt, gomodtidy, ... (#99)
Browse files Browse the repository at this point in the history
* chore: remove kubewebhook v0.11.0 from go.mod

* style: gofmt, gomodtidy, ...
  • Loading branch information
estahn committed Aug 16, 2021
1 parent 1b809f2 commit 9558e6f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yml
@@ -0,0 +1,22 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest

# don't run this on the master branch
if: github.ref != 'refs/heads/master'

steps:
- uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- uses: actions/setup-python@v2.2.2
- uses: pre-commit/action@v2.0.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: 38b88246ccc552bffaaf54259d064beeee434539 # v4.0.1
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -22,6 +22,11 @@ repos:
# - id: doctoc
# args: ['--title', '## Table of Contents']
- repo: https://github.com/golangci/golangci-lint
rev: v1.41.1
rev: a20748098fb3cb4b69f6b6ebb7809e7741122ef8 # v1.41.1
hooks:
- id: golangci-lint
- repo: https://github.com/dnephin/pre-commit-golang
rev: ac0f6582d2484b3aa90b05d568e70f9f3c1374c7 # v0.0.17
hooks:
- id: go-mod-tidy
- id: go-fmt
2 changes: 1 addition & 1 deletion docs/configuration.md
Expand Up @@ -27,7 +27,7 @@ The option `logLevel` & `logFormat` allow to adjust the verbosity and format (e.

The option `imageSwapPolicy` (default: `exists`) defines the mutation strategy used.

* `always`: Will always swap the image regardless of the image existence in the target registry.
* `always`: Will always swap the image regardless of the image existence in the target registry.
This can result in pods ending in state ImagePullBack if images fail to be copied to the target registry.
* `exists`: Only swaps the image if it exits in the target registry.
This can result in pods pulling images from the source registry, e.g. the first pod pulls
Expand Down
4 changes: 1 addition & 3 deletions mkdocs.yml
Expand Up @@ -55,9 +55,7 @@ markdown_extensions:
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- pymdownx.emoji
- pymdownx.highlight:
use_pygments: true
linenums_style: pymdownx-inline
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Expand Up @@ -21,8 +21,8 @@ func TestConfigParses(t *testing.T) {
expCfg: Config{},
},
{
name: "should render multiple filters",
cfg: `
name: "should render multiple filters",
cfg: `
source:
filters:
- jmespath: "obj.metadata.namespace == 'kube-system'"
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/types.go
Expand Up @@ -45,4 +45,4 @@ func ParseImageCopyPolicy(p string) (ImageCopyPolicy, error) {
return ImageCopyPolicyForce, nil
}
return ImageCopyPolicyDelayed, fmt.Errorf("unknown image copy policy string: '%s', defaulting to delayed", p)
}
}
12 changes: 6 additions & 6 deletions pkg/webhook/image_swapper.go
Expand Up @@ -32,7 +32,7 @@ type ImageSwapper struct {
filters []config.JMESPathFilter

// copier manages the jobs copying the images to the target registry
copier *pond.WorkerPool
copier *pond.WorkerPool

imageSwapPolicy types.ImageSwapPolicy
imageCopyPolicy types.ImageCopyPolicy
Expand All @@ -41,9 +41,9 @@ type ImageSwapper struct {
// NewImageSwapper returns a new ImageSwapper initialized.
func NewImageSwapper(registryClient registry.Client, filters []config.JMESPathFilter, imageSwapPolicy types.ImageSwapPolicy, imageCopyPolicy types.ImageCopyPolicy) kwhmutating.Mutator {
return &ImageSwapper{
registryClient: registryClient,
filters: filters,
copier: pond.New(100, 1000),
registryClient: registryClient,
filters: filters,
copier: pond.New(100, 1000),
imageSwapPolicy: imageSwapPolicy,
imageCopyPolicy: imageCopyPolicy,
}
Expand All @@ -53,8 +53,8 @@ func NewImageSwapperWebhook(registryClient registry.Client, filters []config.JME
imageSwapper := NewImageSwapper(registryClient, filters, imageSwapPolicy, imageCopyPolicy)
mt := kwhmutating.MutatorFunc(imageSwapper.Mutate)
mcfg := kwhmutating.WebhookConfig{
ID: "k8s-image-swapper",
Obj: &corev1.Pod{},
ID: "k8s-image-swapper",
Obj: &corev1.Pod{},
Mutator: mt,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/image_swapper_test.go
Expand Up @@ -154,14 +154,14 @@ func TestFilterMatch(t *testing.T) {
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "nginx",
Name: "nginx",
Image: "nginx:latest",
},
},
},
},
Container: corev1.Container{
Name: "nginx",
Name: "nginx",
Image: "nginx:latest",
},
}
Expand Down

0 comments on commit 9558e6f

Please sign in to comment.