Skip to content

Commit 3aef188

Browse files
lixiaoyunerselldinesh
authored andcommitted
Fix k8s node joining failure for Arista-7060X6-16PE-384C-B-O128S2 SKU (#20883)
Description of PR Summary: Fix k8s node joining failure for Arista-7060X6-16PE-384C-B-O128S2 SKU Fixes # (issue) Type of change Bug fix Testbed and Framework(new/improvement) New Test case Skipped for non-supported platforms Test case improvement Approach What is the motivation for this PR? For SKU Arista-7060X6-16PE-384C-B-O128S2, k8s test case fails due to joining failure, need to fix. How did you do it? The reason why the case fails is that there's a parameter for kubelet which will prefer IPv6 address, but in testbed, we are using IPv4, so just need to specify the --node-ip=mgmt_ip. How did you verify/test it? Run the modified code on Arista-7060X6-16PE-384C-B-O128S2 DUT, the case runs successfully. Any platform specific information? N/A Supported testbed topology if it's a new test case? N/A signed-off-by: [email protected] Signed-off-by: selldinesh <[email protected]>
1 parent d2670a8 commit 3aef188

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/kubesonic/test_k8s_join_disjoin.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
MINIKUBE_SETUP_CHECK_INTERVAL = 10
2424
KUBERNETES_VERSION = "v1.22.2"
2525
KUBELET_CONFIGMAP = "kubelet-config-1.22"
26+
KUBELET_DEFAULT_CONFIG = "/etc/default/kubelet"
27+
KUBELET_DEFAULT_CONFIG_BAK = f"{KUBELET_DEFAULT_CONFIG}.bak"
2628
DAEMONSET_NODE_LABEL = "deployDaemonset"
2729
DAEMONSET_POD_LABEL = "test-ds-pod"
2830
DAEMONSET_CONTAINER_NAME = "mock-ds-container"
@@ -184,6 +186,44 @@ def remove_minikube_vip_dns(duthost, vmhost):
184186
logger.info("Minikube vip dns is removed")
185187

186188

189+
def is_the_sku_need_to_remove_node_ip_param(duthost):
190+
hwsku = duthost.facts.get("hwsku") if hasattr(duthost, "facts") else None
191+
if not hwsku:
192+
# Fallback query (ignore errors gracefully)
193+
result = duthost.shell("sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku", module_ignore_errors=True)
194+
hwsku = result.get("stdout", "").strip()
195+
return hwsku == "Arista-7060X6-16PE-384C-B-O128S2"
196+
197+
198+
def remove_node_ip_param(duthost):
199+
"""Remove '--node-ip=::' from kubelet config.
200+
Creates a backup of the original file once (if not already present) so it can be restored.
201+
A series of sed patterns is used to safely eliminate the token with or without surrounding spaces.
202+
"""
203+
if not is_the_sku_need_to_remove_node_ip_param(duthost):
204+
return
205+
logger.info("Detected SKU which requires removal of '--node-ip=::' from kubelet config")
206+
duthost.shell(f"sudo cp {KUBELET_DEFAULT_CONFIG} {KUBELET_DEFAULT_CONFIG_BAK}", module_ignore_errors=True)
207+
duthost.shell(f"sudo sed -i 's/--node-ip=::/--node-ip={duthost.mgmt_ip}/g' {KUBELET_DEFAULT_CONFIG}")
208+
duthost.shell("sudo systemctl daemon-reload")
209+
logger.info("Kubelet config '--node-ip=::' parameter removed")
210+
211+
212+
def restore_node_ip_param(duthost):
213+
"""Restore kubelet config from backup."""
214+
if not is_the_sku_need_to_remove_node_ip_param(duthost):
215+
return
216+
logger.info("Restoring kubelet config to original state if backup exists")
217+
restore_cmd = (
218+
f"if [ -f {KUBELET_DEFAULT_CONFIG_BAK} ]; then "
219+
f"sudo mv {KUBELET_DEFAULT_CONFIG_BAK} {KUBELET_DEFAULT_CONFIG}; "
220+
f"fi"
221+
)
222+
duthost.shell(restore_cmd)
223+
duthost.shell("sudo systemctl daemon-reload")
224+
logger.info("Kubelet config node ip param restore completed")
225+
226+
187227
def deploy_test_daemonset(vmhost):
188228
logger.info("Start to deploy daemonset and check the status")
189229
daemonset_yaml = "/tmp/daemonset.yaml"
@@ -330,6 +370,9 @@ def setup_and_teardown(duthost, vmhost, creds):
330370
# Prepare dns for minikube vip
331371
prepare_minikube_vip_dns(duthost, vmhost)
332372

373+
# Remove node-ip param if the sku is needed
374+
remove_node_ip_param(duthost)
375+
333376
yield
334377

335378
# Clean up the k8s table in configdb
@@ -341,6 +384,9 @@ def setup_and_teardown(duthost, vmhost, creds):
341384
# Restore certs for duthost join
342385
restore_cert(duthost)
343386

387+
# Restore node-ip param if the sku is needed
388+
restore_node_ip_param(duthost)
389+
344390
if asic_type == "vs":
345391

346392
# Restore vmhost param

0 commit comments

Comments
 (0)