@@ -60,6 +60,7 @@ const (
6060func NewDefaultAPIBindingController (
6161 kcpClusterClient kcpclientset.ClusterInterface ,
6262 logicalClusterInformer corev1alpha1informers.LogicalClusterClusterInformer ,
63+ globalLogicalClusterInformer corev1alpha1informers.LogicalClusterClusterInformer ,
6364 workspaceTypeInformer , globalWorkspaceTypeInformer tenancyv1alpha1informers.WorkspaceTypeClusterInformer ,
6465 apiBindingsInformer apisv1alpha2informers.APIBindingClusterInformer ,
6566 apiExportsInformer , globalAPIExportsInformer apisv1alpha2informers.APIExportClusterInformer ,
@@ -76,6 +77,22 @@ func NewDefaultAPIBindingController(
7677 return logicalClusterInformer .Lister ().Cluster (clusterName ).Get (corev1alpha1 .LogicalClusterName )
7778 },
7879
80+ getLogicalClusterByPath : func (path logicalcluster.Path ) (* corev1alpha1.LogicalCluster , error ) {
81+ clusters , err := indexers .ByIndexWithFallback [* corev1alpha1.LogicalCluster ](
82+ logicalClusterInformer .Informer ().GetIndexer (),
83+ globalLogicalClusterInformer .Informer ().GetIndexer (),
84+ indexers .ByLogicalClusterPath ,
85+ path .String (),
86+ )
87+ if err != nil {
88+ return nil , err
89+ }
90+ if len (clusters ) == 0 {
91+ return nil , apierrors .NewNotFound (corev1alpha1 .Resource ("logicalclusters" ), path .String ())
92+ }
93+ return clusters [0 ], nil
94+ },
95+
7996 listLogicalClusters : func () ([]* corev1alpha1.LogicalCluster , error ) {
8097 return logicalClusterInformer .Lister ().List (labels .Everything ())
8198 },
@@ -87,6 +104,17 @@ func NewDefaultAPIBindingController(
87104 listAPIBindings : func (clusterName logicalcluster.Name ) ([]* apisv1alpha2.APIBinding , error ) {
88105 return apiBindingsInformer .Lister ().Cluster (clusterName ).List (labels .Everything ())
89106 },
107+ listAPIBindingsByPath : func (ctx context.Context , clusterPath logicalcluster.Path ) ([]* apisv1alpha2.APIBinding , error ) {
108+ bindingList , err := kcpClusterClient .Cluster (clusterPath ).ApisV1alpha2 ().APIBindings ().List (ctx , metav1.ListOptions {})
109+ if err != nil {
110+ return nil , err
111+ }
112+ result := make ([]* apisv1alpha2.APIBinding , len (bindingList .Items ))
113+ for i := range bindingList .Items {
114+ result [i ] = & bindingList .Items [i ]
115+ }
116+ return result , nil
117+ },
90118 getAPIBinding : func (clusterName logicalcluster.Name , name string ) (* apisv1alpha2.APIBinding , error ) {
91119 return apiBindingsInformer .Lister ().Cluster (clusterName ).Get (name )
92120 },
@@ -134,14 +162,16 @@ type logicalClusterResource = committer.Resource[*corev1alpha1.LogicalClusterSpe
134162type DefaultAPIBindingController struct {
135163 queue workqueue.TypedRateLimitingInterface [string ]
136164
137- getLogicalCluster func (clusterName logicalcluster.Name ) (* corev1alpha1.LogicalCluster , error )
138- getWorkspaceType func (clusterName logicalcluster.Path , name string ) (* tenancyv1alpha1.WorkspaceType , error )
139- listLogicalClusters func () ([]* corev1alpha1.LogicalCluster , error )
165+ getLogicalCluster func (clusterName logicalcluster.Name ) (* corev1alpha1.LogicalCluster , error )
166+ getLogicalClusterByPath func (path logicalcluster.Path ) (* corev1alpha1.LogicalCluster , error )
167+ getWorkspaceType func (clusterName logicalcluster.Path , name string ) (* tenancyv1alpha1.WorkspaceType , error )
168+ listLogicalClusters func () ([]* corev1alpha1.LogicalCluster , error )
140169
141- listAPIBindings func (clusterName logicalcluster.Name ) ([]* apisv1alpha2.APIBinding , error )
142- getAPIBinding func (clusterName logicalcluster.Name , name string ) (* apisv1alpha2.APIBinding , error )
143- createAPIBinding func (ctx context.Context , clusterName logicalcluster.Path , binding * apisv1alpha2.APIBinding ) (* apisv1alpha2.APIBinding , error )
144- getAPIExport func (clusterName logicalcluster.Path , name string ) (* apisv1alpha2.APIExport , error )
170+ listAPIBindings func (clusterName logicalcluster.Name ) ([]* apisv1alpha2.APIBinding , error )
171+ listAPIBindingsByPath func (ctx context.Context , clusterPath logicalcluster.Path ) ([]* apisv1alpha2.APIBinding , error )
172+ getAPIBinding func (clusterName logicalcluster.Name , name string ) (* apisv1alpha2.APIBinding , error )
173+ createAPIBinding func (ctx context.Context , clusterName logicalcluster.Path , binding * apisv1alpha2.APIBinding ) (* apisv1alpha2.APIBinding , error )
174+ getAPIExport func (clusterName logicalcluster.Path , name string ) (* apisv1alpha2.APIExport , error )
145175
146176 commitApiBinding func (ctx context.Context , old , new * apiBindingResource ) error
147177 commitLogicalCluster func (ctx context.Context , old , new * logicalClusterResource ) error
@@ -302,7 +332,13 @@ func (c *DefaultAPIBindingController) process(ctx context.Context, key string) e
302332}
303333
304334// InstallIndexers adds the additional indexers that this controller requires to the informers.
305- func InstallIndexers (apiExportInformer , globalApiExportInformer apisv1alpha2informers.APIExportClusterInformer ) {
335+ func InstallIndexers (logicalClusterInformer , globalLogicalClusterInformer corev1alpha1informers.LogicalClusterClusterInformer , apiExportInformer , globalApiExportInformer apisv1alpha2informers.APIExportClusterInformer ) {
336+ indexers .AddIfNotPresentOrDie (logicalClusterInformer .Informer ().GetIndexer (), cache.Indexers {
337+ indexers .ByLogicalClusterPath : indexers .IndexByLogicalClusterPath ,
338+ })
339+ indexers .AddIfNotPresentOrDie (globalLogicalClusterInformer .Informer ().GetIndexer (), cache.Indexers {
340+ indexers .ByLogicalClusterPath : indexers .IndexByLogicalClusterPath ,
341+ })
306342 indexers .AddIfNotPresentOrDie (apiExportInformer .Informer ().GetIndexer (), cache.Indexers {
307343 indexers .ByLogicalClusterPathAndName : indexers .IndexByLogicalClusterPathAndName ,
308344 })
0 commit comments