Skip to content

Commit

Permalink
test(support-bundle): agent with taint toleration
Browse files Browse the repository at this point in the history
Ref: 5614

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang committed Apr 7, 2023
1 parent a850ce8 commit b51a1b7
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
8 changes: 8 additions & 0 deletions manager/integration/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@

KUBERNETES_STATUS_LABEL = "KubernetesStatus"

MASTER_NODE_TAINT = "node-role.kubernetes.io/master=true:NoExecute;node-role.kubernetes.io/master=true:NoSchedule" # NOQA

# https://github.com/kubernetes/kubernetes/blob/a9f0db16614ae62563ead2018f1692407bd93d8f/pkg/apis/scheduling/types.go#L29 # NOQA
PRIORITY_CLASS_MAX = 1000000000
PRIORITY_CLASS_MIN = 1
Expand Down Expand Up @@ -3166,6 +3168,9 @@ def reset_settings(client):
for setting in client.list_setting():
setting_name = setting.name
setting_default_value = setting.definition.default
if setting_name == "taint-toleration":
setting_default_value = MASTER_NODE_TAINT

setting_readonly = setting.definition.readOnly

# We don't provide the setup for the storage network, hence there is no
Expand Down Expand Up @@ -4869,6 +4874,9 @@ def get_engine_image_status_value(client, ei_name):

def update_setting(client, name, value):
setting = client.by_id_setting(name)
if name == "taint-toleration":
value = value + ";" + MASTER_NODE_TAINT

client.update(setting, value=value)


Expand Down
56 changes: 56 additions & 0 deletions manager/integration/tests/node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest

from kubernetes import client as k8sclient

from common import get_self_host_id


@pytest.fixture(
params=[("foo/bar", "test", "NoSchedule"),
("foo", "", "NoSchedule")]
)
def taint_nodes_exclude_self(request):
taint = k8sclient.V1Taint(
key=request.param[0],
value=request.param[1],
effect=request.param[2],
)

self_host_id = get_self_host_id()

api = k8sclient.CoreV1Api()
node_items = api.list_node().items
saved_nodes = []
for node in node_items:
if node.metadata.name == self_host_id:
continue

saved_nodes.append(node)

if node.spec.taints is None:
taints = [taint]
else:
taints = node.spec.taints + [taint]
payload = {
"spec": {
"taints": taints
}
}
api.patch_node(node.metadata.name, body=payload)

yield saved_nodes

for node in saved_nodes:
if node.metadata.name == self_host_id:
continue

if node.spec.taints is None:
taints = []
else:
taints = node.spec.taints
payload = {
"spec": {
"taints": taints
}
}
api.patch_node(node.metadata.name, body=payload)
47 changes: 46 additions & 1 deletion manager/integration/tests/test_support_bundle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest
import time
import os
import zipfile

from tempfile import TemporaryDirectory

from node import taint_nodes_exclude_self # NOQA

from common import apps_api # NOQA
from common import client # NOQA
from common import core_api # NOQA
Expand All @@ -21,6 +22,7 @@

from common import SETTING_NODE_SELECTOR
from common import SETTING_SUPPORT_BUNDLE_FAILED_LIMIT
from common import SETTING_TAINT_TOLERATION


@pytest.mark.support_bundle # NOQA
Expand Down Expand Up @@ -217,3 +219,46 @@ def check_bundled_nodes_matches(node_names, zip, temp_dir):
f'Nodes zipped in bundle do not match. \n' \
f'Expect = {expect_node_zips}\n' \
f'Got = {node_zips}\n'


@pytest.mark.support_bundle # NOQA
def test_support_bundle_agent_with_taint_toleration(client, core_api, taint_nodes_exclude_self): # NOQA
"""
Scenario: support bundle agent should respect taint toleration
Issue: https://github.com/longhorn/longhorn/issues/5614
Given there are some tainted nodes in the cluster
And Longhorn tolerates the tainted nodes with setting "taint-toleration"
When a support bundle is generated
Then should be able to download the support bundle successfully
And support bundle should include all tainted nodes in node collection
"""
# The taint-toleration is set up to match the "taint_nodes_exclude_self"
# fixture.
update_setting(client, SETTING_TAINT_TOLERATION,
"foo/bar=test:NoSchedule; foo:NoSchedule")

resp = create_support_bundle(client)
node_id = resp['id']
name = resp['name']

wait_for_support_bundle_state("ReadyForDownload", node_id, name, client)

# The temporary directory will be automatically deleted outside of the
# "with" context manager.
with TemporaryDirectory(prefix="supportbundle-") as temp_dir:
download_path = f'{temp_dir}/{0}.zip'.format(name)
download_support_bundle(node_id, name, client,
target_path=download_path)

with zipfile.ZipFile(download_path, 'r') as zip:
nodes = core_api.list_node()
node_names = [f"{node.metadata.name}" for node in nodes.items]
check_bundled_nodes_matches(node_names, zip, temp_dir)

wait_for_support_bundle_cleanup(client)
check_all_support_bundle_managers_deleted()

0 comments on commit b51a1b7

Please sign in to comment.