-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to schedule Calico Typha pods on control-planes.
- Loading branch information
Showing
7 changed files
with
128 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
kubemarine/patches/p1_calico_typha_schedule_control_planes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from textwrap import dedent | ||
from typing import cast, Optional | ||
|
||
from kubemarine import plugins | ||
from kubemarine.core import utils | ||
from kubemarine.core.action import Action | ||
from kubemarine.core.patch import RegularPatch | ||
from kubemarine.core.resources import DynamicResources | ||
from kubemarine.kubernetes import deployment | ||
from kubemarine.plugins import builtin, manifest, calico | ||
|
||
|
||
class TheAction(Action): | ||
def __init__(self) -> None: | ||
super().__init__("Schedule Calico Typha on control-planes") | ||
|
||
def run(self, res: DynamicResources) -> None: | ||
cluster = res.cluster() | ||
logger = cluster.log | ||
|
||
calico_version = cluster.inventory['plugins']['calico']['version'] | ||
if utils.version_key(calico_version)[0:2] >= utils.minor_version_key("v3.27"): | ||
return logger.info("The patch is not relevant for Calico >= v3.27.x.") | ||
|
||
if not calico.is_typha_enabled(cluster.inventory): | ||
return logger.info("The patch is skipped as Calico Typha is not enabled.") | ||
|
||
processor = cast(Optional[calico.CalicoLess_3_27_ManifestProcessor], | ||
builtin.get_manifest_processor(cluster, manifest.Identity('calico'))) | ||
if processor is None: | ||
return logger.warning("Calico manifest is not installed using default procedure. The patch is skipped.") | ||
|
||
original_manifest = processor.original_manifest() | ||
if not processor.get_typha_schedule_control_plane_extra_tolerations(original_manifest): | ||
return logger.info("Necessary tolerations already exist in the original manifest. The patch is skipped.") | ||
|
||
manifest_ = processor.enrich() | ||
key = "Deployment_calico-typha" | ||
typha_deployment_yaml = manifest_.get_obj(key, patch=False) | ||
|
||
typha_deployment = deployment.Deployment(cluster, 'calico-typha', 'kube-system', typha_deployment_yaml) | ||
logger.debug("Apply patched 'calico-typha' deployment") | ||
typha_deployment.apply(cluster.nodes['control-plane'].get_first_member()) | ||
|
||
logger.debug("Expect 'calico-typha' deployment and pods") | ||
plugins.expect_deployment(cluster, [{'name': 'calico-typha', 'namespace': 'kube-system'}]) | ||
plugins.expect_pods(cluster, ['calico-typha'], namespace='kube-system') | ||
|
||
|
||
class CalicoTyphaScheduleControlPlane(RegularPatch): | ||
def __init__(self) -> None: | ||
super().__init__("calico_typha_schedule_control_planes") | ||
|
||
@property | ||
def action(self) -> Action: | ||
return TheAction() | ||
|
||
@property | ||
def description(self) -> str: | ||
return dedent( | ||
f"""\ | ||
Allow to schedule Calico Typha pods on control-planes. | ||
This effectively resolves https://github.com/projectcalico/calico/pull/7979 in older versions. | ||
""".rstrip() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters