Skip to content

Commit d77dc78

Browse files
committed
address reviews
1 parent ec6651d commit d77dc78

12 files changed

Lines changed: 43 additions & 55 deletions

File tree

backend/controllers/serviceexportrequest/serviceexportrequest_reconcile.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r *reconciler) getExportedSchemas(ctx context.Context, cl client.Client) (
117117
return nil, err
118118
}
119119

120-
var boundSchemas kubebindv1alpha2.ExportedSchemas = make(map[string]*kubebindv1alpha2.BoundSchema, len(list.Items))
120+
boundSchemas := make(kubebindv1alpha2.ExportedSchemas, len(list.Items))
121121
for _, item := range list.Items {
122122
boundSchema, err := helpers.UnstructuredToBoundSchema(item)
123123
if err != nil {
@@ -285,7 +285,7 @@ func (r *reconciler) validate(ctx context.Context, cl client.Client, req *kubebi
285285
return fmt.Errorf("no exported schemas found")
286286
}
287287

288-
scopes := make([]apiextensionsv1.ResourceScope, 0, len(exportedSchemas))
288+
first := apiextensionsv1.ResourceScope("")
289289
for _, res := range req.Spec.Resources {
290290
boundSchema, ok := exportedSchemas[res.ResourceGroupName()]
291291
if !ok {
@@ -299,23 +299,19 @@ func (r *reconciler) validate(ctx context.Context, cl client.Client, req *kubebi
299299
)
300300
return fmt.Errorf("schema %s not found", res.ResourceGroupName())
301301
}
302-
scopes = append(scopes, boundSchema.Spec.Scope)
303-
}
304-
305-
// Check CRD scopes matches.
306-
if len(scopes) > 1 {
307-
first := scopes[0]
308-
for _, scope := range scopes[1:] {
309-
if scope != first {
310-
conditions.MarkFalse(req,
311-
kubebindv1alpha2.APIServiceExportRequestConditionExportsReady,
312-
"DifferentScopes",
313-
conditionsapi.ConditionSeverityError,
314-
"Different scopes found: %v",
315-
scopes,
316-
)
317-
return fmt.Errorf("different scopes found for claimed resources: %v", scopes)
318-
}
302+
if first == apiextensionsv1.ResourceScope("") {
303+
first = boundSchema.Spec.Scope
304+
continue
305+
}
306+
if boundSchema.Spec.Scope != first {
307+
conditions.MarkFalse(req,
308+
kubebindv1alpha2.APIServiceExportRequestConditionExportsReady,
309+
"DifferentScopes",
310+
conditionsapi.ConditionSeverityError,
311+
"Different scopes found: %v",
312+
boundSchema.Spec.Scope,
313+
)
314+
return fmt.Errorf("different scopes found for claimed resources: %v", boundSchema.Name)
319315
}
320316
}
321317

backend/http/handler.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,13 @@ func (h *handler) getBackendDynamicResource(ctx context.Context, cluster string)
555555
Version: parts[1],
556556
Group: parts[2],
557557
}
558-
items, err := h.kubeManager.ListDynamicResources(ctx, cluster, gvk, labelSelector.AsSelector())
558+
list, err := h.kubeManager.ListDynamicResources(ctx, cluster, gvk, labelSelector.AsSelector())
559559
if err != nil {
560560
return nil, fmt.Errorf("failed to list resources: %w", err)
561561
}
562-
var boundSchemas kubebindv1alpha2.ExportedSchemas = make(map[string]*kubebindv1alpha2.BoundSchema, len(items.Items))
563-
for _, item := range items.Items {
562+
563+
boundSchemas := make(kubebindv1alpha2.ExportedSchemas, len(list.Items))
564+
for _, item := range list.Items {
564565
boundSchema, err := helpers.UnstructuredToBoundSchema(item)
565566
if err != nil {
566567
return nil, err

contrib/kcp/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ kubectl kcp bind apiexport root:provider:cowboys-stable
9090
```bash
9191
kubectl get logicalcluster
9292
# NAME PHASE URL AGE
93-
# cluster Ready https://192.168.2.166:6443/clusters/crh63mkto0egdjca
93+
# cluster Ready https://192.168.2.166:6443/clusters/xwhgz3kv8l67wx87
9494
```
9595

9696
9. Now we gonna initiate consumer:
@@ -104,15 +104,15 @@ kubectl ws create consumer --enter
104104
10. Bind the thing:
105105

106106
```bash
107-
./bin/kubectl-bind http://127.0.0.1:8080/clusters/crh63mkto0egdjca/exports --dry-run -o yaml > apiserviceexport.yaml
107+
./bin/kubectl-bind http://127.0.0.1:8080/clusters/xwhgz3kv8l67wx87/exports --dry-run -o yaml > apiserviceexport.yaml
108108

109109
# Extract secret for binding process. Note that secret name is not the same as output from command above. Check secret
110110
# name by running `kubectl get secret -n kube-bind`
111-
kubectl get secret kubeconfig-npp6r -n kube-bind -o jsonpath='{.data.kubeconfig}' | base64 -d > remote.kubeconfig
111+
kubectl get secret kubeconfig-ntgtl -n kube-bind -o jsonpath='{.data.kubeconfig}' | base64 -d > remote.kubeconfig
112112

113-
./bin/kubectl-bind apiservice --remote-kubeconfig remote.kubeconfig -f contrib/kcp/deploy/examples/apiserviceexport-namespaced.yaml --skip-konnector --remote-namespace kube-bind-w6gs4
113+
./bin/kubectl-bind apiservice --remote-kubeconfig remote.kubeconfig -f contrib/kcp/deploy/examples/apiserviceexport-namespaced.yaml --skip-konnector --remote-namespace kube-bind-wg2tb
114114

115-
./bin/kubectl-bind apiservice --remote-kubeconfig remote.kubeconfig -f contrib/kcp/deploy/examples/apiserviceexport-cluster.yaml --skip-konnector --remote-namespace kube-bind-t6wg7
115+
./bin/kubectl-bind apiservice --remote-kubeconfig remote.kubeconfig -f contrib/kcp/deploy/examples/apiserviceexport-cluster.yaml --skip-konnector --remote-namespace kube-bind-wg2tb
116116

117117

118118
export KUBECONFIG=.kcp/consumer.kubeconfig

contrib/kcp/deploy/resources/apiexport-kube-bind.io.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
- group: apis.kcp.io
4141
resource: apiresourceschemas
4242
verbs:
43-
- "*"
43+
- '*'
4444
resources:
4545
- group: kube-bind.io
4646
name: apiconversions
@@ -54,7 +54,7 @@ spec:
5454
crd: {}
5555
- group: kube-bind.io
5656
name: apiserviceexportrequests
57-
schema: v250918-24ab10a.apiserviceexportrequests.kube-bind.io
57+
schema: v250923-ec6651d.apiserviceexportrequests.kube-bind.io
5858
storage:
5959
crd: {}
6060
- group: kube-bind.io

contrib/kcp/deploy/resources/apiresourceschema-apiserviceexportrequests.kube-bind.io.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v250918-24ab10a.apiserviceexportrequests.kube-bind.io
5+
name: v250923-ec6651d.apiserviceexportrequests.kube-bind.io
66
spec:
77
conversion:
88
strategy: None
@@ -307,7 +307,7 @@ spec:
307307
type: object
308308
type: array
309309
x-kubernetes-validations:
310-
- message: Permission claim selector is immutable
310+
- message: permissionClaims are immutable
311311
rule: self == oldSelf
312312
resources:
313313
description: resources is a list of resources that should be exported.

deploy/crd/kube-bind.io_apiserviceexportrequests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ spec:
311311
type: object
312312
type: array
313313
x-kubernetes-validations:
314-
- message: Permission claim selector is immutable
314+
- message: permissionClaims are immutable
315315
rule: self == oldSelf
316316
resources:
317317
description: resources is a list of resources that should be exported.

pkg/konnector/controllers/cluster/claimedresources/claimedresources_reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type readReconciler struct {
4646
deleteConsumerObject func(ctx context.Context, ns, name string) error
4747
}
4848

49-
// reconcile syncs conmsumer claimed resources to provider.
49+
// reconcile syncs consumer claimed resources to provider.
5050
func (r *readReconciler) reconcile(ctx context.Context, providerNamespace, name string) error {
5151
logger := klog.FromContext(ctx)
5252
logger = logger.WithValues("name", name, "providerNamespace", providerNamespace)
@@ -128,7 +128,7 @@ func (r *readReconciler) reconcile(ctx context.Context, providerNamespace, name
128128
return nil
129129
}
130130

131-
if providerObj.GetDeletionTimestamp() != nil && !providerObj.GetDeletionTimestamp().IsZero() {
131+
if !providerObj.GetDeletionTimestamp().IsZero() {
132132
logger.Info("Deleting downstream object because it has been deleted upstream", "downstreamNamespace", consumerNS, "downstreamName", providerObj.GetName())
133133
if err := r.deleteConsumerObject(ctx, consumerNS, providerObj.GetName()); err != nil {
134134
return err

pkg/konnector/controllers/cluster/serviceexport/multinsinformer/informer.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,19 @@ func (inf *DynamicMultiNamespaceInformer) enqueueServiceNamespace(obj any) {
189189
logger.V(1).Info("starting dynamic informer", "namespace", sns.Status.Namespace)
190190
ctx, cancel := context.WithCancel(context.Background())
191191

192-
var factory dynamicinformer.DynamicSharedInformerFactory
192+
var tweakListOptions func(options *metav1.ListOptions)
193193
if inf.labelSelector != nil {
194-
tweakListOptions := func(options *metav1.ListOptions) {
194+
tweakListOptions = func(options *metav1.ListOptions) {
195195
selector, err := metav1.LabelSelectorAsSelector(inf.labelSelector)
196196
if err != nil {
197197
utilruntime.HandleError(fmt.Errorf("failed to convert label selector: %w", err))
198198
return
199199
}
200200
options.LabelSelector = selector.String()
201201
}
202-
factory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(inf.providerDynamicClient, time.Minute*30, sns.Status.Namespace, tweakListOptions)
203-
} else {
204-
factory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(inf.providerDynamicClient, time.Minute*30, sns.Status.Namespace, nil)
205202
}
203+
204+
factory := dynamicinformer.NewFilteredDynamicSharedInformerFactory(inf.providerDynamicClient, time.Minute*30, sns.Status.Namespace, tweakListOptions)
206205
gvrInf := factory.ForResource(inf.gvr)
207206
gvrInf.Lister() // to wire the GVR up in the informer factory
208207
inf.namespaceCancel[name] = cancel

pkg/konnector/controllers/cluster/serviceexport/serviceexport_reconcile.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func (r *reconciler) ensureControllers(ctx context.Context, namespace, name stri
9292
if export == nil {
9393
// Clean up any controllers associated with this export
9494
deleted := r.syncStore.BulkDeletePrefixed(exportKey)
95-
for _, k := range deleted {
96-
logger.V(1).Info("Stopping APIServiceExport sync", "key", k.Key(), "reason", "NoAPIServiceExport")
95+
for _, c := range deleted {
96+
logger.V(1).Info("Stopping APIServiceExport sync", "key", c.Key(), "reason", "NoAPIServiceExport")
9797
}
9898

9999
return nil
@@ -362,8 +362,6 @@ func (r *reconciler) ensureControllerForPermissionClaim(
362362
) error {
363363
logger := klog.FromContext(ctx)
364364

365-
ctxWithCancel, cancel := context.WithCancel(ctx)
366-
367365
dynamicProviderClient := dynamicclient.NewForConfigOrDie(r.providerConfig)
368366
dynamicConsumerClient := dynamicclient.NewForConfigOrDie(r.consumerConfig)
369367

@@ -430,7 +428,6 @@ func (r *reconciler) ensureControllerForPermissionClaim(
430428

431429
if err != nil {
432430
logger.Info("aborting", "error", err)
433-
cancel()
434431
return err
435432
}
436433
}
@@ -450,7 +447,6 @@ func (r *reconciler) ensureControllerForPermissionClaim(
450447
serviceNamespaceChannel,
451448
)
452449
if err != nil {
453-
cancel()
454450
return err
455451
}
456452

@@ -465,14 +461,15 @@ func (r *reconciler) ensureControllerForPermissionClaim(
465461
serviceNamespaceChannel,
466462
)
467463
if err != nil {
468-
cancel()
469464
return err
470465
}
471466

472467
logger.Info("creating claim reconciler", "gvr", claimGVR, "key", claimKey)
473468

469+
ctxWithCancel, cancel := context.WithCancel(ctx)
474470
// Start the informers and controllers in a goroutine
475471
go func() {
472+
defer r.syncStore.Delete(claimKey)
476473
defaultConsumerInf.Start(ctxWithCancel.Done())
477474

478475
// Wait for consumer informers to sync

pkg/konnector/controllers/cluster/serviceexport/spec/spec_reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type reconciler struct {
5252
func (r *reconciler) reconcile(ctx context.Context, obj *unstructured.Unstructured) error {
5353
logger := klog.FromContext(ctx)
5454
if r.apiServiceExport == nil { // Should never happen, but we check to make sure we dont regress in the future.
55-
panic("apiServiceExport is nil")
55+
return fmt.Errorf("internal error: apiServiceExport is nil")
5656
}
5757

5858
ns := obj.GetNamespace()

0 commit comments

Comments
 (0)