diff --git a/enabler/dependencies.yaml b/dependencies.yaml similarity index 84% rename from enabler/dependencies.yaml rename to dependencies.yaml index 8cb31aa..4a742ad 100644 --- a/enabler/dependencies.yaml +++ b/dependencies.yaml @@ -1,5 +1,5 @@ -kubectl: "https://storage.googleapis.com/kubernetes-release/release/latest/bin/{}/amd64/kubectl" # noqa +kubectl: "https://storage.googleapis.com/kubernetes-release/release/v1.29.0/bin/{}/amd64/kubectl" # noqa helm: "https://get.helm.sh/helm-v3.1.2-{}-amd64.tar.gz" # noqa istioctl: "https://github.com/istio/istio/releases/download/1.5.1/istioctl-1.5.1-{}.tar.gz" # noqa kind: "https://github.com/kubernetes-sigs/kind/releases/download/v0.22.0/kind-{}-amd64" # noqa -skaffold: "https://storage.googleapis.com/skaffold/releases/latest/skaffold-{}-amd64" # noqa \ No newline at end of file +skaffold: "https://storage.googleapis.com/skaffold/releases/latest/skaffold-{}-amd64" # noqa \ No newline at end of file diff --git a/enabler/grafana-vs.yaml b/grafana-vs.yaml similarity index 100% rename from enabler/grafana-vs.yaml rename to grafana-vs.yaml diff --git a/setup.py b/setup.py index b556246..c9c6466 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="enabler", version="0.1", - packages=["enabler", "enabler.commands", "enabler.helpers"], + packages=["enabler", "src.enabler_keitaro_inc.commands", "src.enabler_keitaro_inc.helpers"], # noqa include_package_data=True, install_requires=["click==7.1.1", "click-log==0.3.2", @@ -16,6 +16,6 @@ "flake8>=7.0.0"], entry_points=""" [console_scripts] - enabler=enabler.cli:cli + enabler=src.enabler_keitaro_inc.enabler:cli """, ) diff --git a/enabler/__init__.py b/src/enabler_keitaro_inc/__init__.py similarity index 100% rename from enabler/__init__.py rename to src/enabler_keitaro_inc/__init__.py diff --git a/enabler/commands/__init__.py b/src/enabler_keitaro_inc/commands/__init__.py similarity index 100% rename from enabler/commands/__init__.py rename to src/enabler_keitaro_inc/commands/__init__.py diff --git a/enabler/commands/cmd_apps.py b/src/enabler_keitaro_inc/commands/cmd_apps.py similarity index 97% rename from enabler/commands/cmd_apps.py rename to src/enabler_keitaro_inc/commands/cmd_apps.py index 6f455b5..42395b1 100644 --- a/enabler/commands/cmd_apps.py +++ b/src/enabler_keitaro_inc/commands/cmd_apps.py @@ -1,4 +1,4 @@ -from enabler.cli import pass_environment, logger +from src.enabler_keitaro_inc.enabler import pass_environment, logger import click import subprocess as s diff --git a/enabler/commands/cmd_kind.py b/src/enabler_keitaro_inc/commands/cmd_kind.py similarity index 98% rename from enabler/commands/cmd_kind.py rename to src/enabler_keitaro_inc/commands/cmd_kind.py index 0404b70..bb67e4e 100644 --- a/enabler/commands/cmd_kind.py +++ b/src/enabler_keitaro_inc/commands/cmd_kind.py @@ -1,5 +1,5 @@ -from enabler.cli import pass_environment, logger -from enabler.helpers import kind, kube +from src.enabler_keitaro_inc.enabler import pass_environment, logger +from src.enabler_keitaro_inc.helpers import kind, kube import click import click_spinner diff --git a/enabler/commands/cmd_platform.py b/src/enabler_keitaro_inc/commands/cmd_platform.py similarity index 97% rename from enabler/commands/cmd_platform.py rename to src/enabler_keitaro_inc/commands/cmd_platform.py index bf0f580..7e8d545 100644 --- a/enabler/commands/cmd_platform.py +++ b/src/enabler_keitaro_inc/commands/cmd_platform.py @@ -1,6 +1,6 @@ -from enabler.cli import pass_environment, logger -from enabler.helpers.git import get_submodules, get_repo -from enabler.type import semver +from src.enabler_keitaro_inc.enabler import pass_environment, logger +from src.enabler_keitaro_inc.helpers.git import get_submodules, get_repo +from src.enabler_keitaro_inc.type import semver from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa @@ -218,8 +218,6 @@ def version(ctx, kube_context_cli, submodules, repopath): # Get the repo from arguments defaults to cwd try: repo = get_repo(repopath) - logger.info("REPO") - logger.info(repo) submodules = get_submodules(repo, submodules) except Exception as e: # noqa logger.info("An error occurred while getting submodule") diff --git a/enabler/commands/cmd_preflight.py b/src/enabler_keitaro_inc/commands/cmd_preflight.py similarity index 98% rename from enabler/commands/cmd_preflight.py rename to src/enabler_keitaro_inc/commands/cmd_preflight.py index 2b6aec2..f6beb5e 100644 --- a/enabler/commands/cmd_preflight.py +++ b/src/enabler_keitaro_inc/commands/cmd_preflight.py @@ -1,4 +1,4 @@ -from enabler.cli import pass_environment, logger +from src.enabler_keitaro_inc.enabler import pass_environment, logger import click import subprocess as s diff --git a/enabler/commands/cmd_setup.py b/src/enabler_keitaro_inc/commands/cmd_setup.py similarity index 92% rename from enabler/commands/cmd_setup.py rename to src/enabler_keitaro_inc/commands/cmd_setup.py index 5339034..8bb403d 100755 --- a/enabler/commands/cmd_setup.py +++ b/src/enabler_keitaro_inc/commands/cmd_setup.py @@ -1,4 +1,4 @@ -from enabler.cli import pass_environment, logger +from src.enabler_keitaro_inc.enabler import pass_environment, logger import click import click_spinner @@ -41,7 +41,7 @@ def init(ctx, kube_context_cli): # Load URLs from the JSON file enabler_path = get_path() - file_path = os.path.join(enabler_path, 'enabler/dependencies.yaml') + file_path = os.path.join(enabler_path, 'dependencies.yaml') with open(file_path, 'r') as f: urls = yaml.safe_load(f) @@ -59,7 +59,7 @@ def init(ctx, kube_context_cli): logger.info(f'kubectl already exists at: {kubectl_location}') else: logger.info('Downloading kubectl...') - download_and_make_executable(kubectl_url, kubectl_location) + download_and_make_executable(kubectl_url, kubectl_location, 'kubectl') # noqa # Download helm if not exists or update if necessary helm_location = 'bin/helm' @@ -67,8 +67,7 @@ def init(ctx, kube_context_cli): logger.info(f'helm already exists at: {helm_location}') update_binary_if_necessary(helm_location, helm_url, ostype) else: - logger.info('Downloading helm...') - download_and_make_executable(helm_url, helm_location) + download_and_make_executable(helm_url, helm_location, 'helm') # Download istioctl if not exists or update if necessary istioctl_location = 'bin/istioctl' @@ -76,8 +75,7 @@ def init(ctx, kube_context_cli): logger.info(f'istioctl already exists at: {istioctl_location}') update_binary_if_necessary(istioctl_location, istioctl_url, ostype) else: - logger.info('Downloading istioctl...') - download_and_make_executable(istioctl_url, istioctl_location) + download_and_make_executable(istioctl_url, istioctl_location, 'istioctl') # noqa # Download kind if not exists or update if necessary kind_location = 'bin/kind' @@ -86,7 +84,7 @@ def init(ctx, kube_context_cli): update_binary_if_necessary(kind_location, kind_url, ostype) else: logger.info('Downloading kind...') - download_and_make_executable(kind_url, kind_location) + download_and_make_executable(kind_url, kind_location, 'kind') # Download skaffold if not exists skaffold_location = 'bin/skaffold' @@ -94,7 +92,7 @@ def init(ctx, kube_context_cli): logger.info(f'skaffold already exists at: {skaffold_location}') else: logger.info('Downloading skaffold...') - download_and_make_executable(skaffold_url, skaffold_location) + download_and_make_executable(skaffold_url, skaffold_location, 'skaffold') # noqa logger.info('All dependencies downloaded to bin/') logger.info('IMPORTANT: Please add the path to your user profile to ' + @@ -114,8 +112,8 @@ def get_latest_version_from_github(repo_url, ostype): else: logger.error("Failed to find latest release tag") return None - except requests.exceptions.RequestException as e: - logger.error(f"Error fetching latest version from GitHub: {e}") + except requests.exceptions.RequestException as e: # noqa + logger.info("Latest release not found") return None @@ -143,11 +141,27 @@ def extract_version_from_filename(filename, binary_name): return None -def download_and_make_executable(url, destination): - urllib.request.urlretrieve(url, destination) - st = os.stat(destination) - os.chmod(destination, st.st_mode | stat.S_IEXEC) - logger.info(f'{os.path.basename(destination)} downloaded and made executable!') # noqa +def download_and_make_executable(url, destination, binary_name): + if binary_name in ['skaffold', 'kind', 'kubectl']: + urllib.request.urlretrieve(url, destination) + st = os.stat(destination) + os.chmod(destination, st.st_mode | stat.S_IEXEC) + logger.info(f'{os.path.basename(destination)} downloaded and made executable!') # noqa + elif binary_name in ['helm', 'istioctl']: + download_and_extract_tar(url, destination, binary_name) + + +def download_and_extract_tar(url, destination, binary_name): + tar_filename = f'bin/{binary_name}.tar.gz' + urllib.request.urlretrieve(url, tar_filename) + tar = tarfile.open(tar_filename, 'r:gz') + for member in tar.getmembers(): + if member.isreg(): + member.name = os.path.basename(member.name) + tar.extract(member, 'bin') + tar.close() + os.remove(tar_filename) + logger.info(f'{binary_name} downloaded and made executable!') def update_binary_if_necessary(binary_location, binary_url, ostype): @@ -415,7 +429,7 @@ def istio(ctx, kube_context_cli, kube_context, monitoring_tools): raise click.Abort() if monitoring_tools == 'monitoring-tools': try: - grafana_virtual_service = s.run(['kubectl', 'apply', '-f', 'enabler/grafana-vs.yaml'], capture_output=True, check=True) # noqa + grafana_virtual_service = s.run(['kubectl', 'apply', '-f', 'grafana-vs.yaml'], capture_output=True, check=True) # noqa except Exception as e: logger.error('Error setting grafana URL') logger.error(str(e)) diff --git a/enabler/commands/cmd_version.py b/src/enabler_keitaro_inc/commands/cmd_version.py similarity index 86% rename from enabler/commands/cmd_version.py rename to src/enabler_keitaro_inc/commands/cmd_version.py index a856330..7f5c176 100644 --- a/enabler/commands/cmd_version.py +++ b/src/enabler_keitaro_inc/commands/cmd_version.py @@ -1,4 +1,4 @@ -from enabler.cli import pass_environment, logger +from src.enabler_keitaro_inc.enabler import pass_environment, logger import pkg_resources import click diff --git a/enabler/commands/enabler_completion.sh b/src/enabler_keitaro_inc/commands/enabler_completion.sh similarity index 100% rename from enabler/commands/enabler_completion.sh rename to src/enabler_keitaro_inc/commands/enabler_completion.sh diff --git a/enabler/cli.py b/src/enabler_keitaro_inc/enabler.py similarity index 94% rename from enabler/cli.py rename to src/enabler_keitaro_inc/enabler.py index 7daf21b..42ea795 100644 --- a/enabler/cli.py +++ b/src/enabler_keitaro_inc/enabler.py @@ -47,7 +47,7 @@ def list_commands(self, ctx): def get_command(self, ctx, name): try: mod = __import__( - "enabler.commands.cmd_{}".format(name), None, None, ["cli"] + "src.enabler_keitaro_inc.commands.cmd_{}".format(name), None, None, ["cli"] # noqa ) except ImportError: return diff --git a/enabler/helpers/__init__.py b/src/enabler_keitaro_inc/helpers/__init__.py similarity index 100% rename from enabler/helpers/__init__.py rename to src/enabler_keitaro_inc/helpers/__init__.py diff --git a/enabler/helpers/git.py b/src/enabler_keitaro_inc/helpers/git.py similarity index 94% rename from enabler/helpers/git.py rename to src/enabler_keitaro_inc/helpers/git.py index 660feee..b1e0b80 100644 --- a/enabler/helpers/git.py +++ b/src/enabler_keitaro_inc/helpers/git.py @@ -1,4 +1,4 @@ -from enabler.cli import logger +from src.enabler_keitaro_inc.enabler import logger import click import git import os diff --git a/enabler/helpers/kind.py b/src/enabler_keitaro_inc/helpers/kind.py similarity index 91% rename from enabler/helpers/kind.py rename to src/enabler_keitaro_inc/helpers/kind.py index bde87bf..9662c82 100644 --- a/enabler/helpers/kind.py +++ b/src/enabler_keitaro_inc/helpers/kind.py @@ -1,4 +1,4 @@ -from enabler.cli import logger +from src.enabler_keitaro_inc.enabler import logger import click import subprocess as s diff --git a/enabler/helpers/kube.py b/src/enabler_keitaro_inc/helpers/kube.py similarity index 96% rename from enabler/helpers/kube.py rename to src/enabler_keitaro_inc/helpers/kube.py index 6b6ec25..bb106f9 100644 --- a/enabler/helpers/kube.py +++ b/src/enabler_keitaro_inc/helpers/kube.py @@ -1,4 +1,4 @@ -from enabler.cli import logger +from src.enabler_keitaro_inc.enabler import logger import subprocess as s diff --git a/enabler/type/__init__.py b/src/enabler_keitaro_inc/type/__init__.py similarity index 100% rename from enabler/type/__init__.py rename to src/enabler_keitaro_inc/type/__init__.py diff --git a/enabler/type/semver.py b/src/enabler_keitaro_inc/type/semver.py similarity index 100% rename from enabler/type/semver.py rename to src/enabler_keitaro_inc/type/semver.py diff --git a/enabler/unit_tests/apps_unittests.py b/tests/apps_unittests.py similarity index 71% rename from enabler/unit_tests/apps_unittests.py rename to tests/apps_unittests.py index bbc9829..a6eaa7d 100644 --- a/enabler/unit_tests/apps_unittests.py +++ b/tests/apps_unittests.py @@ -1,16 +1,15 @@ import unittest from click.testing import CliRunner from unittest.mock import patch -from enabler.commands.cmd_apps import cli as CLI +from src.enabler_keitaro_inc.commands.cmd_apps import cli as CLI class TestAppCommands(unittest.TestCase): def setUp(self): self.runner = CliRunner() - @patch('enabler.commands.cmd_apps.s') + @patch('src.enabler_keitaro_inc.commands.cmd_apps.s') def test_create_namespace_command(self, mock_s): mock_s.run.return_value.returncode = 0 result = self.runner.invoke(CLI, ['namespace', 'test-namespace']) self.assertEqual(result.exit_code, 0) - # self.assertIn('Namespace created successfully', result.output) diff --git a/enabler/unit_tests/kind_unittests.py b/tests/kind_unittests.py similarity index 73% rename from enabler/unit_tests/kind_unittests.py rename to tests/kind_unittests.py index 42104db..02c850a 100644 --- a/enabler/unit_tests/kind_unittests.py +++ b/tests/kind_unittests.py @@ -1,34 +1,34 @@ import unittest from click.testing import CliRunner from unittest.mock import MagicMock, patch -from enabler.commands.cmd_kind import cli as CLI +from src.enabler_keitaro_inc.commands.cmd_kind import cli as CLI class TestKindCommands(unittest.TestCase): def setUp(self): self.runner = CliRunner() - @patch('enabler.commands.cmd_kind.s') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.s') def test_create_command(self, mock_s): mock_s.run.return_value.returncode = 0 result = self.runner.invoke(CLI, ['create']) self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_kind.s') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.s') def test_delete_command(self, mock_s): mock_s.run.return_value.returncode = 1 result = self.runner.invoke(CLI, ['delete']) self.assertEqual(result.exit_code, 1) - @patch('enabler.commands.cmd_kind.s') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.s') def test_status_command(self, mock_s): mock_s.run.return_value.returncode = 0 result = self.runner.invoke(CLI, ['status']) self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_kind.docker') - @patch('enabler.commands.cmd_kind.kube') - @patch('enabler.commands.cmd_kind.click_spinner.spinner') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.docker') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.kube') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.click_spinner.spinner') def test_start_command(self, mock_spinner, mock_kube, mock_docker): mock_kube.kubectl_info.return_value = True mock_container = MagicMock() @@ -38,8 +38,8 @@ def test_start_command(self, mock_spinner, mock_kube, mock_docker): result = self.runner.invoke(CLI, ['start']) self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_kind.docker') - @patch('enabler.commands.cmd_kind.click_spinner.spinner') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.docker') + @patch('src.enabler_keitaro_inc.commands.cmd_kind.click_spinner.spinner') def test_stop_command(self, mock_spinner, mock_docker): mock_container = MagicMock() mock_container.name = 'test-control-plane' diff --git a/enabler/unit_tests/platform_unittests.py b/tests/platform_unittests.py similarity index 78% rename from enabler/unit_tests/platform_unittests.py rename to tests/platform_unittests.py index 0c3638e..3f49446 100644 --- a/enabler/unit_tests/platform_unittests.py +++ b/tests/platform_unittests.py @@ -4,7 +4,7 @@ from click.testing import CliRunner from unittest.mock import patch from git import Repo -from enabler.cli import cli as CLI +from src.enabler_keitaro_inc.enabler import cli as CLI import os @@ -22,27 +22,27 @@ def tearDown(self): # Clean up the temporary directory after the test shutil.rmtree(self.temp_dir) - @patch('enabler.commands.cmd_platform.s') + @patch('src.enabler_keitaro_inc.commands.cmd_platform.s') def test_platform_init(self, mock_s): mock_s.run.return_value.returncode = 0 result = self.runner.invoke(CLI, ['platform', 'init', 'all', self.temp_dir]) # noqa self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_platform.s') + @patch('src.enabler_keitaro_inc.commands.cmd_platform.s') def test_platform_info(self, mock_s): mock_s.run.return_value.returncode = 0 result = self.runner.invoke(CLI, ['platform', 'info', '--kube-context', '']) # noqa self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_platform.click.confirm') - @patch('enabler.commands.cmd_platform.s') + @patch('src.enabler_keitaro_inc.commands.cmd_platform.click.confirm') + @patch('src.enabler_keitaro_inc.commands.cmd_platform.s') def test_platform_keys(self, mock_s, mock_confirm): - mock_s.run.return_value.returncode = 1 + mock_s.run.return_value.returncode = 0 mock_confirm.return_value = False result = self.runner.invoke(CLI, ['platform', 'keys']) - self.assertEqual(result.exit_code, 1) + self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_platform.s') + @patch('src.enabler_keitaro_inc.commands.cmd_platform.s') def test_platform_release(self, mock_s): mock_s.run.return_value.returncode = 0 simulated_path = 'platform/microservice' @@ -52,7 +52,7 @@ def test_platform_release(self, mock_s): result = self.runner.invoke(CLI, ['platform', 'release', '2.1.7', simulated_path]) # noqa self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_platform.s') + @patch('src.enabler_keitaro_inc.commands.cmd_platform.s') def test_platform_version(self, mock_s): mock_s.run.return_value.returncode = 0 result = self.runner.invoke(CLI, ['platform', 'version']) diff --git a/enabler/unit_tests/preflight_unittests.py b/tests/preflight_unittests.py similarity index 85% rename from enabler/unit_tests/preflight_unittests.py rename to tests/preflight_unittests.py index bdb1ce7..dc01a1f 100644 --- a/enabler/unit_tests/preflight_unittests.py +++ b/tests/preflight_unittests.py @@ -1,14 +1,14 @@ import unittest from click.testing import CliRunner from unittest.mock import patch -from enabler.commands.cmd_preflight import cli as CLI +from src.enabler_keitaro_inc.commands.cmd_preflight import cli as CLI class TestPreflightCommands(unittest.TestCase): def setUp(self): self.runner = CliRunner() - @patch('enabler.commands.cmd_preflight.s') + @patch('src.enabler_keitaro_inc.commands.cmd_preflight.s') def test_preflight_command(self, mock_s): mock_s.run.return_value.returncode = 0 with self.runner.isolated_filesystem(): diff --git a/enabler/unit_tests/setup_unittests.py b/tests/setup_unittests.py similarity index 72% rename from enabler/unit_tests/setup_unittests.py rename to tests/setup_unittests.py index f2ed130..2edf3c0 100644 --- a/enabler/unit_tests/setup_unittests.py +++ b/tests/setup_unittests.py @@ -1,7 +1,7 @@ import unittest from click.testing import CliRunner from unittest.mock import MagicMock, patch -from enabler.commands.cmd_setup import cli as CLI +from src.enabler_keitaro_inc.commands.cmd_setup import cli as CLI import os @@ -9,9 +9,9 @@ class TestSetupCommands(unittest.TestCase): def setUp(self): self.runner = CliRunner() - @patch('enabler.commands.cmd_setup.urllib.request') - @patch('enabler.commands.cmd_setup.os.stat') - @patch('enabler.commands.cmd_setup.os.chmod') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.urllib.request') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.os.stat') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.os.chmod') def test_init_command(self, mock_chmod, mock_stat, mock_request): permission = 0o755 @@ -31,10 +31,10 @@ def test_init_command(self, mock_chmod, mock_stat, mock_request): print(result.output) self.assertEqual(result.exit_code, 0) - @patch('enabler.commands.cmd_setup.docker.from_env') - @patch('enabler.commands.cmd_setup.docker.networks') - @patch('enabler.commands.cmd_setup.logger') - @patch('enabler.commands.cmd_setup.s') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.docker.from_env') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.docker.networks') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.logger') + @patch('src.enabler_keitaro_inc.commands.cmd_setup.s') def test_metallb_command(self, mock_s, mock_logger, mock_networks, mock_from_env): # noqa mock_network = MagicMock() mock_network['Name'] = 'kind' diff --git a/enabler/unit_tests/version_unittests.py b/tests/version_unittests.py similarity index 79% rename from enabler/unit_tests/version_unittests.py rename to tests/version_unittests.py index 3b7da7b..f717490 100644 --- a/enabler/unit_tests/version_unittests.py +++ b/tests/version_unittests.py @@ -1,13 +1,13 @@ import unittest from unittest.mock import patch -from enabler.cli import CLI +from src.enabler_keitaro_inc.enabler import CLI class TestVersionCommands(unittest.TestCase): def setUp(self): self.cli = CLI(runner=None) - @patch('enabler.cli.subprocess.run') + @patch('src.enabler_keitaro_inc.enabler.subprocess.run') def test_version_command(self, mock_subprocess_run): mock_subprocess_run.return_value.stdout = 'Enabler 0.1' version = self.cli.version_command()