Skip to content

Commit

Permalink
add create configmap module
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Marten Brüggemann <[email protected]>
  • Loading branch information
brueggemann authored and NotTheEvilOne committed May 29, 2024
1 parent dcf7855 commit db380fe
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/rookify/modules/create_configmap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# type: ignore

from .main import CreateConfigMapHandler

MODULE_NAME = "create_configmap"
HANDLER_CLASS = CreateConfigMapHandler
REQUIRES = []
AFTER = []
PREFLIGHT_REQUIRES = ["analyze_ceph"]
58 changes: 58 additions & 0 deletions src/rookify/modules/create_configmap/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-

from ..module import ModuleHandler, ModuleException
import kubernetes

from typing import Any


class CreateConfigMapHandler(ModuleHandler):
def __create_configmap_definition(self) -> Any:
pass

def preflight(self) -> None:
self.__cluster_name = self._config["rook"]["cluster"]["name"]
self.__fsid = self._data["analyze_ceph"]["mon"]["dump"]["fsid"]

# If the secret already exists, we have to abort to not override it
try:
self.k8s.core_v1_api.read_namespaced_secret(
"rook-ceph-mon", self._config["rook"]["cluster"]["namespace"]
)
except kubernetes.client.exceptions.ApiException:
pass
else:
raise ModuleException("Secret rook-ceph-mon already exists")

def run(self) -> Any:
# Get or create needed auth keys
admin_auth = self.ceph.mon_command(
"auth get-or-create-key",
entity="client.admin",
mon="allow *",
mgr="allow *",
mds="allow *",
)

mon_auth = self.ceph.mon_command(
"auth get-or-create-key", entity="mon.", mon="allow *"
)

metadata = kubernetes.client.V1ObjectMeta(name="rook-ceph-mon")

string_data = {
"admin-secret": admin_auth["key"],
"cluster-name": self.__cluster_name,
"fsid": self.__fsid,
"mon-secret": mon_auth["key"],
}

secret = kubernetes.client.V1Secret(
api_version="v1", kind="Secret", metadata=metadata, string_data=string_data
)

secret = self.k8s.core_v1_api.create_namespaced_secret(
self._config["rook"]["cluster"]["namespace"], body=secret
)

return secret.to_dict()

0 comments on commit db380fe

Please sign in to comment.