Skip to content

Commit

Permalink
fix: resync labels initially (#2368) (#2370)
Browse files Browse the repository at this point in the history
* fix: resync labels initially

* chore: use smaller background proxy timeout

(cherry picked from commit 9248472)

Co-authored-by: Fabian Kramm <[email protected]>
  • Loading branch information
loft-bot and FabianKramm authored Jan 2, 2025
1 parent fd1dfd7 commit eb61515
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/localkubernetes/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func CreateBackgroundProxyContainer(ctx context.Context, vClusterName, vClusterN
return "", errors.Errorf("error starting background proxy: %s %v", string(out), err)
}
server := fmt.Sprintf("https://127.0.0.1:%v", localPort)
waitErr := wait.PollUntilContextTimeout(ctx, time.Second, time.Second*60, true, func(ctx context.Context) (bool, error) {
waitErr := wait.PollUntilContextTimeout(ctx, time.Second, time.Second*7, true, func(ctx context.Context) (bool, error) {
err = testConnectionWithServer(ctx, vRawConfig, server)
if err != nil {
return false, nil
Expand Down
30 changes: 25 additions & 5 deletions pkg/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,29 @@ func (r *SyncController) Reconcile(ctx context.Context, vReq reconcile.Request)
}
}

return r.genericSyncer.Sync(syncContext, &synccontext.SyncEvent[client.Object]{
result, err := r.genericSyncer.Sync(syncContext, &synccontext.SyncEvent[client.Object]{
VirtualOld: vObjOld,
Virtual: vObj,

HostOld: pObjOld,
Host: pObj,
})
if err != nil {
return ctrl.Result{}, fmt.Errorf("sync: %w", err)
}

return result, nil
} else if vObj != nil {
return r.genericSyncer.SyncToHost(syncContext, &synccontext.SyncToHostEvent[client.Object]{
result, err := r.genericSyncer.SyncToHost(syncContext, &synccontext.SyncToHostEvent[client.Object]{
HostOld: pObjOld,

Virtual: vObj,
})
if err != nil {
return ctrl.Result{}, fmt.Errorf("sync to host: %w", err)
}

return result, nil
} else if pObj != nil {
if pObj.GetAnnotations() != nil {
if shouldSkip, ok := pObj.GetAnnotations()[translate.SkipBackSyncInMultiNamespaceMode]; ok && shouldSkip == "true" {
Expand All @@ -215,11 +225,16 @@ func (r *SyncController) Reconcile(ctx context.Context, vReq reconcile.Request)
}
}

return r.genericSyncer.SyncToVirtual(syncContext, &synccontext.SyncToVirtualEvent[client.Object]{
result, err := r.genericSyncer.SyncToVirtual(syncContext, &synccontext.SyncToVirtualEvent[client.Object]{
VirtualOld: vObjOld,

Host: pObj,
})
if err != nil {
return ctrl.Result{}, fmt.Errorf("sync to virtual: %w", err)
}

return result, nil
}

return ctrl.Result{}, nil
Expand Down Expand Up @@ -252,11 +267,16 @@ func (r *SyncController) getObjects(ctx *synccontext.SyncContext, vReq, pReq ctr
var ok bool
vObjOld, ok = r.objectCache.Virtual().Get(vReq.NamespacedName)
if !ok && vObj != nil {
// for upgrading from pre-0.21 clusters we want to re-sync labels for the new objects initially once
// since we changed label prefixes so this is required to make sure all labels are initially synced
// from virtual to host correctly.
vObjOld = vObj.DeepCopyObject().(client.Object)
vObjOld.SetLabels(nil)

// only add to cache if it's not deleting
if vObj.GetDeletionTimestamp() == nil {
r.objectCache.Virtual().Put(vObj)
r.objectCache.Virtual().Put(vObjOld)
}
vObjOld = vObj
}

pObjOld, ok = r.objectCache.Host().Get(pReq.NamespacedName)
Expand Down

0 comments on commit eb61515

Please sign in to comment.