Skip to content
Open
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
40 changes: 28 additions & 12 deletions docs/agents/specs/cilium-per-host-device-config-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ device to use on each host, rather than trying to enumerate what to avoid.
## Solution

Replace the cluster-wide cilium devices annotation with per-host
`CiliumNodeConfig` resources that specify the exact interface name for each
control node. The interface is determined by querying juju for each machine's
network interfaces and matching against the internal space.
`CiliumNodeConfig` resources that specify the exact internal and public
interface names for each control node. Sunbeam queries Juju for each machine's
interfaces and matches them to the spaces used by the MetalLB advertisements.
MAAS deployments also include the storage interface when the optional storage
IPAddressPool exists. When several spaces resolve to the same interface, the
device appears once. With multiple devices, the internal interface remains the
direct-routing device.

## Reverts

Expand Down Expand Up @@ -61,11 +65,11 @@ underscore-prefixed). This deduplicates ~60-70 lines.

- **Constructor**: `deployment`, `client`, `jhelper`, `model`, `network`,
`fqdn` (optional). Initializes `to_update: list[dict]`,
`to_delete: list[dict]`, `_ifnames: dict[str, str]` cache.
- **`_get_interface(node)`**: Looks up machine interfaces via
`jhelper.get_machine_interfaces()`, matches by the step's `network` space.
Caches results in `_ifnames`. Raises a step-specific error (defined by
subclass) if no matching interface found.
`to_delete: list[dict]`, and a cache of Juju machine interfaces.
- **`_get_interface(node, network=None)`** looks up machine interfaces via
`jhelper.get_machine_interfaces()` and matches the requested network's space.
It defaults to the step's configured network and raises an error if the node
has no interface in that space.
- **`is_skip(context)`**: Control node lookup (single node if `fqdn` provided,
all control nodes otherwise), kube client creation, calls abstract
`_get_outdated_resources(nodes, kube)`, populates `to_update`/`to_delete`,
Expand Down Expand Up @@ -97,8 +101,10 @@ Lists existing `CiliumNodeConfig` resources labeled with
- `spec.nodeSelector.matchLabels` contains exactly
`sunbeam/hostname: <hostname>` (guards against over-broad or empty
selectors that could silently misconfigure other nodes)
- `spec.defaults.devices` matches the current internal-space interface for that
node
- `spec.defaults.devices` matches the node's internal, public, and optional
storage interfaces, in that order, with each interface listed once
- `spec.defaults.direct-routing-device` matches the internal interface when
the node has multiple devices

A resource that has the right metadata label and device but a wrong or missing
`nodeSelector` is considered outdated and will be re-applied.
Expand All @@ -107,7 +113,7 @@ Returns `(outdated, deleted)` lists.

### `run(context)`

- For each node in `to_update`: look up interface, apply `CiliumNodeConfig` via
- For each node in `to_update`: resolve the devices, apply `CiliumNodeConfig` via
lightkube, then delete the cilium pod on that node to trigger restart
- For each node in `to_delete`: delete the `CiliumNodeConfig` resource and
delete the cilium pod
Expand All @@ -129,12 +135,18 @@ spec:
matchLabels:
kubernetes.io/hostname: <hostname>
defaults:
devices: "<interface-name>"
devices: "<internal-interface>,<public-interface>"
direct-routing-device: "<internal-interface>"
```

Uses `cilium.io/v2` (Canonical K8s 1.32 LTS ships Cilium 1.17.1; `v2alpha1`
is deprecated since Cilium 1.17).

For a shared interface, Sunbeam sets `devices` to the single interface name.
Cilium can select that device for direct routing automatically.
For a MAAS node with a distinct storage interface and an existing storage
IPAddressPool, Sunbeam appends the storage interface to `devices`.

### Cilium Pod Restart

After applying a config change for a node, restart the cilium agent on that node:
Expand Down Expand Up @@ -174,6 +186,10 @@ configured before metallb).
- Bootstrap plan — before `EnsureL2AdvertisementByHostStep`, all control nodes
- Remove-node plan — all control nodes (cleans up departed node's config)

MAAS instance recovery enablement creates the optional pool first, then
reconciles Cilium and the storage L2 advertisements before assigning the
Consul storage VIP.

### Local commands (`sunbeam-python/sunbeam/provider/local/commands.py`)

- Bootstrap plan — same positioning
Expand Down
28 changes: 1 addition & 27 deletions sunbeam-python/sunbeam/core/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def run(self, context: StepContext) -> Result: # noqa: C901


class CreateLoadBalancerIPPoolsStep(BaseStep, abc.ABC):
"""Create IPPool and L2Advertisement resources."""
"""Ensure the configured MetalLB IP pools exist."""

def __init__(
self,
Expand All @@ -921,9 +921,6 @@ def __init__(
)
self.client = client
self.lbpool_resource = K8SHelper.get_lightkube_loadbalancer_resource()
self.l2_advertisement_resource = (
K8SHelper.get_lightkube_l2_advertisement_resource()
)
self.model = K8SHelper.get_loadbalancer_namespace()

@abc.abstractmethod
Expand Down Expand Up @@ -962,21 +959,6 @@ def handle_lb_pools(self, name: str, addresses: list[str]):
)
self.kube.create(new_ippool)

def handle_l2_advertisement(self, name: str):
"""Manage L2Advertisement resource.

Kept for backward compatibility, deleting the resource on
upgraded versions of Sunbeam.
"""
try:
self.kube.get(
self.l2_advertisement_resource, name=name, namespace=self.model
)
self.kube.delete(self.l2_advertisement_resource, name, namespace=self.model)
except l_exceptions.ApiError as e:
if e.status.code != 404:
raise

def run(self, context: StepContext) -> Result:
"""Create Loadbalancer IPPool."""
try:
Expand All @@ -1001,12 +983,4 @@ def run(self, context: StepContext) -> Result:
f"Error in processing LoadBalancer pool {name}: {str(e)}",
)

try:
self.handle_l2_advertisement(name)
except l_exceptions.ApiError as e:
return Result(
ResultType.FAILED,
f"Error in processing L2Advertisement {name}: {str(e)}",
)

return Result(ResultType.COMPLETED)
27 changes: 24 additions & 3 deletions sunbeam-python/sunbeam/features/instance_recovery/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rich.console import Console

from sunbeam.core.common import BaseStep, run_plan
from sunbeam.core.deployment import Deployment
from sunbeam.core.deployment import Deployment, Networks
from sunbeam.core.juju import JujuHelper
from sunbeam.core.manifest import (
AddManifestStep,
Expand All @@ -31,6 +31,10 @@
from sunbeam.provider.maas.steps import MaasCreateLoadBalancerIPPoolsStep
from sunbeam.steps.hypervisor import ReapplyHypervisorTerraformPlanStep
from sunbeam.steps.juju import RemoveSaasApplicationsStep
from sunbeam.steps.k8s import (
EnsureCiliumDeviceByHostStep,
EnsureL2AdvertisementByHostStep,
)
from sunbeam.steps.openstack import ValidateInfraAppsStep
from sunbeam.utils import click_option_show_hints, pass_method_obj
from sunbeam.versions import CONSUL_CHANNEL, OPENSTACK_CHANNEL
Expand Down Expand Up @@ -154,14 +158,31 @@ def run_enable_plans(
plan2.extend(
[
MaasCreateLoadBalancerIPPoolsStep(deployment, client, maas_client),
EnsureCiliumDeviceByHostStep(
deployment,
client,
jhelper,
deployment.openstack_machines_model,
storage_pool=deployment.storage_ip_pool,
),
EnsureL2AdvertisementByHostStep(
deployment,
client,
jhelper,
deployment.openstack_machines_model,
Networks.STORAGE,
deployment.storage_ip_pool,
optional_if_pool_missing=True,
remove_legacy=True,
),
consul.PatchConsulStorageLoadBalancerIPPoolStep(
client,
deployment.storage_ippool_label,
deployment.storage_ip_pool,
ignore_errors=True,
),
consul.PatchConsulStorageLoadBalancerIPStep(
client,
pool_name=deployment.storage_ippool_label,
pool_name=deployment.storage_ip_pool,
ignore_errors=True,
),
]
Expand Down
6 changes: 5 additions & 1 deletion sunbeam-python/sunbeam/provider/maas/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,14 @@ def deploy(
deployment, client, jhelper, deployment.openstack_machines_model
)
)
plan2.append(EnsureDefaultL2AdvertisementMutedStep(deployment, client, jhelper))
plan2.append(MaasCreateLoadBalancerIPPoolsStep(deployment, client, maas_client))
plan2.append(
EnsureCiliumDeviceByHostStep(
deployment,
client,
jhelper,
deployment.openstack_machines_model,
storage_pool=deployment.storage_ip_pool,
),
)
plan2.append(
Expand All @@ -815,6 +815,7 @@ def deploy(
deployment.openstack_machines_model,
Networks.PUBLIC,
deployment.public_ip_pool,
remove_legacy=True,
)
)
plan2.append(
Expand All @@ -826,8 +827,10 @@ def deploy(
Networks.STORAGE,
deployment.storage_ip_pool,
optional_if_pool_missing=True,
remove_legacy=True,
)
)
plan2.append(EnsureDefaultL2AdvertisementMutedStep(deployment, client, jhelper))
plan2.append(AddK8SCloudStep(deployment, jhelper))

plan2.append(TerraformInitStep(tfhelper_microceph))
Expand Down Expand Up @@ -1799,6 +1802,7 @@ def remove_node(ctx: click.Context, name: str, force: bool, show_hints: bool) ->
client,
jhelper,
deployment.openstack_machines_model,
storage_pool=deployment.storage_ip_pool,
),
EnsureL2AdvertisementByHostStep(
deployment,
Expand Down
Loading
Loading