Skip to content

Commit da59d21

Browse files
authored
Merge pull request #481 from mjudeikis/store.assigned.namespace
2 parents db4c30a + 6cb7074 commit da59d21

8 files changed

Lines changed: 44 additions & 8 deletions

File tree

backend/controllers/bindableresourcesrequest/bindableresourcesrequest_controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (r *reconciler) reconcile(ctx context.Context, clusterName string, cl clien
251251
}
252252

253253
// Handle resources and get kubeconfig
254-
kfg, err := r.kubeManager.HandleResources(ctx, req.Spec.Author, req.Spec.ClusterIdentity.Identity, clusterName)
254+
result, err := r.kubeManager.HandleResources(ctx, req.Spec.Author, req.Spec.ClusterIdentity.Identity, clusterName)
255255
if err != nil {
256256
meta.SetStatusCondition(&req.Status.Conditions, metav1.Condition{
257257
Type: string(kubebindv1alpha2.BindableResourcesRequestConditionReady),
@@ -263,8 +263,11 @@ func (r *reconciler) reconcile(ctx context.Context, clusterName string, cl clien
263263
return ctrl.Result{}, fmt.Errorf("failed to handle resources for cluster identity %q: %w", req.Spec.ClusterIdentity.Identity, err)
264264
}
265265

266+
// Set the namespace in the status
267+
req.Status.Namespace = result.Namespace
268+
266269
// Create or update the BindingResourceResponse secret
267-
if err := r.ensureBindingResponseSecret(ctx, cl, req, kfg, secretName, secretKey); err != nil {
270+
if err := r.ensureBindingResponseSecret(ctx, cl, req, result.Kubeconfig, secretName, secretKey); err != nil {
268271
meta.SetStatusCondition(&req.Status.Conditions, metav1.Condition{
269272
Type: string(kubebindv1alpha2.BindableResourcesRequestConditionReady),
270273
Status: metav1.ConditionFalse,

backend/http/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
367367
return
368368
}
369369

370-
kfg, err := h.kubeManager.HandleResources(r.Context(), state.Token.Subject, params.ConsumerID, params.ClusterID)
370+
handleResult, err := h.kubeManager.HandleResources(r.Context(), state.Token.Subject, params.ConsumerID, params.ClusterID)
371371
if err != nil {
372372
logger.Error(err, "failed to handle resources")
373373
statusCode, code, details := mapErrorToCode(err)
@@ -418,7 +418,7 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
418418
ID: state.Token.Issuer + "/" + state.Token.Subject,
419419
},
420420
},
421-
Kubeconfig: kfg,
421+
Kubeconfig: handleResult.Kubeconfig,
422422
Requests: []runtime.RawExtension{{Raw: requestBytes}},
423423
}
424424

backend/kubernetes/manager.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ func NewKubernetesManager(
8383
return m, nil
8484
}
8585

86+
// HandleResourcesResult contains the result of HandleResources operation.
87+
type HandleResourcesResult struct {
88+
// Kubeconfig is the kubeconfig data for accessing the service provider cluster.
89+
Kubeconfig []byte
90+
// Namespace is the namespace assigned to this binding on the service provider cluster.
91+
Namespace string
92+
}
93+
8694
func (m *Manager) HandleResources(
8795
ctx context.Context,
8896
author, identity, cluster string,
89-
) ([]byte, error) {
97+
) (*HandleResourcesResult, error) {
9098
logger := klog.FromContext(ctx).WithValues("identity", identity)
9199
ctx = klog.NewContext(ctx, logger)
92100

@@ -159,7 +167,10 @@ func (m *Manager) HandleResources(
159167
return nil, err
160168
}
161169

162-
return kfgSecret.Data["kubeconfig"], nil
170+
return &HandleResourcesResult{
171+
Kubeconfig: kfgSecret.Data["kubeconfig"],
172+
Namespace: ns,
173+
}, nil
163174
}
164175

165176
func (m *Manager) ListCustomResourceDefinitions(ctx context.Context, cluster string, selector labels.Selector) (*apiextensionsv1.CustomResourceDefinitionList, error) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ spec:
8282
crd: {}
8383
- group: kube-bind.io
8484
name: bindableresourcesrequests
85-
schema: v260122-c9f0f376.bindableresourcesrequests.kube-bind.io
85+
schema: v260225-974c2a97.bindableresourcesrequests.kube-bind.io
8686
storage:
8787
crd: {}
8888
- group: kube-bind.io

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
4-
name: v260122-c9f0f376.bindableresourcesrequests.kube-bind.io
4+
name: v260225-974c2a97.bindableresourcesrequests.kube-bind.io
55
spec:
66
group: kube-bind.io
77
names:
@@ -192,6 +192,11 @@ spec:
192192
- key
193193
- name
194194
type: object
195+
namespace:
196+
description: |-
197+
namespace is the namespace assigned to this binding request on the service provider cluster.
198+
This is where the resources for this binding are created and managed.
199+
type: string
195200
phase:
196201
default: Pending
197202
description: phase is the current phase of the binding request.

deploy/charts/backend/crds/kube-bind.io_bindableresourcesrequests.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ spec:
196196
- key
197197
- name
198198
type: object
199+
namespace:
200+
description: |-
201+
namespace is the namespace assigned to this binding request on the service provider cluster.
202+
This is where the resources for this binding are created and managed.
203+
type: string
199204
phase:
200205
default: Pending
201206
description: phase is the current phase of the binding request.

deploy/crd/kube-bind.io_bindableresourcesrequests.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ spec:
196196
- key
197197
- name
198198
type: object
199+
namespace:
200+
description: |-
201+
namespace is the namespace assigned to this binding request on the service provider cluster.
202+
This is where the resources for this binding are created and managed.
203+
type: string
199204
phase:
200205
default: Pending
201206
description: phase is the current phase of the binding request.

sdk/apis/kubebind/v1alpha2/bindingresponse_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ type BindableResourcesRequestStatus struct {
178178
// +kubebuilder:validation:Enum=Pending;Failed;Succeeded
179179
Phase BindableResourcesRequestPhase `json:"phase,omitempty"`
180180

181+
// namespace is the namespace assigned to this binding request on the service provider cluster.
182+
// This is where the resources for this binding are created and managed.
183+
//
184+
// +optional
185+
// +kubebuilder:validation:Optional
186+
Namespace string `json:"namespace,omitempty"`
187+
181188
// kubeconfigSecretRef is a reference to a secret containing the kubeconfig, used
182189
// to be used by the konnector agent.
183190
KubeconfigSecretRef *LocalSecretKeyRef `json:"kubeconfigSecretRef,omitempty"`

0 commit comments

Comments
 (0)