This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces a new field in Baremetal configuration named `node_specific_labels`. This feature adds the ability to provide specific set of labels unique to the node. Signed-off-by: Imran Pochi <imran@kinvolk.io>
- Loading branch information
Showing
11 changed files
with
219 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
test/components/kubernetes/baremetal_kubelet_labels_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// @build baremetal | ||
// @build e2e | ||
|
||
package kubernetes //nolint:testpackage | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
pkglabels "k8s.io/apimachinery/pkg/labels" | ||
|
||
testutil "github.com/kinvolk/lokomotive/test/components/util" | ||
) | ||
|
||
// This map is copied from file ci/baremetal/baremetal-cluster.lokocfg.envsubst | ||
// the field is `node_specific_labels`. | ||
// The node name keys are costructed as follows: <cluster-name>-<controller/worker>-<index> | ||
const nodeNamesAndExpectedLabelsInCI = map[string]map[string]string{ | ||
"mercury-controller-0": map[string]string{ | ||
"testkey": "testvalue", | ||
}, | ||
"mercury-worker-0": map[string]string{ | ||
"ingressnode": "yes", | ||
}, | ||
"mercury-worker-1": map[string]string{ | ||
"storagenode": "yes", | ||
}, | ||
} | ||
|
||
func TestBaremetalNodeHasNodeSpecificLabels(t *testing.T) { | ||
client := testutil.CreateKubeClient(t) | ||
|
||
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) | ||
if err != nil { | ||
t.Errorf("could not list nodes: %v", err) | ||
} | ||
|
||
if len(nodes.Items) != len(nodeNamesAndExpectedLabelsInCI) { | ||
t.Errorf("expected %d worker nodes, got: %d", len(nodeNamesAndExpectedLabelsInCI), len(nodes.Items)) | ||
} | ||
|
||
for nodeName, labelsMap := range nodeNamesAndExpectedLabelsInCI { | ||
labels := pkglabels.Set(labelsMap).String() | ||
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{ | ||
LabelSelector: labels, | ||
}) | ||
|
||
if err != nil { | ||
t.Errorf("expected node with name %q not found: %v", nodeName, err) | ||
} | ||
|
||
// Currently we assume that the labels added to the node in CI are unique to the worker node. | ||
if len(nodes.Items) > 1 { | ||
t.Errorf("more than one worker node found having labels: %q", labels) | ||
} | ||
|
||
// This check confirms that the expected set of labels as per CI configuration were | ||
// present on the correct node. | ||
if nodes.Items[0].Name != nodeName { | ||
t.Errorf("expected node %q to have the labels %s", nodes.Items[0].Name, labels) | ||
} | ||
} | ||
} |