Skip to content

Commit 4fbb3da

Browse files
authored
test: add taints and tolerations e2e test (#5901)
1 parent e2e74b5 commit 4fbb3da

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

.github/renovate.json

-6
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,6 @@
278278
"gaopenghigh"
279279
]
280280
},
281-
{
282-
"matchPackageNames": [
283-
"containernetworking/azure-ipam"
284-
],
285-
"groupName": "azure-ipam"
286-
},
287281
{
288282
"matchPackageNames": [
289283
"oss/kubernetes/azure-cloud-node-manager"

e2e/kube.go

+36-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type Kubeclient struct {
3838
}
3939

4040
const (
41-
hostNetworkDebugAppLabel = "debug-mariner"
42-
podNetworkDebugAppLabel = "debugnonhost-mariner"
41+
hostNetworkDebugAppLabel = "debug-mariner-tolerated"
42+
podNetworkDebugAppLabel = "debugnonhost-mariner-tolerated"
4343
)
4444

4545
func getClusterKubeClient(ctx context.Context, resourceGroupName, clusterName string) (*Kubeclient, error) {
@@ -164,10 +164,6 @@ func (k *Kubeclient) WaitUntilNodeReady(ctx context.Context, t *testing.T, vmssN
164164
node = castNode
165165
nodeTaints, _ := json.Marshal(node.Spec.Taints)
166166
nodeConditions, _ := json.Marshal(node.Status.Conditions)
167-
if len(node.Spec.Taints) > 0 {
168-
t.Logf("node %s is tainted. Taints: %s Conditions: %s", node.Name, string(nodeTaints), string(nodeConditions))
169-
continue
170-
}
171167

172168
for _, cond := range node.Status.Conditions {
173169
if cond.Type == corev1.NodeReady && cond.Status == corev1.ConditionTrue {
@@ -417,6 +413,23 @@ func daemonsetDebug(t *testing.T, deploymentName, targetNodeLabel, privateACRNam
417413
},
418414
},
419415
},
416+
// Set Tolerations to tolerate the node with test taints "testkey1=value1:NoSchedule,testkey2=value2:NoSchedule".
417+
// This is to ensure that the pod can be scheduled on the node with the taints.
418+
// It won't affect other pods running on the same node.
419+
Tolerations: []corev1.Toleration{
420+
{
421+
Key: "testkey1",
422+
Operator: corev1.TolerationOpEqual,
423+
Value: "value1",
424+
Effect: corev1.TaintEffectNoSchedule,
425+
},
426+
{
427+
Key: "testkey2",
428+
Operator: corev1.TolerationOpEqual,
429+
Value: "value2",
430+
Effect: corev1.TaintEffectNoSchedule,
431+
},
432+
},
420433
},
421434
},
422435
},
@@ -468,6 +481,23 @@ func podHTTPServerLinux(s *Scenario) *corev1.Pod {
468481
},
469482
},
470483
},
484+
// Set Tolerations to tolerate the node with test taints "testkey1=value1:NoSchedule,testkey2=value2:NoSchedule".
485+
// This is to ensure that the pod can be scheduled on the node with the taints.
486+
// It won't affect other pods running on the same node.
487+
Tolerations: []corev1.Toleration{
488+
{
489+
Key: "testkey1",
490+
Operator: corev1.TolerationOpEqual,
491+
Value: "value1",
492+
Effect: corev1.TaintEffectNoSchedule,
493+
},
494+
{
495+
Key: "testkey2",
496+
Operator: corev1.TolerationOpEqual,
497+
Value: "value2",
498+
Effect: corev1.TaintEffectNoSchedule,
499+
},
500+
},
471501
NodeSelector: map[string]string{
472502
"kubernetes.io/hostname": s.Runtime.KubeNodeName,
473503
},

e2e/scenario_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -824,18 +824,20 @@ func Test_Ubuntu2204_ArtifactStreaming_Scriptless(t *testing.T) {
824824
})
825825
}
826826

827-
func Test_Ubuntu2204_ChronyRestarts(t *testing.T) {
827+
func Test_Ubuntu2204_ChronyRestarts_Taints_And_Tolerations(t *testing.T) {
828828
RunScenario(t, &Scenario{
829-
Description: "Tests that the chrony service restarts if it is killed",
829+
Description: "Tests that the chrony service restarts if it is killed. Also tests taints and tolerations",
830830
Config: Config{
831831
Cluster: ClusterKubenet,
832832
VHD: config.VHDUbuntu2204Gen2Containerd,
833833
BootstrapConfigMutator: func(nbc *datamodel.NodeBootstrappingConfiguration) {
834+
nbc.KubeletConfig["--register-with-taints"] = "testkey1=value1:NoSchedule,testkey2=value2:NoSchedule"
834835
},
835836
Validator: func(ctx context.Context, s *Scenario) {
836837
ValidateFileHasContent(ctx, s, "/etc/systemd/system/chronyd.service.d/10-chrony-restarts.conf", "Restart=always")
837838
ValidateFileHasContent(ctx, s, "/etc/systemd/system/chronyd.service.d/10-chrony-restarts.conf", "RestartSec=5")
838839
ServiceCanRestartValidator(ctx, s, "chronyd", 10)
840+
ValidateTaints(ctx, s)
839841
},
840842
},
841843
})

e2e/validators.go

+16
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,19 @@ func GetFieldFromJsonObjectOnNode(ctx context.Context, s *Scenario, fileName str
427427

428428
return podExecResult.stdout.String()
429429
}
430+
431+
// ValidateTaints checks if the node has the expected taints that are set in the kubelet config with --register-with-taints flag
432+
func ValidateTaints(ctx context.Context, s *Scenario) {
433+
expectedTaints := s.Runtime.NBC.KubeletConfig["--register-with-taints"]
434+
node, err := s.Runtime.Cluster.Kube.Typed.CoreV1().Nodes().Get(ctx, s.Runtime.KubeNodeName, metav1.GetOptions{})
435+
require.NoError(s.T, err, "failed to get node %q", s.Runtime.KubeNodeName)
436+
actualTaints := ""
437+
for i, taint := range node.Spec.Taints {
438+
actualTaints += fmt.Sprintf("%s=%s:%s", taint.Key, taint.Value, taint.Effect)
439+
// add a comma if it's not the last element
440+
if i < len(node.Spec.Taints)-1 {
441+
actualTaints += ","
442+
}
443+
}
444+
require.Equal(s.T, expectedTaints, actualTaints, "expected node %q to have taint %q, but got %q", s.Runtime.KubeNodeName, expectedTaints, actualTaints)
445+
}

0 commit comments

Comments
 (0)