Skip to content

Commit 3b534a4

Browse files
authored
Merge branch 'kubernetes-sigs:main' into add-fake-client-interception
2 parents f264518 + a24b949 commit 3b534a4

File tree

17 files changed

+559
-679
lines changed

17 files changed

+559
-679
lines changed

.github/workflows/golangci-lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
steps:
1717
- uses: actions/setup-go@v4
1818
with:
19-
go-version: '1.19'
19+
go-version: '1.20'
2020
cache: false
2121
- uses: actions/checkout@v3
2222
- name: golangci-lint
2323
uses: golangci/golangci-lint-action@v3
2424
with:
25-
version: v1.51.1
25+
version: v1.52.1
2626
working-directory: ${{matrix.working-directory}}

.golangci.yml

+31-5
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,42 @@ linters-settings:
5959
- pkg: sigs.k8s.io/controller-runtime
6060
alias: ctrl
6161
staticcheck:
62-
go: "1.19"
62+
go: "1.20"
6363
stylecheck:
64-
go: "1.19"
64+
go: "1.20"
6565
depguard:
6666
include-go-root: true
6767
packages:
6868
- io/ioutil # https://go.dev/doc/go1.16#ioutil
69+
revive:
70+
rules:
71+
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
72+
- name: blank-imports
73+
- name: context-as-argument
74+
- name: context-keys-type
75+
- name: dot-imports
76+
- name: error-return
77+
- name: error-strings
78+
- name: error-naming
79+
- name: exported
80+
- name: if-return
81+
- name: increment-decrement
82+
- name: var-naming
83+
- name: var-declaration
84+
- name: range
85+
- name: receiver-naming
86+
- name: time-naming
87+
- name: unexported-return
88+
- name: indent-error-flow
89+
- name: errorf
90+
- name: superfluous-else
91+
- name: unreachable-code
92+
- name: redefines-builtin-id
93+
#
94+
# Rules in addition to the recommended configuration above.
95+
#
96+
- name: bool-literal-in-expr
97+
- name: constant-logical-expr
6998

7099
issues:
71100
max-same-issues: 0
@@ -133,9 +162,6 @@ issues:
133162
- linters:
134163
- gosec
135164
text: "G304: Potential file inclusion via variable"
136-
- linters:
137-
- revive
138-
text: "package-comments: should have a package comment"
139165
- linters:
140166
- dupl
141167
path: _test\.go

examples/builtins/validatingwebhook.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"k8s.io/apimachinery/pkg/runtime"
2525

2626
logf "sigs.k8s.io/controller-runtime/pkg/log"
27+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2728
)
2829

2930
// +kubebuilder:webhook:path=/validate-v1-pod,mutating=false,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=vpod.kb.io
@@ -32,34 +33,34 @@ import (
3233
type podValidator struct{}
3334

3435
// validate admits a pod if a specific annotation exists.
35-
func (v *podValidator) validate(ctx context.Context, obj runtime.Object) error {
36+
func (v *podValidator) validate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
3637
log := logf.FromContext(ctx)
3738
pod, ok := obj.(*corev1.Pod)
3839
if !ok {
39-
return fmt.Errorf("expected a Pod but got a %T", obj)
40+
return nil, fmt.Errorf("expected a Pod but got a %T", obj)
4041
}
4142

4243
log.Info("Validating Pod")
4344
key := "example-mutating-admission-webhook"
4445
anno, found := pod.Annotations[key]
4546
if !found {
46-
return fmt.Errorf("missing annotation %s", key)
47+
return nil, fmt.Errorf("missing annotation %s", key)
4748
}
4849
if anno != "foo" {
49-
return fmt.Errorf("annotation %s did not have value %q", key, "foo")
50+
return nil, fmt.Errorf("annotation %s did not have value %q", key, "foo")
5051
}
5152

52-
return nil
53+
return nil, nil
5354
}
5455

55-
func (v *podValidator) ValidateCreate(ctx context.Context, obj runtime.Object) error {
56+
func (v *podValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
5657
return v.validate(ctx, obj)
5758
}
5859

59-
func (v *podValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
60+
func (v *podValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
6061
return v.validate(ctx, newObj)
6162
}
6263

63-
func (v *podValidator) ValidateDelete(ctx context.Context, obj runtime.Object) error {
64+
func (v *podValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
6465
return v.validate(ctx, obj)
6566
}

examples/crd/pkg/resource.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/webhook"
27+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2728
)
2829

2930
// ChaosPodSpec defines the desired state of ChaosPod
@@ -66,41 +67,41 @@ type ChaosPodList struct {
6667
var _ webhook.Validator = &ChaosPod{}
6768

6869
// ValidateCreate implements webhookutil.validator so a webhook will be registered for the type
69-
func (c *ChaosPod) ValidateCreate() error {
70+
func (c *ChaosPod) ValidateCreate() (admission.Warnings, error) {
7071
log.Info("validate create", "name", c.Name)
7172

7273
if c.Spec.NextStop.Before(&metav1.Time{Time: time.Now()}) {
73-
return fmt.Errorf(".spec.nextStop must be later than current time")
74+
return nil, fmt.Errorf(".spec.nextStop must be later than current time")
7475
}
75-
return nil
76+
return nil, nil
7677
}
7778

7879
// ValidateUpdate implements webhookutil.validator so a webhook will be registered for the type
79-
func (c *ChaosPod) ValidateUpdate(old runtime.Object) error {
80+
func (c *ChaosPod) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
8081
log.Info("validate update", "name", c.Name)
8182

8283
if c.Spec.NextStop.Before(&metav1.Time{Time: time.Now()}) {
83-
return fmt.Errorf(".spec.nextStop must be later than current time")
84+
return nil, fmt.Errorf(".spec.nextStop must be later than current time")
8485
}
8586

8687
oldC, ok := old.(*ChaosPod)
8788
if !ok {
88-
return fmt.Errorf("expect old object to be a %T instead of %T", oldC, old)
89+
return nil, fmt.Errorf("expect old object to be a %T instead of %T", oldC, old)
8990
}
9091
if c.Spec.NextStop.After(oldC.Spec.NextStop.Add(time.Hour)) {
91-
return fmt.Errorf("it is not allowed to delay.spec.nextStop for more than 1 hour")
92+
return nil, fmt.Errorf("it is not allowed to delay.spec.nextStop for more than 1 hour")
9293
}
93-
return nil
94+
return nil, nil
9495
}
9596

9697
// ValidateDelete implements webhookutil.validator so a webhook will be registered for the type
97-
func (c *ChaosPod) ValidateDelete() error {
98+
func (c *ChaosPod) ValidateDelete() (admission.Warnings, error) {
9899
log.Info("validate delete", "name", c.Name)
99100

100101
if c.Spec.NextStop.Before(&metav1.Time{Time: time.Now()}) {
101-
return fmt.Errorf(".spec.nextStop must be later than current time")
102+
return nil, fmt.Errorf(".spec.nextStop must be later than current time")
102103
}
103-
return nil
104+
return nil, nil
104105
}
105106

106107
// +kubebuilder:webhook:path=/mutate-chaosapps-metamagical-io-v1-chaospod,mutating=true,failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=mchaospod.kb.io

go.mod

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module sigs.k8s.io/controller-runtime
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/evanphx/json-patch/v5 v5.6.0
@@ -10,7 +10,7 @@ require (
1010
github.com/google/go-cmp v0.5.9
1111
github.com/onsi/ginkgo/v2 v2.9.2
1212
github.com/onsi/gomega v1.27.6
13-
github.com/prometheus/client_golang v1.14.0
13+
github.com/prometheus/client_golang v1.15.0
1414
github.com/prometheus/client_model v0.3.0
1515
go.uber.org/goleak v1.2.1
1616
go.uber.org/zap v1.24.0
@@ -29,7 +29,7 @@ require (
2929

3030
require (
3131
github.com/beorn7/perks v1.0.1 // indirect
32-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
32+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3333
github.com/davecgh/go-spew v1.1.1 // indirect
3434
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
3535
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
@@ -48,23 +48,24 @@ require (
4848
github.com/josharian/intern v1.0.0 // indirect
4949
github.com/json-iterator/go v1.1.12 // indirect
5050
github.com/mailru/easyjson v0.7.6 // indirect
51-
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
51+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
5252
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5353
github.com/modern-go/reflect2 v1.0.2 // indirect
5454
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5555
github.com/pkg/errors v0.9.1 // indirect
56-
github.com/prometheus/common v0.37.0 // indirect
57-
github.com/prometheus/procfs v0.8.0 // indirect
56+
github.com/prometheus/common v0.42.0 // indirect
57+
github.com/prometheus/procfs v0.9.0 // indirect
58+
github.com/rogpeppe/go-internal v1.10.0 // indirect
5859
github.com/spf13/pflag v1.0.5 // indirect
5960
go.uber.org/atomic v1.7.0 // indirect
6061
go.uber.org/multierr v1.6.0 // indirect
6162
golang.org/x/net v0.8.0 // indirect
62-
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
63+
golang.org/x/oauth2 v0.5.0 // indirect
6364
golang.org/x/term v0.6.0 // indirect
6465
golang.org/x/text v0.8.0 // indirect
6566
golang.org/x/tools v0.7.0 // indirect
6667
google.golang.org/appengine v1.6.7 // indirect
67-
google.golang.org/protobuf v1.28.1 // indirect
68+
google.golang.org/protobuf v1.30.0 // indirect
6869
gopkg.in/inf.v0 v0.9.1 // indirect
6970
gopkg.in/yaml.v2 v2.4.0 // indirect
7071
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)