diff --git a/pkg/controllers/resources/nodes/fake_syncer.go b/pkg/controllers/resources/nodes/fake_syncer.go index 9adba0557..71dfe93e8 100644 --- a/pkg/controllers/resources/nodes/fake_syncer.go +++ b/pkg/controllers/resources/nodes/fake_syncer.go @@ -159,7 +159,7 @@ func CreateFakeNode(ctx context.Context, "beta.kubernetes.io/arch": "amd64", "beta.kubernetes.io/os": "linux", "kubernetes.io/arch": "amd64", - "kubernetes.io/hostname": translate.SafeConcatName("fake", name), + "kubernetes.io/hostname": GetNodeHost(name), "kubernetes.io/os": "linux", }, Annotations: map[string]string{ diff --git a/pkg/controllers/resources/nodes/fake_syncer_test.go b/pkg/controllers/resources/nodes/fake_syncer_test.go index 4b91449a4..84169be3e 100644 --- a/pkg/controllers/resources/nodes/fake_syncer_test.go +++ b/pkg/controllers/resources/nodes/fake_syncer_test.go @@ -66,7 +66,7 @@ func TestFakeSync(t *testing.T) { "beta.kubernetes.io/arch": "amd64", "beta.kubernetes.io/os": "linux", "kubernetes.io/arch": "amd64", - "kubernetes.io/hostname": "fake-" + baseName.Name, + "kubernetes.io/hostname": GetNodeHost(baseName.Name), "kubernetes.io/os": "linux", }, Annotations: map[string]string{ diff --git a/pkg/controllers/resources/nodes/syncer_test.go b/pkg/controllers/resources/nodes/syncer_test.go index 61aad3e04..9ee7710f1 100644 --- a/pkg/controllers/resources/nodes/syncer_test.go +++ b/pkg/controllers/resources/nodes/syncer_test.go @@ -81,12 +81,14 @@ func TestSync(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: baseName.Name, Labels: map[string]string{ - "test": "true", + "test": "true", + "kubernetes.io/hostname": GetNodeHost(baseName.Name), }, Annotations: map[string]string{ "test": "true", translate.ManagedAnnotationsAnnotation: "test", - translate.ManagedLabelsAnnotation: "test", + translate.ManagedLabelsAnnotation: "kubernetes.io/hostname\ntest", + "vcluster.loft.sh/managed-annotations": "vcluster.loft.sh/original-taints", }, }, Status: corev1.NodeStatus{ @@ -184,8 +186,12 @@ func TestSync(t *testing.T) { baseNode = &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: baseName.Name, + Labels: map[string]string{ + "kubernetes.io/hostname": GetNodeHost(baseName.Name), + }, Annotations: map[string]string{ - TaintsAnnotation: "[\"{\\\"key\\\":\\\"key1\\\",\\\"value\\\":\\\"value1\\\",\\\"effect\\\":\\\"NoSchedule\\\"}\"]", + translate.ManagedLabelsAnnotation: "kubernetes.io/hostname", + TaintsAnnotation: "[\"{\\\"key\\\":\\\"key1\\\",\\\"value\\\":\\\"value1\\\",\\\"effect\\\":\\\"NoSchedule\\\"}\"]", }, }, Spec: corev1.NodeSpec{ @@ -218,8 +224,12 @@ func TestSync(t *testing.T) { editedNode = &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: baseName.Name, + Labels: map[string]string{ + "kubernetes.io/hostname": GetNodeHost(baseName.Name), + }, Annotations: map[string]string{ - TaintsAnnotation: "[\"{\\\"key\\\":\\\"key1\\\",\\\"value\\\":\\\"value1\\\",\\\"effect\\\":\\\"NoSchedule\\\"}\"]", + translate.ManagedLabelsAnnotation: "kubernetes.io/hostname", + TaintsAnnotation: "[\"{\\\"key\\\":\\\"key1\\\",\\\"value\\\":\\\"value1\\\",\\\"effect\\\":\\\"NoSchedule\\\"}\"]", }, }, Spec: corev1.NodeSpec{ @@ -345,7 +355,8 @@ func TestSync(t *testing.T) { translate.ManagedLabelsAnnotation: "test", }, Labels: map[string]string{ - "test": "true", + "test": "true", + "kubernetes.io/hostname": GetNodeHost(baseName.Name), }, }, Status: corev1.NodeStatus{ @@ -486,7 +497,8 @@ func TestSync(t *testing.T) { translate.ManagedLabelsAnnotation: "test", }, Labels: map[string]string{ - "test": "true", + "test": "true", + "kubernetes.io/hostname": GetNodeHost(baseName.Name), }, }, Status: corev1.NodeStatus{ @@ -533,7 +545,8 @@ func TestSync(t *testing.T) { translate.ManagedLabelsAnnotation: "test", }, Labels: map[string]string{ - "test": "true", + "test": "true", + "kubernetes.io/hostname": GetNodeHost(baseName.Name), }, }, Status: corev1.NodeStatus{ diff --git a/pkg/controllers/resources/nodes/translate.go b/pkg/controllers/resources/nodes/translate.go index 87860cd40..aa582a292 100644 --- a/pkg/controllers/resources/nodes/translate.go +++ b/pkg/controllers/resources/nodes/translate.go @@ -100,6 +100,10 @@ func (s *nodeSyncer) translateUpdateBackwards(pNode *corev1.Node, vNode *corev1. } } + if s.useFakeKubelets { + labels["kubernetes.io/hostname"] = GetNodeHost(vNode.Name) + } + // Omit those taints for which the vcluster has enforced tolerations defined if len(s.enforcedTolerations) > 0 && len(translatedSpec.Taints) > 0 { translatedSpec.Taints = s.filterOutTaintsMatchingTolerations(translatedSpec.Taints) diff --git a/test/e2e_node/node.go b/test/e2e_node/node.go index 1ba7be0fe..0fb1f326e 100644 --- a/test/e2e_node/node.go +++ b/test/e2e_node/node.go @@ -21,11 +21,15 @@ var _ = ginkgo.Describe("Node sync", func() { hostNodeLabels := make(map[string]map[string]string) for _, node := range hostNodes.Items { + pHostname := node.Labels[corev1.LabelHostname] + pHostname += ".nodes.vcluster.com" + node.Labels[corev1.LabelHostname] = pHostname hostNodeLabels[node.Name] = node.Labels } virtualNodeLabels := make(map[string]map[string]string) for _, node := range virtualNodes.Items { + delete(node.Labels, "vcluster.loft.sh/fake-node") virtualNodeLabels[node.Name] = node.Labels }