Skip to content

Commit

Permalink
Add extra_args.taint_worker function
Browse files Browse the repository at this point in the history
We're adding a separate worker that applies a list of taints,
cleaning up the code a little.
  • Loading branch information
petrutlucian94 committed Dec 11, 2024
1 parent efc1d84 commit 13d3347
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,9 @@ def _join_with_token(self, relation: ops.Relation, token: str, cluster_name: str
request.config = NodeJoinConfig()
config.extra_args.craft(self.config, request.config, cluster_name)

bootstrap_node_taints = str(self.config["bootstrap-node-taints"] or "").strip().split()
config.extra_args.taint_worker(request.config, bootstrap_node_taints)

self.api_manager.join_cluster(request)
log.info("Joined %s(%s)", self.unit, node_name)

Expand Down
25 changes: 15 additions & 10 deletions charms/worker/k8s/src/config/extra_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Learn more at: https://juju.is/docs/sdk

"""Parse extra arguments for Kubernetes components."""
from typing import Dict, Union
from typing import Dict, List, Union

import ops
from charms.k8s.v0.k8sd_api_manager import (
Expand Down Expand Up @@ -71,12 +71,17 @@ def craft(
cmd = _parse(src["kubelet-extra-args"])
dest.extra_node_kubelet_args = cmd

is_worker_node = isinstance(dest, NodeJoinConfig) and not isinstance(
dest, ControlPlaneNodeJoinConfig
)
if is_worker_node:
# We'll only do this for worker nodes, control plane nodes are handled
# separately.
taints = str(src["bootstrap-node-taints"] or "").strip().split()
if taints:
dest.extra_node_kubelet_args["--register-with-taints"] = ",".join(taints)

def taint_worker(dest: NodeJoinConfig, taints: List[str]):
"""Apply the specified list of taints to the node join configuration.
Updates the following attributes of the `config` object:
- extra_node_kubelet_args: arguments for kubelet.
Args:
dest (NodeJoinConfig):
The configuration object to be updated with extra arguments.
taints (List[str]):
The list of taints to apply.
"""
dest.extra_node_kubelet_args["--register-with-taints"] = ",".join(taints)

0 comments on commit 13d3347

Please sign in to comment.