Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@0a35821d5c230e903fcfe077583637dea1b27b47 # tag=v9.0.0
with:
version: v2.5.0
version: v2.6.1
args: --output.text.print-linter-name=true --output.text.colors=true --timeout 10m
working-directory: ${{matrix.working-directory}}
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- iotamixing
- makezero
- misspell
- modernize
- nakedret
- nilerr
- nolintlint
Expand Down Expand Up @@ -75,6 +76,10 @@ linters:
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
no-unaliased: true
modernize:
disable:
- omitzero
- fmtappendf
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
Expand Down
1 change: 1 addition & 0 deletions examples/crd/pkg/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hack/tools/cmd/gomodcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func modulesFromUpstreamModGraph(upstreamRefList []string) (map[string]map[strin
}

modToVersionToUpstreamRef := make(map[string]map[string]string)
for _, line := range strings.Split(graph, "\n") {
for line := range strings.SplitSeq(graph, "\n") {
ref := strings.SplitN(line, "@", 2)[0]

if _, ok := upstreamRefs[ref]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (blder *TypedBuilder[request]) doWatch() error {
return err
}

if reflect.TypeFor[request]() != reflect.TypeOf(reconcile.Request{}) {
if reflect.TypeFor[request]() != reflect.TypeFor[reconcile.Request]() {
return fmt.Errorf("For() can only be used with reconcile.Request, got %T", *new(request))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func (l *testLogger) Enabled(int) bool {
return true
}

func (l *testLogger) Info(level int, msg string, keysAndValues ...interface{}) {
func (l *testLogger) Info(level int, msg string, keysAndValues ...any) {
}

func (l *testLogger) WithValues(keysAndValues ...interface{}) logr.LogSink {
func (l *testLogger) WithValues(keysAndValues ...any) logr.LogSink {
return l
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/builder/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import (
// WebhookBuilder builds a Webhook.
type WebhookBuilder[T runtime.Object] struct {
apiType runtime.Object
customDefaulter admission.CustomDefaulter
customDefaulter admission.CustomDefaulter //nolint:staticcheck
defaulter admission.Defaulter[T]
customDefaulterOpts []admission.DefaulterOption
customValidator admission.CustomValidator
customValidator admission.CustomValidator //nolint:staticcheck
validator admission.Validator[T]
customPath string
customValidatorCustomPath string
Expand All @@ -64,6 +64,7 @@ func WebhookManagedBy[T runtime.Object](m manager.Manager, object T) *WebhookBui

// WithCustomDefaulter takes an admission.CustomDefaulter interface, a MutatingWebhook with the provided opts (admission.DefaulterOption)
// will be wired for this type.
//
// Deprecated: Use WithDefaulter instead.
func (blder *WebhookBuilder[T]) WithCustomDefaulter(defaulter admission.CustomDefaulter, opts ...admission.DefaulterOption) *WebhookBuilder[T] {
blder.customDefaulter = defaulter
Expand All @@ -79,6 +80,7 @@ func (blder *WebhookBuilder[T]) WithDefaulter(defaulter admission.Defaulter[T],
}

// WithCustomValidator takes a admission.CustomValidator interface, a ValidatingWebhook will be wired for this type.
//
// Deprecated: Use WithValidator instead.
func (blder *WebhookBuilder[T]) WithCustomValidator(validator admission.CustomValidator) *WebhookBuilder[T] {
blder.customValidator = validator
Expand Down Expand Up @@ -306,6 +308,7 @@ func (blder *WebhookBuilder[T]) getValidatingWebhook() (*admission.Webhook, erro
}
w = admission.WithValidator(blder.mgr.GetScheme(), blder.validator)
} else if blder.customValidator != nil {
//nolint:staticcheck
w = admission.WithCustomValidator(blder.mgr.GetScheme(), blder.apiType, blder.customValidator)
}
if w != nil && blder.recoverPanic != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/builder/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ func (*testDefaulter) Default(ctx context.Context, obj *TestDefaulterObject) err
return nil
}

//nolint:staticcheck
var _ admission.CustomDefaulter = &TestCustomDefaulter{}

type TestCustomValidator struct{}
Expand Down Expand Up @@ -1263,6 +1264,7 @@ func (*testValidator) ValidateDelete(ctx context.Context, obj *TestValidatorObje
return nil, nil
}

//nolint:staticcheck
var _ admission.CustomValidator = &TestCustomValidator{}

// TestCustomDefaultValidator for default
Expand All @@ -1286,6 +1288,7 @@ func (*TestCustomDefaultValidator) Default(ctx context.Context, obj runtime.Obje
return nil
}

//nolint:staticcheck
var _ admission.CustomDefaulter = &TestCustomDefaulter{}

// TestCustomDefaultValidator for validation
Expand Down Expand Up @@ -1345,6 +1348,7 @@ func (*TestCustomDefaultValidator) ValidateDelete(ctx context.Context, obj runti
return nil, nil
}

//nolint:staticcheck
var _ admission.CustomValidator = &TestCustomValidator{}

type testValidatorDefaulter struct{}
Expand Down
36 changes: 18 additions & 18 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ var _ = Describe("Cache with transformers", func() {

By("creating the informer cache")
informerCache, err = cache.New(cfg, cache.Options{
DefaultTransform: func(i interface{}) (interface{}, error) {
DefaultTransform: func(i any) (any, error) {
obj := i.(runtime.Object)
Expect(obj).NotTo(BeNil())

Expand All @@ -238,7 +238,7 @@ var _ = Describe("Cache with transformers", func() {
},
ByObject: map[client.Object]cache.ByObject{
&corev1.Pod{}: {
Transform: func(i interface{}) (interface{}, error) {
Transform: func(i any) (any, error) {
obj := i.(runtime.Object)
Expect(obj).NotTo(BeNil())
accessor, err := meta.Accessor(obj)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(out).To(Equal(uKnownPod2))

By("altering a field in the retrieved pod")
m, _ := out.Object["spec"].(map[string]interface{})
m, _ := out.Object["spec"].(map[string]any)
m["activeDeadlineSeconds"] = 4

By("verifying the pods are no longer equal")
Expand Down Expand Up @@ -1954,8 +1954,8 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(sii.HasSynced()).To(BeTrue())

By("adding an event handler listening for object creation which sends the object to a channel")
out := make(chan interface{})
addFunc := func(obj interface{}) {
out := make(chan any)
addFunc := func(obj any) {
out <- obj
}
_, _ = sii.AddEventHandler(kcache.ResourceEventHandlerFuncs{AddFunc: addFunc})
Expand Down Expand Up @@ -2014,8 +2014,8 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(sii.HasSynced()).To(BeTrue())

By("adding an event handler listening for object creation which sends the object to a channel")
out := make(chan interface{})
addFunc := func(obj interface{}) {
out := make(chan any)
addFunc := func(obj any) {
out <- obj
}
_, _ = sii.AddEventHandler(kcache.ResourceEventHandlerFuncs{AddFunc: addFunc})
Expand Down Expand Up @@ -2196,9 +2196,9 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
By("getting a shared index informer for a pod")

pod := &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"containers": []map[string]interface{}{
Object: map[string]any{
"spec": map[string]any{
"containers": []map[string]any{
{
"name": "nginx",
"image": "nginx",
Expand All @@ -2220,8 +2220,8 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(sii.HasSynced()).To(BeTrue())

By("adding an event handler listening for object creation which sends the object to a channel")
out := make(chan interface{})
addFunc := func(obj interface{}) {
out := make(chan any)
addFunc := func(obj any) {
out <- obj
}
_, _ = sii.AddEventHandler(kcache.ResourceEventHandlerFuncs{AddFunc: addFunc})
Expand All @@ -2239,9 +2239,9 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
It("should be able to stop and restart informers", func(ctx SpecContext) {
By("getting a shared index informer for a pod")
pod := &unstructured.Unstructured{
Object: map[string]interface{}{
"spec": map[string]interface{}{
"containers": []map[string]interface{}{
Object: map[string]any{
"spec": map[string]any{
"containers": []map[string]any{
{
"name": "nginx",
"image": "nginx",
Expand Down Expand Up @@ -2294,7 +2294,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
if !ok {
return []string{}
}
m, ok := s.(map[string]interface{})
m, ok := s.(map[string]any)
if !ok {
return []string{}
}
Expand Down Expand Up @@ -2379,8 +2379,8 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(sii.HasSynced()).To(BeTrue())

By("adding an event handler listening for object creation which sends the object to a channel")
out := make(chan interface{})
addFunc := func(obj interface{}) {
out := make(chan any)
addFunc := func(obj any) {
out <- obj
}
_, _ = sii.AddEventHandler(kcache.ResourceEventHandlerFuncs{AddFunc: addFunc})
Expand Down
8 changes: 3 additions & 5 deletions pkg/cache/defaulting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,9 @@ func TestDefaultOptsRace(t *testing.T) {
// Start go routines which re-use the above options struct.
wg := sync.WaitGroup{}
for range 2 {
wg.Add(1)
go func() {
wg.Go(func() {
_, _ = defaultOpts(&rest.Config{}, opts)
wg.Done()
}()
})
}

// Wait for the go routines to finish.
Expand Down Expand Up @@ -509,7 +507,7 @@ func TestDefaultConfigConsidersAllFields(t *testing.T) {
},
)

for i := 0; i < 100; i++ {
for range 100 {
fuzzed := Config{}
f.Fuzz(&fuzzed)

Expand Down
6 changes: 2 additions & 4 deletions pkg/cache/delegating_by_gvk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ func (dbt *delegatingByGVKCache) Start(ctx context.Context) error {
errs := make(chan error)
for idx := range allCaches {
cache := allCaches[idx]
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
if err := cache.Start(ctx); err != nil {
errs <- err
}
}()
})
}

select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/informer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (ic *informerCache) IndexField(ctx context.Context, obj client.Object, fiel
}

func indexByField(informer Informer, field string, extractValue client.IndexerFunc) error {
indexFunc := func(objRaw interface{}) ([]string, error) {
indexFunc := func(objRaw any) ([]string, error) {
// TODO(directxman12): check if this is the correct type?
obj, isObj := objRaw.(client.Object)
if !isObj {
Expand Down
16 changes: 7 additions & 9 deletions pkg/cache/internal/cache_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"reflect"
"slices"

apierrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -109,7 +110,7 @@ func (c *CacheReader) Get(_ context.Context, key client.ObjectKey, out client.Ob

// List lists items out of the indexer and writes them to out.
func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...client.ListOption) error {
var objs []interface{}
var objs []any
var err error

listOpts := client.ListOptions{}
Expand Down Expand Up @@ -186,10 +187,10 @@ func (c *CacheReader) List(_ context.Context, out client.ObjectList, opts ...cli
return nil
}

func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace string) ([]interface{}, error) {
func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace string) ([]any, error) {
var (
err error
objs []interface{}
objs []any
vals []string
)
indexers := indexer.GetIndexers()
Expand All @@ -213,17 +214,14 @@ func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace st
if !exist {
return nil, fmt.Errorf("index with name %s does not exist", indexName)
}
filteredObjects := make([]interface{}, 0, len(objs))
filteredObjects := make([]any, 0, len(objs))
for _, obj := range objs {
vals, err = fn(obj)
if err != nil {
return nil, err
}
for _, val := range vals {
if val == indexedValue {
filteredObjects = append(filteredObjects, obj)
break
}
if slices.Contains(vals, indexedValue) {
filteredObjects = append(filteredObjects, obj)
}
}
if len(filteredObjects) == 0 {
Expand Down
6 changes: 2 additions & 4 deletions pkg/cache/internal/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,9 @@ func (ip *Informers) startInformerLocked(cacheEntry *Cache) {
return
}

ip.waitGroup.Add(1)
go func() {
defer ip.waitGroup.Done()
ip.waitGroup.Go(func() {
cacheEntry.Start(ip.ctx.Done())
}()
})
}

func (ip *Informers) waitForStarted(ctx context.Context) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/certwatcher/certwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ var _ = Describe("CertWatcher", func() {
})

func writeCerts(certPath, keyPath, ip string) error {
var priv interface{}
var priv any
var err error
priv, err = rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/apiutil/apimachinery.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (t targetZeroingDecoder) Decode(data []byte, defaults *schema.GroupVersionK
}

// zero zeros the value of a pointer.
func zero(x interface{}) {
func zero(x any) {
if x == nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/apiutil/restmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func TestLazyRestMapperProvider(t *testing.T) {

wg := sync.WaitGroup{}
wg.Add(50)
for i := 0; i < 50; i++ {
for range 50 {
go func() {
defer wg.Done()
httpClient, err := rest.HTTPClientFor(restCfg)
Expand Down Expand Up @@ -811,7 +811,7 @@ type errorMatcher struct {
message string
}

func (e *errorMatcher) Match(actual interface{}) (success bool, err error) {
func (e *errorMatcher) Match(actual any) (success bool, err error) {
if actual == nil {
return false, nil
}
Expand All @@ -824,10 +824,10 @@ func (e *errorMatcher) Match(actual interface{}) (success bool, err error) {
return e.checkFunc(actualErr), nil
}

func (e *errorMatcher) FailureMessage(actual interface{}) (message string) {
func (e *errorMatcher) FailureMessage(actual any) (message string) {
return format.Message(actual, fmt.Sprintf("to be %s error", e.message))
}

func (e *errorMatcher) NegatedFailureMessage(actual interface{}) (message string) {
func (e *errorMatcher) NegatedFailureMessage(actual any) (message string) {
return format.Message(actual, fmt.Sprintf("not to be %s error", e.message))
}
Loading
Loading