From ea038726abe022dbf026b4e06b835a5f2926a1bb Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 19 Dec 2024 16:10:57 +0000 Subject: [PATCH 1/2] chore: reduce the number of user-facing tasks --- tasks/containerd.py | 3 +-- tasks/demo_apps.py | 14 +++++++++----- tasks/k8s.py | 4 +--- tasks/k9s.py | 4 +--- tasks/knative.py | 6 ++---- tasks/kubeadm.py | 7 ++----- tasks/operator.py | 5 ----- tasks/sc2.py | 22 ++++++++++++---------- 8 files changed, 28 insertions(+), 37 deletions(-) diff --git a/tasks/containerd.py b/tasks/containerd.py index 47618f0..e15fb83 100644 --- a/tasks/containerd.py +++ b/tasks/containerd.py @@ -82,8 +82,7 @@ def set_log_level(ctx, log_level): restart_containerd() -@task -def install(ctx, debug=False, clean=False): +def install(debug=False, clean=False): """ Install (and build) containerd from source """ diff --git a/tasks/demo_apps.py b/tasks/demo_apps.py index 6bef3b4..8136fbd 100644 --- a/tasks/demo_apps.py +++ b/tasks/demo_apps.py @@ -59,11 +59,7 @@ def build(ctx, app=None, nocache=False): run(docker_cmd, shell=True, check=True) -@task -def push_to_local_registry(ctx, debug=False): - """ - Build an app for its usage with the project - """ +def do_push_to_local_registry(debug=False): print_dotted_line("Pushing {} demo apps to local regsitry".format(len(APP_LIST))) for app_name in APP_LIST: @@ -92,3 +88,11 @@ def push_to_local_registry(ctx, debug=False): print(result.stdout.decode("utf-8").strip()) print("Success!") + + +@task +def push_to_local_registry(ctx, debug=False): + """ + Build an app for its usage with the project + """ + do_push_to_local_registry(debug=debug) diff --git a/tasks/k8s.py b/tasks/k8s.py index f3e6457..bd4a0de 100644 --- a/tasks/k8s.py +++ b/tasks/k8s.py @@ -1,4 +1,3 @@ -from invoke import task from os import makedirs from os.path import exists, join from shutil import rmtree @@ -145,8 +144,7 @@ def configure_kubelet_service(debug=False, clean=False): print(result.stdout.decode("utf-8").strip()) -@task -def install(ctx, debug=False, clean=False): +def install(debug=False, clean=False): """ Install and configure all tools to deploy a single-node k8s cluster """ diff --git a/tasks/k9s.py b/tasks/k9s.py index 7a7a1d3..7bcd848 100644 --- a/tasks/k9s.py +++ b/tasks/k9s.py @@ -1,4 +1,3 @@ -from invoke import task from os.path import join from os import makedirs from shutil import copy, rmtree @@ -8,8 +7,7 @@ from tasks.util.versions import K9S_VERSION -@task -def install(ctx, debug=False): +def install(debug=False): """ Install the K9s CLI """ diff --git a/tasks/knative.py b/tasks/knative.py index f23e45c..ca8d8d8 100644 --- a/tasks/knative.py +++ b/tasks/knative.py @@ -106,8 +106,7 @@ def install_metallb(debug=False): ) -@task -def install(ctx, skip_push=False, debug=False): +def install(skip_push=False, debug=False): """ Install Knative on a running K8s cluster @@ -316,8 +315,7 @@ def install(ctx, skip_push=False, debug=False): print("Success!") -@task -def uninstall(ctx): +def uninstall(): """ Uninstall a Knative Serving installation diff --git a/tasks/kubeadm.py b/tasks/kubeadm.py index c6ce699..3b55497 100644 --- a/tasks/kubeadm.py +++ b/tasks/kubeadm.py @@ -1,4 +1,3 @@ -from invoke import task from os import getegid, geteuid, makedirs from os.path import exists from shutil import rmtree @@ -19,8 +18,7 @@ from time import sleep -@task -def create(ctx, debug=False): +def create(debug=False): """ Create a single-node k8s cluster """ @@ -121,8 +119,7 @@ def get_node_state(): print("Success!") -@task -def destroy(ctx, debug=False): +def destroy(debug=False): """ Destroy a k8s cluster initialised with `inv kubeadm.create` """ diff --git a/tasks/operator.py b/tasks/operator.py index 25a3236..84c6670 100644 --- a/tasks/operator.py +++ b/tasks/operator.py @@ -1,4 +1,3 @@ -from invoke import task from os.path import join from tasks.util.env import CONTAINERD_CONFIG_FILE, KATA_CONFIG_DIR, print_dotted_line from tasks.util.kubeadm import ( @@ -13,7 +12,6 @@ OPERATOR_NAMESPACE = "confidential-containers-system" -@task def install(ctx, debug=False): """ Install the cc-operator on the cluster @@ -36,7 +34,6 @@ def install(ctx, debug=False): print("Success!") -@task def install_cc_runtime(ctx, debug=False): """ Install the CoCo runtime through the operator @@ -118,7 +115,6 @@ def install_cc_runtime(ctx, debug=False): print("Success!") -@task def uninstall(ctx): """ Uninstall the operator @@ -129,7 +125,6 @@ def uninstall(ctx): run_kubectl_command("delete -k {}".format(operator_url)) -@task def uninstall_cc_runtime(ctx): """ Un-install the CoCo runtimes from the k8s cluster diff --git a/tasks/sc2.py b/tasks/sc2.py index 95cdab8..13faab9 100644 --- a/tasks/sc2.py +++ b/tasks/sc2.py @@ -3,7 +3,9 @@ from os.path import exists, join from subprocess import run from tasks.containerd import install as containerd_install -from tasks.demo_apps import push_to_local_registry as push_demo_apps_to_local_registry +from tasks.demo_apps import ( + do_push_to_local_registry as push_demo_apps_to_local_registry, +) from tasks.k8s import install as k8s_tooling_install from tasks.k9s import install as k9s_install from tasks.knative import install as knative_install @@ -229,25 +231,25 @@ def deploy(ctx, debug=False, clean=False): run("sudo swapoff -a", shell=True, check=True) # Build and install containerd - containerd_install(ctx, debug=debug, clean=clean) + containerd_install(debug=debug, clean=clean) # Install k8s tooling (including k9s) - k8s_tooling_install(ctx, debug=debug, clean=clean) - k9s_install(ctx, debug=debug) + k8s_tooling_install(debug=debug, clean=clean) + k9s_install(debug=debug) # Create a single-node k8s cluster - k8s_create(ctx, debug=debug) + k8s_create(debug=debug) # Install the CoCo operator as well as the CC-runtimes - operator_install(ctx, debug=debug) - operator_install_cc_runtime(ctx, debug=debug) + operator_install(debug=debug) + operator_install_cc_runtime(debug=debug) # Start a local docker registry (must happen before knative installation, # as we rely on it to host our sidecar image) start_local_registry(debug=debug, clean=clean) # Install Knative - knative_install(ctx, debug=debug) + knative_install(debug=debug) # Apply general patches to the Kata Agent (and initrd), making sure we # have the latest patched version @@ -274,7 +276,7 @@ def deploy(ctx, debug=False, clean=False): restart_containerd(debug=debug) # Push demo apps to local registry for easy testing - push_demo_apps_to_local_registry(ctx, debug=debug) + push_demo_apps_to_local_registry(debug=debug) # Finally, create a deployment file (right now, it is empty) if not exists(SC2_CONFIG_DIR): @@ -308,7 +310,7 @@ def destroy(ctx, debug=False): stop_local_registry(debug=debug) # Destroy k8s cluster - k8s_destroy(ctx, debug=debug) + k8s_destroy(debug=debug) # Remove deployment file result = run(f"rm -f {SC2_DEPLOYMENT_FILE}", shell=True, capture_output=True) From 1fe33f79bd9bb3c3475cdf5733ee72c23ed5a9f7 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 19 Dec 2024 16:17:39 +0000 Subject: [PATCH 2/2] fix: remove ctx from operator --- tasks/operator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/operator.py b/tasks/operator.py index 84c6670..110b3ee 100644 --- a/tasks/operator.py +++ b/tasks/operator.py @@ -12,7 +12,7 @@ OPERATOR_NAMESPACE = "confidential-containers-system" -def install(ctx, debug=False): +def install(debug=False): """ Install the cc-operator on the cluster """ @@ -34,7 +34,7 @@ def install(ctx, debug=False): print("Success!") -def install_cc_runtime(ctx, debug=False): +def install_cc_runtime(debug=False): """ Install the CoCo runtime through the operator """ @@ -115,7 +115,7 @@ def install_cc_runtime(ctx, debug=False): print("Success!") -def uninstall(ctx): +def uninstall(): """ Uninstall the operator """ @@ -125,7 +125,7 @@ def uninstall(ctx): run_kubectl_command("delete -k {}".format(operator_url)) -def uninstall_cc_runtime(ctx): +def uninstall_cc_runtime(): """ Un-install the CoCo runtimes from the k8s cluster """