Skip to content

Commit 83466f4

Browse files
authored
Merge pull request kubernetes-sigs#16 from sttts/sttts-cluster-indexes
✨ Add index support to providers
2 parents 223b19b + 127907d commit 83466f4

File tree

25 files changed

+419
-224
lines changed

25 files changed

+419
-224
lines changed

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ linters:
1212
- errchkjson
1313
- errorlint
1414
- exhaustive
15+
- gci
1516
- ginkgolinter
1617
- goconst
1718
- gocritic
@@ -45,6 +46,17 @@ linters-settings:
4546
disable:
4647
- fieldalignment
4748
- shadow
49+
gci:
50+
custom-order: true
51+
skip-generated: true
52+
sections:
53+
- standard
54+
- default
55+
- prefix(k8s.io)
56+
- prefix(sigs.k8s.io/controller-runtime)
57+
- prefix(github.com/multicluster-runtime)
58+
- blank
59+
- dot
4860
importas:
4961
no-unaliased: true
5062
alias:

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,13 @@ verify-apidiff: $(GO_APIDIFF) ## Check for API differences
183183

184184
go-version: ## Print the go version we use to compile our binaries and images
185185
@echo $(GO_VERSION)
186+
187+
WHAT ?=
188+
imports:
189+
@if [ -n "$(WHAT)" ]; then \
190+
$(GOLANGCI_LINT) run --enable-only=gci --fix --fast $(WHAT); \
191+
else \
192+
for MOD in . $$(git ls-files '**/go.mod' | sed 's,/go.mod,,'); do \
193+
(cd $$MOD; $(GOLANGCI_LINT) run --enable-only=gci --fix --fast); \
194+
done; \
195+
fi

examples/cluster-api/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import (
2222
"os"
2323

2424
"golang.org/x/sync/errgroup"
25+
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
26+
2527
corev1 "k8s.io/api/core/v1"
2628
apierrors "k8s.io/apimachinery/pkg/api/errors"
2729
"k8s.io/apimachinery/pkg/util/runtime"
2830
"k8s.io/client-go/kubernetes/scheme"
29-
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
3031

3132
ctrl "sigs.k8s.io/controller-runtime"
3233
"sigs.k8s.io/controller-runtime/pkg/client"

examples/kind/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import (
2222
"os"
2323

2424
"golang.org/x/sync/errgroup"
25+
2526
corev1 "k8s.io/api/core/v1"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
27-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2828

2929
ctrl "sigs.k8s.io/controller-runtime"
3030
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
31+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3132
"sigs.k8s.io/controller-runtime/pkg/manager"
3233
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3334
"sigs.k8s.io/controller-runtime/pkg/reconcile"

examples/namespace/main.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ import (
2323

2424
flag "github.com/spf13/pflag"
2525
"golang.org/x/sync/errgroup"
26-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2726

2827
corev1 "k8s.io/api/core/v1"
28+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/util/runtime"
3131
"k8s.io/client-go/rest"
3232
"k8s.io/klog/v2"
3333

3434
ctrl "sigs.k8s.io/controller-runtime"
35-
"sigs.k8s.io/controller-runtime/pkg/cache"
3635
"sigs.k8s.io/controller-runtime/pkg/client"
3736
"sigs.k8s.io/controller-runtime/pkg/cluster"
3837
"sigs.k8s.io/controller-runtime/pkg/envtest"
@@ -103,17 +102,16 @@ func main() {
103102
runtime.Must(client.IgnoreAlreadyExists(cli.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "island"}})))
104103
runtime.Must(client.IgnoreAlreadyExists(cli.Create(ctx, &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: "island", Name: "bird"}})))
105104

106-
cl, err := cluster.New(cfg, namespace.WithClusterNameIndex())
105+
cl, err := cluster.New(cfg)
106+
if err != nil {
107+
entryLog.Error(err, "failed to create cluster")
108+
os.Exit(1)
109+
}
107110
provider := namespace.New(cl)
108111

109112
// Setup a cluster-aware Manager, with the provider to lookup clusters.
110113
entryLog.Info("Setting up cluster-aware manager")
111-
mgr, err := mcmanager.New(cfg, provider, manager.Options{
112-
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
113-
// wrap cache to turn IndexField calls into cluster-scoped indexes.
114-
return &namespace.NamespaceScopeableCache{Cache: cl.GetCache()}, nil
115-
},
116-
})
114+
mgr, err := mcmanager.New(cfg, provider, manager.Options{})
117115
if err != nil {
118116
entryLog.Error(err, "unable to set up overall controller manager")
119117
os.Exit(1)

hack/check-everything.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ header_text "installing envtest tools@${ENVTEST_K8S_VERSION} with setup-envtest
3636
tmp_bin=/tmp/cr-tests-bin
3737
(
3838
# don't presume to install for the user
39-
GOBIN=${tmp_bin} go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
39+
GOBIN=${tmp_bin} go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.20
4040
)
4141
export KUBEBUILDER_ASSETS="$(${tmp_bin}/setup-envtest use --use-env -p path "${ENVTEST_K8S_VERSION}")"
4242

internal/forked/testing/addr/manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"net"
2121
"strconv"
2222

23+
"github.com/multicluster-runtime/multicluster-runtime/internal/forked/testing/addr"
24+
2325
. "github.com/onsi/ginkgo/v2"
2426
. "github.com/onsi/gomega"
25-
26-
"github.com/multicluster-runtime/multicluster-runtime/internal/forked/testing/addr"
2727
)
2828

2929
var _ = Describe("SuggestAddress", func() {

pkg/builder/forked_builder_suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ package builder
1919
import (
2020
"testing"
2121

22-
. "github.com/onsi/ginkgo/v2"
23-
. "github.com/onsi/gomega"
24-
2522
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2623
"k8s.io/apimachinery/pkg/api/meta"
2724
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -35,6 +32,9 @@ import (
3532
"sigs.k8s.io/controller-runtime/pkg/webhook"
3633

3734
"github.com/multicluster-runtime/multicluster-runtime/internal/forked/testing/addr"
35+
36+
. "github.com/onsi/ginkgo/v2"
37+
. "github.com/onsi/gomega"
3838
)
3939

4040
func TestBuilder(t *testing.T) {

pkg/builder/forked_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ import (
2424

2525
"github.com/go-logr/logr"
2626

27-
"sigs.k8s.io/controller-runtime/pkg/source"
28-
2927
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3028
"k8s.io/apimachinery/pkg/runtime/schema"
3129
"k8s.io/klog/v2"
3230
"k8s.io/utils/ptr"
3331

34-
mccontroller "github.com/multicluster-runtime/multicluster-runtime/pkg/controller"
35-
mchandler "github.com/multicluster-runtime/multicluster-runtime/pkg/handler"
36-
mcmanager "github.com/multicluster-runtime/multicluster-runtime/pkg/manager"
37-
mcreconcile "github.com/multicluster-runtime/multicluster-runtime/pkg/reconcile"
38-
mcsource "github.com/multicluster-runtime/multicluster-runtime/pkg/source"
3932
"sigs.k8s.io/controller-runtime/pkg/client"
4033
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
4134
"sigs.k8s.io/controller-runtime/pkg/cluster"
4235
"sigs.k8s.io/controller-runtime/pkg/controller"
4336
"sigs.k8s.io/controller-runtime/pkg/handler"
4437
"sigs.k8s.io/controller-runtime/pkg/predicate"
4538
"sigs.k8s.io/controller-runtime/pkg/reconcile"
39+
"sigs.k8s.io/controller-runtime/pkg/source"
40+
41+
mccontroller "github.com/multicluster-runtime/multicluster-runtime/pkg/controller"
42+
mchandler "github.com/multicluster-runtime/multicluster-runtime/pkg/handler"
43+
mcmanager "github.com/multicluster-runtime/multicluster-runtime/pkg/manager"
44+
mcreconcile "github.com/multicluster-runtime/multicluster-runtime/pkg/reconcile"
45+
mcsource "github.com/multicluster-runtime/multicluster-runtime/pkg/source"
4646
)
4747

4848
// project represents other forms that we can use to

pkg/builder/forked_controller_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323
"sync/atomic"
2424

2525
"github.com/go-logr/logr"
26-
. "github.com/onsi/ginkgo/v2"
27-
. "github.com/onsi/gomega"
26+
2827
appsv1 "k8s.io/api/apps/v1"
2928
corev1 "k8s.io/api/core/v1"
3029
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -34,7 +33,6 @@ import (
3433
"k8s.io/client-go/rest"
3534
"k8s.io/client-go/util/workqueue"
3635
"k8s.io/utils/ptr"
37-
"sigs.k8s.io/controller-runtime/pkg/source"
3836

3937
"sigs.k8s.io/controller-runtime/pkg/cache"
4038
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -44,12 +42,16 @@ import (
4442
"sigs.k8s.io/controller-runtime/pkg/predicate"
4543
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4644
"sigs.k8s.io/controller-runtime/pkg/scheme"
45+
"sigs.k8s.io/controller-runtime/pkg/source"
4746

4847
mccontroller "github.com/multicluster-runtime/multicluster-runtime/pkg/controller"
4948
mchandler "github.com/multicluster-runtime/multicluster-runtime/pkg/handler"
5049
mcmanager "github.com/multicluster-runtime/multicluster-runtime/pkg/manager"
5150
mcreconcile "github.com/multicluster-runtime/multicluster-runtime/pkg/reconcile"
5251
mcsource "github.com/multicluster-runtime/multicluster-runtime/pkg/source"
52+
53+
. "github.com/onsi/ginkgo/v2"
54+
. "github.com/onsi/gomega"
5355
)
5456

5557
var _ untypedWatchesInput = (*WatchesInput[mcreconcile.Request])(nil)

0 commit comments

Comments
 (0)