Skip to content
Open
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}}
7 changes: 7 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,9 @@ linters:
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
no-unaliased: true
modernize:
disable:
- omitzero
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
Expand Down Expand Up @@ -125,6 +129,9 @@ linters:
- linters:
- staticcheck
text: 'SA1019: .*The component config package has been deprecated and will be removed in a future release.'
- linters:
- staticcheck
text: 'SA1019: .* is deprecated: .* is deprecated, use .* instead '
# With Go 1.16, the new embed directive can be used with an un-named import,
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
# This directive allows the embed package to be imported with an underscore everywhere.
Expand Down
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
2 changes: 2 additions & 0 deletions pkg/builder/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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))
}
12 changes: 6 additions & 6 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func deleteNamespace(ctx context.Context, ns *corev1.Namespace) {
Expect(err).NotTo(HaveOccurred())

WAIT_LOOP:
for i := 0; i < 10; i++ {
for range 10 {
ns, err = clientset.CoreV1().Namespaces().Get(ctx, ns.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
// success!
Expand Down Expand Up @@ -1215,7 +1215,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
dep, err := clientset.AppsV1().Deployments(dep.Namespace).Create(ctx, dep, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
dep.APIVersion = appsv1.SchemeGroupVersion.String()
dep.Kind = reflect.TypeOf(dep).Elem().Name()
dep.Kind = reflect.TypeFor[appsv1.Deployment]().Name()
depUnstructured, err := toUnstructured(dep)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -4133,7 +4133,7 @@ var _ = Describe("Patch", func() {
Expect(err).NotTo(HaveOccurred())

By("returning a patch with data only containing the annotation change")
Expect(data).To(Equal([]byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"%s"}}}`, annotationKey, annotationValue))))
Expect(data).To(Equal(fmt.Appendf(nil, `{"metadata":{"annotations":{"%s":"%s"}}}`, annotationKey, annotationValue)))
})

It("creates a merge patch with the modifications applied during the mutation, using optimistic locking", func() {
Expand All @@ -4158,7 +4158,7 @@ var _ = Describe("Patch", func() {
Expect(err).NotTo(HaveOccurred())

By("returning a patch with data containing the annotation change and the resourceVersion change")
Expect(data).To(Equal([]byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"%s"},"resourceVersion":"%s"}}`, annotationKey, annotationValue, cm.ResourceVersion))))
Expect(data).To(Equal(fmt.Appendf(nil, `{"metadata":{"annotations":{"%s":"%s"},"resourceVersion":"%s"}}`, annotationKey, annotationValue, cm.ResourceVersion)))
})
})

Expand Down Expand Up @@ -4234,9 +4234,9 @@ var _ = Describe("Patch", func() {
Expect(err).NotTo(HaveOccurred())

By("returning a patch with data containing the image change and the resourceVersion change")
Expect(data).To(Equal([]byte(fmt.Sprintf(`{"metadata":{"resourceVersion":"%s"},`+
Expect(data).To(Equal(fmt.Appendf(nil, `{"metadata":{"resourceVersion":"%s"},`+
`"spec":{"template":{"spec":{"$setElementOrder/containers":[{"name":"main"},{"name":"sidecar"}],"containers":[{"image":"foo:v2","name":"main"}]}}}}`,
dep.ResourceVersion))))
dep.ResourceVersion)))
})
})
})
Expand Down
Loading