Skip to content

Commit

Permalink
[e2e] Adjustments for recent K8S versions (#35)
Browse files Browse the repository at this point in the history
- Retrieve cluster version before fetching first node
  to ensure control plane node is always correctly
  identified
- Tolerate both "master" and "control-plane" taints
  in pod specs

Signed-off-by: Salvatore Orlando <[email protected]>
  • Loading branch information
salv-orlando authored Jun 4, 2022
1 parent 75f6968 commit 67d0658
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ func (data *TestData) collectClusterInfo() error {
workerIdx := 1
clusterInfo.nodes = make(map[int]ClusterNode)
clusterInfo.nodesOS = make(map[string]string)

// retrieve K8s server version

serverVersion, err := testData.clientset.Discovery().ServerVersion()
if err != nil {
return err
}
clusterInfo.k8sServerVersion = serverVersion.String()

for _, node := range nodes.Items {
isControlPlaneNode := func() bool {
_, ok := node.Labels[labelNodeRoleControlPlane()]
Expand Down Expand Up @@ -500,14 +509,6 @@ func (data *TestData) collectClusterInfo() error {
clusterInfo.svcV4NetworkCIDR = svcCIDRs[0]
clusterInfo.svcV6NetworkCIDR = svcCIDRs[1]

// retrieve K8s server version

serverVersion, err := testData.clientset.Discovery().ServerVersion()
if err != nil {
return err
}
clusterInfo.k8sServerVersion = serverVersion.String()

// Retrieve kubernetes Service host and Port
svc, err := testData.clientset.CoreV1().Services("default").Get(context.TODO(), "kubernetes", metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -771,12 +772,19 @@ func workerNodeName(idx int) string {
return node.name
}

func controlPlaneNoScheduleToleration() corev1.Toleration {
// the Node taint still uses "master" in K8s v1.20
return corev1.Toleration{
Key: "node-role.kubernetes.io/master",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
func controlPlaneNoScheduleTolerations() []corev1.Toleration {
// Use both "old" and "new" label for NoSchedule Toleration
return []corev1.Toleration{
{
Key: "node-role.kubernetes.io/master",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
},
{
Key: "node-role.kubernetes.io/control-plane",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
},
}
}

Expand Down Expand Up @@ -806,8 +814,7 @@ func (data *TestData) CreatePodOnNodeInNamespace(name, ns string, nodeName, ctrN
}
if nodeName == controlPlaneNodeName() {
// tolerate NoSchedule taint if we want Pod to run on control-plane Node
noScheduleToleration := controlPlaneNoScheduleToleration()
podSpec.Tolerations = []corev1.Toleration{noScheduleToleration}
podSpec.Tolerations = controlPlaneNoScheduleTolerations()
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 67d0658

Please sign in to comment.