Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kale-amruta committed Feb 13, 2025
1 parent 1e21ada commit f2c9309
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 9 additions & 0 deletions pkg/controllers/resources/nodes/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ func (s *nodeSyncer) Sync(ctx *synccontext.SyncContext, event *synccontext.SyncE
}

s.translateUpdateBackwards(event.Host, event.Virtual)

// Set the marker of managed-by vcluster so that
// we skip deleting the nodes which are not managed
// by vcluster in `SyncToHost` function
if len(event.Virtual.Labels) == 0 {
event.Virtual.Labels = map[string]string{}
}
event.Virtual.Labels[translate.MarkerLabel] = translate.VClusterName

return ctrl.Result{}, nil
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/controllers/resources/nodes/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ func TestSyncBothExist(t *testing.T) {
}

if tC.virtualNodeExists {
node := initialVNode.DeepCopy()
if len(tC.virtualInitialAnnotations) > 0 {
node.Annotations = tC.virtualInitialAnnotations
// Since we pass initialVNode to syncer.Sync, we should
// update the initialVNode to have annnotations as per
// the test case
initialVNode.Annotations = tC.virtualInitialAnnotations
}

initialObjects = append(initialObjects, node)
initialObjects = append(initialObjects, initialVNode)
}

physical.Labels = tC.hostLabel
Expand Down
5 changes: 0 additions & 5 deletions pkg/controllers/resources/nodes/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ func (s *nodeSyncer) translateUpdateBackwards(pNode *corev1.Node, vNode *corev1.
annotations["cluster-autoscaler.kubernetes.io/scale-down-disabled"] = "true"
}

// Set the marker of managed-by vcluster so that
// we skip deleting the nodes which are not managed
// by vcluster in `SyncToHost` function
labels[translate.MarkerLabel] = translate.VClusterName

// set annotations, spec & labels
vNode.Spec = *translatedSpec
vNode.Annotations = annotations
Expand Down

0 comments on commit f2c9309

Please sign in to comment.