Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add worker bootstrap-node-taints setting #215

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions charms/worker/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ bases:

config:
options:
bootstrap-node-taints:
type: string
default: ""
description: |
Space-separated list of taints to apply to this node at registration time.

This config is only used at bootstrap time when Kubelet first registers the
node with Kubernetes. To change node taints after deploy time, use kubectl
instead.

For more information, see the upstream Kubernetes documentation about
taints:
https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
node-labels:
default: ""
type: string
Expand Down
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
17 changes: 16 additions & 1 deletion 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 @@ -70,3 +70,18 @@ def craft(

cmd = _parse(src["kubelet-extra-args"])
dest.extra_node_kubelet_args = cmd


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)
Loading