Skip to content

Commit

Permalink
chore(core): hardcoded module name (#299)
Browse files Browse the repository at this point in the history
Hardcoded module name in hook
---------

Signed-off-by: Nikita korolev <nikita.korolev@flant.com>
  • Loading branch information
universal-itengineer authored Aug 21, 2024
1 parent 683bb70 commit c3a0936
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 53 deletions.
17 changes: 16 additions & 1 deletion hooks/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@ version: "3"
tasks:
test:
cmds:
- python3 -m venv .venv
- task test:prepare
- task test:run
- task test:clean

test:prepare:
cmds:
- |
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r ../lib/python/requirements.txt
deactivate
test:run:
cmds:
- |
source .venv/bin/activate
python3 -m unittest discover -s . -v
deactivate
test:clean:
cmds:
- rm -rf .venv
3 changes: 2 additions & 1 deletion hooks/copy_custom_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# limitations under the License.

from lib.hooks.copy_custom_certificate import CopyCustomCertificatesHook
import common

if __name__ == "__main__":
hook = CopyCustomCertificatesHook()
hook = CopyCustomCertificatesHook(common.MODULE_NAME)
hook.run()
6 changes: 3 additions & 3 deletions hooks/discovery_clusterip_service_for_dvcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
class DiscoveryClusterIPServiceHook(Hook):
SNAPSHOT_NAME = "discovery-service"

def __init__(self, module_name: str = None):
super().__init__(module_name=module_name)
def __init__(self, module_name: str):
self.module_name = module_name
self.namespace = common.NAMESPACE
self.service_name = "dvcr"
self.value_path = f"{self.module_name}.internal.dvcr.serviceIP"
Expand Down Expand Up @@ -69,5 +69,5 @@ def r(ctx: hook.Context):


if __name__ == "__main__":
h = DiscoveryClusterIPServiceHook()
h = DiscoveryClusterIPServiceHook(common.MODULE_NAME)
h.run()
8 changes: 5 additions & 3 deletions hooks/generate_secret_for_dvcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def __init__(self,
*keys: Key,
secret_name: str,
namespace: str,
module_name: str = None):
super().__init__(module_name=module_name)
module_name: str,
):
self.module_name = module_name
self.keys = keys
self.secret_name = secret_name
self.namespace = namespace
Expand Down Expand Up @@ -136,6 +137,7 @@ def r(ctx: Context):
Key(name="salt",
value_path=f"{common.MODULE_NAME}.internal.dvcr.salt"),
secret_name="dvcr-secrets",
namespace=common.NAMESPACE
namespace=common.NAMESPACE,
module_name=common.MODULE_NAME
)
hook.run()
1 change: 0 additions & 1 deletion hooks/lib/hooks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
PUBLIC_DOMAIN_PREFIX = "%PUBLIC_DOMAIN%://"
CLUSTER_DOMAIN_PREFIX = "%CLUSTER_DOMAIN%://"


def cluster_domain_san(san: str) -> str:
"""
Create template to enrich specified san with a cluster domain
Expand Down
5 changes: 2 additions & 3 deletions hooks/lib/hooks/copy_custom_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
class CopyCustomCertificatesHook(Hook):
CUSTOM_CERTIFICATES_SNAPSHOT_NAME = "custom_certificates"

def __init__(self,
module_name: str = None):
super().__init__(module_name=module_name)
def __init__(self, module_name: str):
self.module_name = module_name
self.queue = f"/modules/{self.module_name}/copy-custom-certificates"

def generate_config(self) -> dict:
Expand Down
9 changes: 0 additions & 9 deletions hooks/lib/hooks/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@


class Hook:
def __init__(self, module_name: str = None) -> None:
self.module_name = self.get_module_name(module_name)

def generate_config(self):
pass

Expand All @@ -39,12 +36,6 @@ def set_value(path: str, values: dict, value) -> None:
def delete_value(path: str, values: dict) -> None:
return module_values.delete_value(path, values)

@staticmethod
def get_module_name(module_name: str) -> str:
if module_name is not None:
return module_name
return module.get_module_name()

def reconcile(self) -> Callable[[hook.Context], None]:
def r(ctx: hook.Context) -> None:
pass
Expand Down
4 changes: 2 additions & 2 deletions hooks/lib/hooks/internal_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ class GenerateCertificatesHook(Hook):

def __init__(self, *certificate_requests: CertitifacteRequest,
namespace: str,
module_name: str = None,
module_name: str,
algo: str = "rsa",
ca_request: CACertitifacteRequest = None) -> None:
super().__init__(module_name=module_name)
self.module_name=module_name
self.namespace = namespace
self.algo = algo
self.ca_request = ca_request
Expand Down
5 changes: 3 additions & 2 deletions hooks/lib/hooks/manage_tenant_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class ManageTenantSecretsHook(Hook):
def __init__(self,
source_namespace: str,
source_secret_name: str,
module_name: str,
pod_labels_to_follow: dict,
destination_secret_labels: dict = {},
module_name: str = None):
super().__init__(module_name=module_name)
):
self.module_name = module_name
self.source_namespace = source_namespace
self.source_secret_name = source_secret_name
self.pod_labels_to_follow = pod_labels_to_follow
Expand Down
28 changes: 0 additions & 28 deletions hooks/lib/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# limitations under the License.

from lib.module import values as module_values
import re
import os


def get_values_first_defined(values: dict, *keys):
Expand All @@ -36,29 +34,3 @@ def get_https_mode(module_name: str, values: dict) -> str:
if https_mode is not None:
return str(https_mode)
raise Exception("https mode is not defined")


def get_module_name() -> str:
module = ""
file_path = os.path.abspath(__file__)
external_modules_dir = os.getenv("EXTERNAL_MODULES_DIR")
for dir in os.getenv("MODULES_DIR").split(":"):
if dir.startswith(external_modules_dir):
dir = external_modules_dir
if file_path.startswith(dir):
module = re.sub(f"{dir}/?\d?\d?\d?-?", "",
file_path, 1).split("/")[0]
# /deckhouse/external-modules/virtualization/mr/hooks/hook_name.py
# {-------------------------- file_path --------------------------}
# {------ MODULES_DIR ------}{---------- regexp result ----------}}
# virtualization/mr/hooks/hook_name.py
# {-module-name-}{---------------------}
# or
# /deckhouse/modules/900-virtualization/hooks/hook_name.py
# {---------------------- file_path ----------------------}
# {-- MODULES_DIR --}{---{-------- regexp result --------}}
# virtualization/hooks/hook_name.py
# {-module-name-}{-----------------}

break
return module
1 change: 1 addition & 0 deletions hooks/manage_tenant_secrets_for_cdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
def main():
hook = ManageTenantSecretsHook(source_namespace=common.NAMESPACE,
source_secret_name="virtualization-module-registry",
module_name=common.MODULE_NAME,
pod_labels_to_follow={
"app": "containerized-data-importer",
"app.kubernetes.io/managed-by": "cdi-controller"
Expand Down

0 comments on commit c3a0936

Please sign in to comment.