Skip to content

Commit 179c0af

Browse files
committed
modify crd indexers
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
1 parent a9589f9 commit 179c0af

4 files changed

Lines changed: 12 additions & 45 deletions

File tree

contrib/example-backend/controllers/serviceexport/serviceexport_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func NewAPIServiceExportReconciler(
6767
return nil, err
6868
}
6969

70-
// Set up field indexer for APIServiceExports by CustomResourceDefinition name.
71-
if err := cache.IndexField(ctx, &kubebindv1alpha2.APIServiceExport{}, indexers.ServiceExportByCustomResourceDefinition,
72-
indexers.IndexServiceExportByCustomResourceDefinitionControllerRuntime); err != nil {
73-
return nil, fmt.Errorf("failed to setup ServiceExportByCustomResourceDefinition indexer: %w", err)
70+
// Set up field indexer for APIServiceExports by APIResourceSchema name.
71+
if err := cache.IndexField(ctx, &kubebindv1alpha2.APIServiceExport{}, indexers.ServiceExportByAPIResourceSchema,
72+
indexers.IndexServiceExportByAPIResourceSchema); err != nil {
73+
return nil, fmt.Errorf("failed to setup ServiceExportByAPIResourceSchema indexer: %w", err)
7474
}
7575

7676
r := &APIServiceExportReconciler{

contrib/example-backend/controllers/serviceexportrequest/serviceexportrequest_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func NewAPIServiceExportRequestReconciler(
7979

8080
// Set up field indexers for APIServiceExportRequests
8181
if err := cache.IndexField(ctx, &kubebindv1alpha2.APIServiceExportRequest{}, indexers.ServiceExportRequestByServiceExport,
82-
indexers.IndexServiceExportRequestByServiceExportControllerRuntime); err != nil {
82+
indexers.IndexServiceExportRequestByServiceExport); err != nil {
8383
return nil, fmt.Errorf("failed to setup ServiceExportRequestByServiceExport indexer: %w", err)
8484
}
8585

8686
if err := cache.IndexField(ctx, &kubebindv1alpha2.APIServiceExportRequest{}, indexers.ServiceExportRequestByGroupResource,
87-
indexers.IndexServiceExportRequestByGroupResourceControllerRuntime); err != nil {
87+
indexers.IndexServiceExportRequestByGroupResource); err != nil {
8888
return nil, fmt.Errorf("failed to setup ServiceExportRequestByGroupResource indexer: %w", err)
8989
}
9090

pkg/indexers/serviceexport.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ func IndexServiceExportByCustomResourceDefinition(obj any) ([]string, error) {
3636
return []string{export.Name}, nil
3737
}
3838

39-
// IndexServiceExportByCustomResourceDefinitionControllerRuntime is a controller-runtime compatible indexer function
40-
// that indexes APIServiceExports by their CustomResourceDefinition name.
41-
func IndexServiceExportByCustomResourceDefinitionControllerRuntime(obj client.Object) []string {
39+
// IndexServiceExportByAPIResourceSchema is a controller-runtime compatible indexer function.
40+
func IndexServiceExportByAPIResourceSchema(obj client.Object) []string {
4241
export, ok := obj.(*v1alpha2.APIServiceExport)
4342
if !ok {
4443
return nil
@@ -51,11 +50,3 @@ func IndexServiceExportByCustomResourceDefinitionControllerRuntime(obj client.Ob
5150

5251
return names
5352
}
54-
func IndexServiceExportByAPIResourceSchema(obj any) ([]string, error) {
55-
export, ok := obj.(*v1alpha2.APIServiceExport)
56-
if !ok {
57-
return nil, nil
58-
}
59-
60-
return []string{export.Name}, nil
61-
}

pkg/indexers/serviceexportrequest.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,9 @@ const (
2727
ServiceExportRequestByServiceExport = "ServiceExportRequestByServiceExport"
2828
)
2929

30-
func IndexServiceExportRequestByGroupResource(obj any) ([]string, error) {
31-
apiServiceExportRequest, ok := obj.(*kubebindv1alpha2.APIServiceExportRequest)
32-
if !ok {
33-
return nil, nil
34-
}
35-
keys := []string{}
36-
for _, gr := range apiServiceExportRequest.Spec.Resources {
37-
keys = append(keys, gr.Resource+"."+gr.Group)
38-
}
39-
return keys, nil
40-
}
41-
42-
// IndexServiceExportRequestByGroupResourceControllerRuntime is a controller-runtime compatible indexer function
30+
// IndexServiceExportRequestByGroupResource is a controller-runtime compatible indexer function
4331
// that indexes APIServiceExportRequests by their Group.Resource name.
44-
func IndexServiceExportRequestByGroupResourceControllerRuntime(obj client.Object) []string {
32+
func IndexServiceExportRequestByGroupResource(obj client.Object) []string {
4533
apiServiceExportRequest, ok := obj.(*kubebindv1alpha2.APIServiceExportRequest)
4634
if !ok {
4735
return nil
@@ -53,21 +41,9 @@ func IndexServiceExportRequestByGroupResourceControllerRuntime(obj client.Object
5341
return keys
5442
}
5543

56-
func IndexServiceExportRequestByServiceExport(obj any) ([]string, error) {
57-
apiServiceExportRequest, ok := obj.(*kubebindv1alpha2.APIServiceExportRequest)
58-
if !ok {
59-
return nil, nil
60-
}
61-
keys := []string{}
62-
for _, gr := range apiServiceExportRequest.Spec.Resources {
63-
keys = append(keys, apiServiceExportRequest.Namespace+"/"+gr.Resource+"."+gr.Group)
64-
}
65-
return keys, nil
66-
}
67-
68-
// IndexServiceExportRequestByServiceExportControllerRuntime is a controller-runtime compatible indexer function
44+
// IndexServiceExportRequestByServiceExport is a controller-runtime compatible indexer function
6945
// that indexes APIServiceExportRequests by their related ServiceExport name.
70-
func IndexServiceExportRequestByServiceExportControllerRuntime(obj client.Object) []string {
46+
func IndexServiceExportRequestByServiceExport(obj client.Object) []string {
7147
apiServiceExportRequest, ok := obj.(*kubebindv1alpha2.APIServiceExportRequest)
7248
if !ok {
7349
return nil

0 commit comments

Comments
 (0)