Skip to content

Commit fe69d96

Browse files
committed
SQUASH: remove logical.Name alias
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent b22303f commit fe69d96

File tree

16 files changed

+122
-138
lines changed

16 files changed

+122
-138
lines changed

examples/fleet/main.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
2222
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2323
kind "sigs.k8s.io/kind/pkg/cluster"
24-
"sigs.k8s.io/logical-cluster"
2524
)
2625

2726
func init() {
@@ -63,7 +62,7 @@ func main() {
6362
func(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
6463
log := log.FromContext(ctx)
6564

66-
cluster, err := mgr.GetCluster(ctx, req.Cluster)
65+
cluster, err := mgr.GetCluster(ctx, req.ClusterName)
6766
if err != nil {
6867
return reconcile.Result{}, err
6968
}
@@ -97,9 +96,9 @@ func main() {
9796
// KindClusterProvider is a cluster provider that works with a local Kind instance.
9897
type KindClusterProvider struct{}
9998

100-
func (k *KindClusterProvider) Get(ctx context.Context, name logical.Name, opts ...cluster.Option) (cluster.Cluster, error) {
99+
func (k *KindClusterProvider) Get(ctx context.Context, clusterName string, opts ...cluster.Option) (cluster.Cluster, error) {
101100
provider := kind.NewProvider()
102-
kubeconfig, err := provider.KubeConfig(string(name), false)
101+
kubeconfig, err := provider.KubeConfig(clusterName, false)
103102
if err != nil {
104103
return nil, err
105104
}
@@ -111,18 +110,18 @@ func (k *KindClusterProvider) Get(ctx context.Context, name logical.Name, opts .
111110
return cluster.New(cfg, opts...)
112111
}
113112

114-
func (k *KindClusterProvider) List() ([]logical.Name, error) {
113+
func (k *KindClusterProvider) List() ([]string, error) {
115114
provider := kind.NewProvider()
116115
list, err := provider.List()
117116
if err != nil {
118117
return nil, err
119118
}
120-
res := make([]logical.Name, 0, len(list))
119+
res := make([]string, 0, len(list))
121120
for _, cluster := range list {
122121
if !strings.HasPrefix(cluster, "fleet-") {
123122
continue
124123
}
125-
res = append(res, logical.Name(cluster))
124+
res = append(res, cluster)
126125
}
127126
return res, nil
128127
}
@@ -169,8 +168,8 @@ func (k *KindWatcher) ResultChan() <-chan cluster.WatchEvent {
169168
continue
170169
}
171170
k.ch <- cluster.WatchEvent{
172-
Type: watch.Added,
173-
Name: logical.Name(cl),
171+
Type: watch.Added,
172+
ClusterName: cl,
174173
}
175174
}
176175
// Check for deleted clusters.
@@ -179,8 +178,8 @@ func (k *KindWatcher) ResultChan() <-chan cluster.WatchEvent {
179178
continue
180179
}
181180
k.ch <- cluster.WatchEvent{
182-
Type: watch.Deleted,
183-
Name: logical.Name(cl),
181+
Type: watch.Deleted,
182+
ClusterName: cl,
184183
}
185184
}
186185
set = newSet

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ require (
2727
k8s.io/component-base v0.30.0-beta.0
2828
k8s.io/klog/v2 v2.120.1
2929
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
30-
sigs.k8s.io/logical-cluster v0.0.1-alpha.0
3130
sigs.k8s.io/yaml v1.4.0
3231
)
3332

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RCh
241241
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0/go.mod h1:z7+wmGM2dfIiLRfrC6jb5kV2Mq/sK1ZP303cxzkV5Y4=
242242
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
243243
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
244-
sigs.k8s.io/logical-cluster v0.0.1-alpha.0 h1:vigMG0I1fgDVn0hsTOeZB55AmplXC7D4iLa60qeyX70=
245-
sigs.k8s.io/logical-cluster v0.0.1-alpha.0/go.mod h1:7YymTkuUFI+tkwCRPMsk+TiyBQiPDKRArxVAAGpezZI=
246244
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
247245
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
248246
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=

pkg/builder/controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"sigs.k8s.io/controller-runtime/pkg/predicate"
3737
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3838
"sigs.k8s.io/controller-runtime/pkg/source"
39-
"sigs.k8s.io/logical-cluster"
4039
)
4140

4241
// Supporting mocking out functions for testing.
@@ -61,7 +60,7 @@ type Builder struct {
6160
watchesInput []WatchesInput
6261
mgr manager.Manager
6362
cluster cluster.Cluster
64-
logicalName logical.Name
63+
clusterName string
6564
globalPredicates []predicate.Predicate
6665
ctrl controller.Controller
6766
ctrlOptions controller.Options
@@ -337,7 +336,7 @@ func (blder *Builder) doWatch() error {
337336
// given that the cache cannot be validated to be coming from the same cluter.
338337
// In the future, we could consider allowing this by satisfying a new interface
339338
// that sets and uses the cluster.
340-
if blder.logicalName != "" {
339+
if blder.clusterName != "" {
341340
return fmt.Errorf("when using a logical adapter, custom raw watches %T are not allowed", w.src)
342341
}
343342
}

pkg/builder/controller_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import (
4646
"sigs.k8s.io/controller-runtime/pkg/predicate"
4747
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4848
"sigs.k8s.io/controller-runtime/pkg/scheme"
49-
"sigs.k8s.io/logical-cluster"
5049
)
5150

5251
type typedNoop struct{}
@@ -562,7 +561,7 @@ var _ = Describe("application", func() {
562561
Context("with logical adapter", func() {
563562
It("should support watching across clusters", func() {
564563
adapter := &fakeClusterProvider{
565-
list: []logical.Name{
564+
clusterNameList: []string{
566565
"cluster1",
567566
"cluster2",
568567
},
@@ -602,7 +601,7 @@ var _ = Describe("application", func() {
602601
}
603602

604603
defer GinkgoRecover()
605-
switch req.Cluster {
604+
switch req.ClusterName {
606605
case "cluster1":
607606
ch1 <- req
608607
case "cluster2":
@@ -645,14 +644,14 @@ var _ = Describe("application", func() {
645644
Name: dep.Name,
646645
Namespace: dep.Namespace,
647646
},
648-
Cluster: "cluster1",
647+
ClusterName: "cluster1",
649648
})))
650649
Eventually(ch2).Should(Receive(Equal(reconcile.Request{
651650
NamespacedName: types.NamespacedName{
652651
Name: dep.Name,
653652
Namespace: dep.Namespace,
654653
},
655-
Cluster: "cluster2",
654+
ClusterName: "cluster2",
656655
})))
657656

658657
By("Creating a ReplicaSet")
@@ -686,14 +685,14 @@ var _ = Describe("application", func() {
686685
Name: dep.Name,
687686
Namespace: dep.Namespace,
688687
},
689-
Cluster: "cluster1",
688+
ClusterName: "cluster1",
690689
})))
691690
Eventually(ch2).Should(Receive(Equal(reconcile.Request{
692691
NamespacedName: types.NamespacedName{
693692
Name: dep.Name,
694693
Namespace: dep.Namespace,
695694
},
696-
Cluster: "cluster2",
695+
ClusterName: "cluster2",
697696
})))
698697
})
699698
})
@@ -838,18 +837,18 @@ func (*fakeType) GetObjectKind() schema.ObjectKind { return nil }
838837
func (*fakeType) DeepCopyObject() runtime.Object { return nil }
839838

840839
type fakeClusterProvider struct {
841-
list []logical.Name
842-
listErr error
840+
clusterNameList []string
841+
listErr error
843842

844843
watch chan cluster.WatchEvent
845844
}
846845

847-
func (f *fakeClusterProvider) Get(ctx context.Context, name logical.Name, opts ...cluster.Option) (cluster.Cluster, error) {
846+
func (f *fakeClusterProvider) Get(ctx context.Context, clusterName string, opts ...cluster.Option) (cluster.Cluster, error) {
848847
return cluster.New(testenv.Config, opts...)
849848
}
850849

851-
func (f *fakeClusterProvider) List() ([]logical.Name, error) {
852-
return f.list, f.listErr
850+
func (f *fakeClusterProvider) List() ([]string, error) {
851+
return f.clusterNameList, f.listErr
853852
}
854853

855854
func (f *fakeClusterProvider) Watch() (cluster.Watcher, error) {

pkg/cluster/cluster.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828
"k8s.io/client-go/kubernetes/scheme"
2929
"k8s.io/client-go/rest"
3030
"k8s.io/client-go/tools/record"
31-
"sigs.k8s.io/logical-cluster"
32-
3331
"sigs.k8s.io/controller-runtime/pkg/cache"
3432
"sigs.k8s.io/controller-runtime/pkg/client"
3533
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
@@ -66,13 +64,13 @@ type AwareDeepCopy[T any] interface {
6664
DeepCopyFor(Cluster) T
6765
}
6866

69-
// LogicalGetterFunc is a function that returns a cluster for a given logical cluster name.
70-
type LogicalGetterFunc func(context.Context, logical.Name) (Cluster, error)
67+
// ByNameGetterFunc is a function that returns a cluster for a given logical cluster name.
68+
type ByNameGetterFunc func(ctx context.Context, clusterName string) (Cluster, error)
7169

7270
// Cluster provides various methods to interact with a cluster.
7371
type Cluster interface {
74-
// Name returns the unique logical name of the cluster.
75-
Name() logical.Name
72+
// Name returns the identifying name of the cluster.
73+
Name() string
7674

7775
// GetHTTPClient returns an HTTP client that can be used to talk to the apiserver
7876
GetHTTPClient() *http.Client
@@ -112,8 +110,8 @@ type Cluster interface {
112110

113111
// Options are the possible options that can be configured for a Cluster.
114112
type Options struct {
115-
// Name is the unique name of the cluster.
116-
Name logical.Name
113+
// Name is the identifying name of the cluster.
114+
Name string
117115

118116
// Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources
119117
// Defaults to the kubernetes/client-go scheme.Scheme, but it's almost always better
@@ -196,7 +194,7 @@ func New(config *rest.Config, opts ...Option) (Cluster, error) {
196194
if config == nil {
197195
return nil, errors.New("must specify Config")
198196
}
199-
197+
200198
config = rest.CopyConfig(config)
201199
if config.UserAgent == "" {
202200
config.UserAgent = rest.DefaultKubernetesUserAgent()
@@ -354,7 +352,7 @@ func setOptionsDefaults(options Options, config *rest.Config) (Options, error) {
354352
}
355353

356354
// WithName sets the name of the cluster.
357-
func WithName(name logical.Name) Option {
355+
func WithName(name string) Option {
358356
return func(o *Options) {
359357
if o.Name != "" {
360358
panic("cluster name cannot be set more than once")

pkg/cluster/internal.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/cache"
3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131
intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
32-
"sigs.k8s.io/logical-cluster"
3332
)
3433

3534
type cluster struct {
36-
name logical.Name
35+
name string
3736

3837
// config is the rest.config used to talk to the apiserver. Required.
3938
config *rest.Config
@@ -62,7 +61,7 @@ type cluster struct {
6261
logger logr.Logger
6362
}
6463

65-
func (c *cluster) Name() logical.Name {
64+
func (c *cluster) Name() string {
6665
return c.name
6766
}
6867

pkg/cluster/provider.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55

66
"k8s.io/apimachinery/pkg/watch"
7-
"sigs.k8s.io/logical-cluster"
87
)
98

109
// Provider defines methods to retrieve, list, and watch fleet of clusters.
@@ -15,12 +14,12 @@ import (
1514
// clusters that are backed by Cluster API resources, which can live
1615
// in multiple namespaces in a single management cluster.
1716
type Provider interface {
18-
Get(ctx context.Context, name logical.Name, opts ...Option) (Cluster, error)
17+
Get(ctx context.Context, clusterName string, opts ...Option) (Cluster, error)
1918

2019
// List returns a list of logical clusters.
2120
// This method is used to discover the initial set of logical clusters
2221
// and to refresh the list of logical clusters periodically.
23-
List() ([]logical.Name, error)
22+
List() ([]string, error)
2423

2524
// Watch returns a Watcher that watches for changes to a list of logical clusters
2625
// and react to potential changes.
@@ -54,6 +53,6 @@ type WatchEvent struct {
5453
// A periodic event is sent that contains no new data: ignored.
5554
Type watch.EventType
5655

57-
// Name is the name of the logical cluster related to the event.
58-
Name logical.Name
56+
// ClusterName is the name of the cluster related to the event.
57+
ClusterName string
5958
}

pkg/handler/enqueue.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"sigs.k8s.io/controller-runtime/pkg/event"
2626
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
2727
"sigs.k8s.io/controller-runtime/pkg/reconcile"
28-
"sigs.k8s.io/logical-cluster"
2928
)
3029

3130
var enqueueLog = logf.RuntimeLog.WithName("eventhandler").WithName("EnqueueRequestForObject")
@@ -47,12 +46,12 @@ func (e *EnqueueRequestForObject) Create(ctx context.Context, evt event.CreateEv
4746
enqueueLog.Error(nil, "CreateEvent received with no metadata", "event", evt)
4847
return
4948
}
50-
var logicalClusterName logical.Name
49+
var clusterName string
5150
if e.cluster != nil {
52-
logicalClusterName = e.cluster.Name()
51+
clusterName = e.cluster.Name()
5352
}
5453
q.Add(reconcile.Request{
55-
Cluster: logicalClusterName,
54+
ClusterName: clusterName,
5655
NamespacedName: types.NamespacedName{
5756
Name: evt.Object.GetName(),
5857
Namespace: evt.Object.GetNamespace(),
@@ -62,23 +61,23 @@ func (e *EnqueueRequestForObject) Create(ctx context.Context, evt event.CreateEv
6261

6362
// Update implements EventHandler.
6463
func (e *EnqueueRequestForObject) Update(ctx context.Context, evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
65-
var logicalClusterName logical.Name
64+
var clusterName string
6665
if e.cluster != nil {
67-
logicalClusterName = e.cluster.Name()
66+
clusterName = e.cluster.Name()
6867
}
6968

7069
switch {
7170
case evt.ObjectNew != nil:
7271
q.Add(reconcile.Request{
73-
Cluster: logicalClusterName,
72+
ClusterName: clusterName,
7473
NamespacedName: types.NamespacedName{
7574
Name: evt.ObjectNew.GetName(),
7675
Namespace: evt.ObjectNew.GetNamespace(),
7776
},
7877
})
7978
case evt.ObjectOld != nil:
8079
q.Add(reconcile.Request{
81-
Cluster: logicalClusterName,
80+
ClusterName: clusterName,
8281
NamespacedName: types.NamespacedName{
8382
Name: evt.ObjectOld.GetName(),
8483
Namespace: evt.ObjectOld.GetNamespace(),
@@ -95,12 +94,12 @@ func (e *EnqueueRequestForObject) Delete(ctx context.Context, evt event.DeleteEv
9594
enqueueLog.Error(nil, "DeleteEvent received with no metadata", "event", evt)
9695
return
9796
}
98-
var logicalClusterName logical.Name
97+
var clusterName string
9998
if e.cluster != nil {
100-
logicalClusterName = e.cluster.Name()
99+
clusterName = e.cluster.Name()
101100
}
102101
q.Add(reconcile.Request{
103-
Cluster: logicalClusterName,
102+
ClusterName: clusterName,
104103
NamespacedName: types.NamespacedName{
105104
Name: evt.Object.GetName(),
106105
Namespace: evt.Object.GetNamespace(),
@@ -114,12 +113,12 @@ func (e *EnqueueRequestForObject) Generic(ctx context.Context, evt event.Generic
114113
enqueueLog.Error(nil, "GenericEvent received with no metadata", "event", evt)
115114
return
116115
}
117-
var logicalClusterName logical.Name
116+
var clusterName string
118117
if e.cluster != nil {
119-
logicalClusterName = e.cluster.Name()
118+
clusterName = e.cluster.Name()
120119
}
121120
q.Add(reconcile.Request{
122-
Cluster: logicalClusterName,
121+
ClusterName: clusterName,
123122
NamespacedName: types.NamespacedName{
124123
Name: evt.Object.GetName(),
125124
Namespace: evt.Object.GetNamespace(),

0 commit comments

Comments
 (0)