Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.21] fix: resync labels initially (#2368) #2370

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading