-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan-Marten Brüggemann <[email protected]>
- Loading branch information
1 parent
e1500b1
commit b189ed1
Showing
9 changed files
with
517 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,4 @@ cython_debug/ | |
data.yaml | ||
config.yaml | ||
.ceph | ||
.k8s |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# type: ignore | ||
|
||
from .main import CreateClusterHandler | ||
|
||
|
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,102 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ..module import ModuleHandler, ModuleException | ||
|
||
from typing import Any | ||
import kubernetes | ||
|
||
|
||
class CreateClusterHandler(ModuleHandler): | ||
def __create_cluster_definition(self) -> Any: | ||
try: | ||
node_ls_data = self._data["analyze_ceph"]["node"]["ls"] | ||
|
||
# Get monitor count | ||
mon_count = 0 | ||
for node, mons in node_ls_data["mon"].items(): | ||
mon_count += 1 | ||
if len(mons) > 1: | ||
raise ModuleException( | ||
f"There are more than 1 mon running on node {node}" | ||
) | ||
|
||
# Get manager count | ||
mgr_count = 0 | ||
for node, mgrs in node_ls_data["mgr"].items(): | ||
mgr_count += 1 | ||
if len(mons) > 1: | ||
raise ModuleException( | ||
f"There are more than 1 mgr running on node {node}" | ||
) | ||
|
||
# Render cluster config from template | ||
self.__cluster_name = self._config["rook"]["cluster"]["name"] | ||
self.__cluster_namespace = self._config["rook"]["cluster"]["namespace"] | ||
self.__cluster_image = self._config["rook"]["ceph"]["image"] | ||
self.__mon_placement_label = ( | ||
self._config["rook"]["cluster"]["mon_placement_label"] | ||
if "mon_placement_label" in self._config["rook"]["cluster"] | ||
else f"placement-{self.__cluster_name}-mon" | ||
) | ||
self.__mgr_placement_label = ( | ||
self._config["rook"]["cluster"]["mgr_placement_label"] | ||
if "mgr_placement_label" in self._config["rook"]["cluster"] | ||
else f"placement-{self.__cluster_name}-mgr" | ||
) | ||
self.__cluster_definition = self.load_template( | ||
"cluster.yaml.j2", | ||
cluster_name=self.__cluster_name, | ||
cluster_namespace=self.__cluster_namespace, | ||
ceph_image=self.__cluster_image, | ||
mon_count=mon_count, | ||
mgr_count=mgr_count, | ||
mon_placement_label=self.__mon_placement_label, | ||
mgr_placement_label=self.__mgr_placement_label, | ||
) | ||
|
||
except KeyError: | ||
raise ModuleException("Ceph monitor data is incomplete") | ||
|
||
def __check_k8s_prerequisites(self) -> None: | ||
# We have to check, if our placement labels are disabled or unset | ||
nodes = self.k8s.CoreV1Api.list_node().items | ||
for node in nodes: | ||
node_labels = node.metadata.labels | ||
if ( | ||
self.__mon_placement_label in node_labels | ||
and node_labels[self.__mon_placement_label] == "enabled" | ||
): | ||
raise ModuleException( | ||
f"Label {self.__mon_placement_label} is set on node {node.metadata.name}" | ||
) | ||
if ( | ||
self.__mgr_placement_label in node_labels | ||
and node_labels[self.__mgr_placement_label] == "enabled" | ||
): | ||
raise ModuleException( | ||
f"Label {self.__mon_placement_label} is set on node {node.metadata.name}" | ||
) | ||
|
||
def preflight(self) -> None: | ||
self.__create_cluster_definition() | ||
self.__check_k8s_prerequisites() | ||
|
||
def run(self) -> Any: | ||
# Create Namespace | ||
namespace = kubernetes.client.V1Namespace( | ||
metadata=kubernetes.client.V1ObjectMeta(name=self.__cluster_name) | ||
) | ||
try: | ||
self.k8s.CoreV1Api.create_namespace(namespace) | ||
except kubernetes.client.exceptions.ApiException as err: | ||
if err.reason != "Conflict": | ||
raise ModuleException(f"Could not create namespace: {err.reason}") | ||
|
||
# Create CephCluster | ||
result = self.k8s.crd_api_apply( | ||
manifest=self.__cluster_definition.yaml | ||
).to_dict() | ||
|
||
# Check Cluster | ||
|
||
return result |
Oops, something went wrong.