Skip to content

Commit fbf7314

Browse files
committed
fix e2e tests
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com> On-behalf-of: @SAP karol.szwaj@sap.com
1 parent 7c9a234 commit fbf7314

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

backend/http/handler.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
456456
}
457457

458458
// Resolve the UI sentinel to a real identity derived from the authenticated session.
459-
if identity == auth.UIIdentity {
459+
isUIFlow := identity == auth.UIIdentity
460+
if isUIFlow {
460461
identity = state.Token.Issuer + "/" + state.Token.Subject
461462
logger.Info("Resolved ui-identity from session", "identity", identity)
462463
}
@@ -499,20 +500,24 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
499500
},
500501
}
501502

502-
// Create the APIServiceExportRequest on the provider cluster and wait for reconciliation.
503-
// This ensures the binding is fully set up server-side for both CLI and UI flows.
504-
exportRequest, err := h.kubeManager.CreateAPIServiceExportRequest(
505-
r.Context(),
506-
params.ClusterID,
507-
handleResult.Namespace,
508-
bindRequest.Name,
509-
request.Spec,
510-
)
511-
if err != nil {
512-
logger.Error(err, "failed to create APIServiceExportRequest")
513-
statusCode, code, details := mapErrorToCode(err)
514-
writeErrorResponse(w, statusCode, code, "Failed to create API service export request", details)
515-
return
503+
// For UI-only flow, create the APIServiceExportRequest on the provider cluster
504+
// and wait for reconciliation. In CLI flow the konnector handles this instead.
505+
var exportRequestName string
506+
if isUIFlow {
507+
exportRequest, err := h.kubeManager.CreateAPIServiceExportRequest(
508+
r.Context(),
509+
params.ClusterID,
510+
handleResult.Namespace,
511+
bindRequest.Name,
512+
request.Spec,
513+
)
514+
if err != nil {
515+
logger.Error(err, "failed to create APIServiceExportRequest")
516+
statusCode, code, details := mapErrorToCode(err)
517+
writeErrorResponse(w, statusCode, code, "Failed to create API service export request", details)
518+
return
519+
}
520+
exportRequestName = exportRequest.Name
516521
}
517522

518523
// callback response
@@ -537,7 +542,7 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
537542
Kubeconfig: handleResult.Kubeconfig,
538543
Requests: []runtime.RawExtension{{Raw: requestBytes}},
539544
ProviderNamespace: handleResult.Namespace,
540-
BindingName: exportRequest.Name,
545+
BindingName: exportRequestName,
541546
}
542547

543548
payload, err := json.Marshal(&response)

backend/kubernetes/manager.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,24 @@ func (m *Manager) CreateAPIServiceExportRequest(
215215
logger = logger.WithValues("createdName", createdName)
216216
logger.Info("Created APIServiceExportRequest, waiting for reconciliation")
217217

218-
// Poll until reconciled
218+
// Poll until reconciled. The client reads from cache, so the object may not
219+
// be visible immediately after creation. Tolerate NotFound for an initial
220+
// grace period before treating it as a real deletion.
219221
var result *kubebindv1alpha2.APIServiceExportRequest
220-
if err := wait.PollUntilContextTimeout(ctx, 1*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) {
222+
seenOnce := false
223+
if err := wait.PollUntilContextTimeout(ctx, 1*time.Second, 60*time.Second, false, func(ctx context.Context) (bool, error) {
221224
req := &kubebindv1alpha2.APIServiceExportRequest{}
222225
if err := c.Get(ctx, types.NamespacedName{Namespace: namespace, Name: createdName}, req); err != nil {
223226
if errors.IsNotFound(err) {
224-
return false, fmt.Errorf("APIServiceExportRequest %s was deleted", createdName)
227+
if seenOnce {
228+
return false, fmt.Errorf("APIServiceExportRequest %s was deleted", createdName)
229+
}
230+
// Cache hasn't synced yet — keep polling.
231+
return false, nil
225232
}
226233
return false, err
227234
}
235+
seenOnce = true
228236
if req.Status.Phase == kubebindv1alpha2.APIServiceExportRequestPhaseSucceeded {
229237
result = req
230238
return true, nil

0 commit comments

Comments
 (0)