Skip to content

Commit

Permalink
Merge pull request #1259 from ishankhare07/fix-node-labels
Browse files Browse the repository at this point in the history
fix node labels syncing
  • Loading branch information
FabianKramm authored Oct 6, 2023
2 parents b7813a4 + 679ea2c commit 97dc882
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/resources/nodes/fake_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/resources/nodes/fake_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
27 changes: 20 additions & 7 deletions pkg/controllers/resources/nodes/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions pkg/controllers/resources/nodes/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e_node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 97dc882

Please sign in to comment.