Skip to content

Commit

Permalink
chore: reduce the number of user-facing tasks (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz authored Dec 19, 2024
1 parent e9ac038 commit 19936e5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 41 deletions.
3 changes: 1 addition & 2 deletions tasks/containerd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
14 changes: 9 additions & 5 deletions tasks/demo_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
4 changes: 1 addition & 3 deletions tasks/k8s.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from invoke import task
from os import makedirs
from os.path import exists, join
from shutil import rmtree
Expand Down Expand Up @@ -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
"""
Expand Down
4 changes: 1 addition & 3 deletions tasks/k9s.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from invoke import task
from os.path import join
from os import makedirs
from shutil import copy, rmtree
Expand All @@ -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
"""
Expand Down
6 changes: 2 additions & 4 deletions tasks/knative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions tasks/kubeadm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from invoke import task
from os import getegid, geteuid, makedirs
from os.path import exists
from shutil import rmtree
Expand All @@ -19,8 +18,7 @@
from time import sleep


@task
def create(ctx, debug=False):
def create(debug=False):
"""
Create a single-node k8s cluster
"""
Expand Down Expand Up @@ -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`
"""
Expand Down
13 changes: 4 additions & 9 deletions tasks/operator.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -13,8 +12,7 @@
OPERATOR_NAMESPACE = "confidential-containers-system"


@task
def install(ctx, debug=False):
def install(debug=False):
"""
Install the cc-operator on the cluster
"""
Expand All @@ -36,8 +34,7 @@ def install(ctx, debug=False):
print("Success!")


@task
def install_cc_runtime(ctx, debug=False):
def install_cc_runtime(debug=False):
"""
Install the CoCo runtime through the operator
"""
Expand Down Expand Up @@ -118,8 +115,7 @@ def install_cc_runtime(ctx, debug=False):
print("Success!")


@task
def uninstall(ctx):
def uninstall():
"""
Uninstall the operator
"""
Expand All @@ -129,8 +125,7 @@ def uninstall(ctx):
run_kubectl_command("delete -k {}".format(operator_url))


@task
def uninstall_cc_runtime(ctx):
def uninstall_cc_runtime():
"""
Un-install the CoCo runtimes from the k8s cluster
"""
Expand Down
22 changes: 12 additions & 10 deletions tasks/sc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19936e5

Please sign in to comment.