Skip to content

Commit

Permalink
only label node if it is found in kubectl get nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebot committed Apr 12, 2024
1 parent b78816e commit 5120d27
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions smol_k8s_lab/k8s_distros/k3s.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,21 @@ def join_k3s_nodes(extra_nodes: dict) -> None:
# join node to cluster
subproc([ssh_cmd + k3s_cmd], shell=True, universal_newlines=True)

labels = metadata.get('node_labels', None)
taints = metadata.get('node_taints', None)

# after joining the node make sure the labels are up to date
if labels:
for label in labels:
subproc([f"kubectl label nodes {node} {label}"])

# after joining the node make sure the taints are up to date
if taints:
for taint in taints:
subproc([f"kubectl taint nodes {node} {taint}"], error_ok=True)
nodes = subproc(["kubectl get nodes"])

if node in nodes:
labels = metadata.get('node_labels', None)
taints = metadata.get('node_taints', None)

# after joining the node make sure the labels are up to date
if labels:
for label in labels:
subproc([f"kubectl label nodes {node} {label}"])

# after joining the node make sure the taints are up to date
if taints:
for taint in taints:
subproc([f"kubectl taint nodes {node} {taint}"], error_ok=True)


def uninstall_k3s(cluster_name: str) -> str:
Expand Down

0 comments on commit 5120d27

Please sign in to comment.