Skip to content

Commit

Permalink
Use the Minikube context instead of run_steps_minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
ssorj committed Jan 16, 2024
1 parent 263aa37 commit b3aefd9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
60 changes: 29 additions & 31 deletions python/skewer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from plano import *

__all__ = [
"generate_readme", "run_steps_minikube", "run_steps", "Minikube",
"generate_readme", "run_steps", "Minikube",
]

standard_text = read_yaml(join(get_parent_dir(__file__), "standardtext.yaml"))
Expand Down Expand Up @@ -109,33 +109,6 @@ def await_console_ok():

await_http_ok("service/skupper", "https://{}:8010/", user="admin", password=password)

def run_steps_minikube(skewer_file, debug=False):
notice("Running steps on Minikube")

check_environment()
check_program("minikube")

model = Model(skewer_file)
model.check()

kube_sites = [x for _, x in model.sites if x.platform == "kubernetes"]
kubeconfigs = list()

make_dir("/tmp/skewer", quiet=True)

with Minikube():
for site in kube_sites:
kubeconfig = site.env["KUBECONFIG"].replace("~", "/tmp/skewer")
site.env["KUBECONFIG"] = kubeconfig

kubeconfigs.append(kubeconfig)

with site:
run("minikube -p skewer update-context")
check_file(ENV["KUBECONFIG"])

run_steps(skewer_file, kubeconfigs=kubeconfigs, debug=debug)

def run_steps(skewer_file, kubeconfigs=[], debug=False):
notice(f"Running steps (skewer_file='{skewer_file}', kubeconfigs={kubeconfigs})")

Expand Down Expand Up @@ -371,7 +344,7 @@ def get_github_owner_repo():
return path.split("/", 1)

if result.scheme in ("http", "https") and result.netloc == "github.com":
path = remove_prefix(result.path, "/", result.path)
path = remove_prefix(result.path, "/")

return path.split("/", 1)

Expand Down Expand Up @@ -663,17 +636,42 @@ def check(self):
check_unknown_attributes(self)

class Minikube:
def __init__(self, skewer_file):
self.skewer_file = skewer_file
self.kubeconfigs = list()

def __enter__(self):
notice("Starting Minikube")

check_environment()
check_program("minikube")

make_dir("/tmp/skewer", quiet=True)
run("minikube -p skewer start --auto-update-drivers false")

make_dir("/tmp/skewer", quiet=True)
tunnel_output_file = open("/tmp/skewer/minikube-tunnel-output", "w")

self.tunnel = start("minikube -p skewer tunnel", output=tunnel_output_file)

model = Model(self.skewer_file)
model.check()

kube_sites = [x for _, x in model.sites if x.platform == "kubernetes"]

for site in kube_sites:
kubeconfig = site.env["KUBECONFIG"].replace("~", "/tmp/skewer")
site.env["KUBECONFIG"] = kubeconfig

self.kubeconfigs.append(kubeconfig)

with site:
run("minikube -p skewer update-context")
check_file(ENV["KUBECONFIG"])

return self

def __exit__(self, exc_type, exc_value, traceback):
notice("Stopping Minikube")

stop(self.tunnel)

run("minikube -p skewer delete")
16 changes: 7 additions & 9 deletions python/skewer/planocommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
""".strip()

@command
def generate():
def generate(output="README.md"):
"""
Generate README.md from the data in skewer.yaml
"""
generate_readme("skewer.yaml", "README.md")
generate_readme("skewer.yaml", output)

@command
def render(verbose=False, quiet=False):
Expand Down Expand Up @@ -88,7 +88,8 @@ def run_(*kubeconfigs, debug=False):
Run the example steps
"""
if not kubeconfigs:
run_steps_minikube("skewer.yaml", debug=debug)
with Minikube("skewer.yaml") as mk:
run_steps("skewer.yaml", mk.kubeconfigs, debug=debug)
else:
run_steps("skewer.yaml", kubeconfigs, debug=debug)

Expand All @@ -98,18 +99,15 @@ def demo(*kubeconfigs, debug=False):
Run the example steps and pause for a demo before cleaning up
"""
with working_env(SKEWER_DEMO=1):
if not kubeconfigs:
run_steps_minikube("skewer.yaml", debug=debug)
else:
run_steps("skewer.yaml", kubeconfigs, debug=debug)
run_(*kubeconfigs, debug=debug)

@command
def test_(debug=False):
"""
Test README generation and run the steps
"""
generate_readme("skewer.yaml", make_temp_file())
run_steps_minikube("skewer.yaml", debug=debug)
generate(output=make_temp_file())
run_(debug=debug)

@command
def update_skewer():
Expand Down
12 changes: 7 additions & 5 deletions python/skewer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ def generate_readme_():
check_file("README.md")

@test
def run_steps():
def run_steps_():
with working_dir("example"):
run_steps_minikube("skewer.yaml", debug=True)
with Minikube("skewer.yaml") as mk:
run_steps("skewer.yaml", kubeconfigs=mk.kubeconfigs, debug=True)

@test
def run_steps_demo():
with working_dir("example"):
with working_env(SKEWER_DEMO=1, SKEWER_DEMO_NO_WAIT=1):
run_steps_minikube("skewer.yaml", debug=True)
with Minikube("skewer.yaml") as mk:
run_steps("skewer.yaml", kubeconfigs=mk.kubeconfigs, debug=True)

@test
def run_steps_debug():
with working_dir("example"):
with expect_error():
with working_env(SKEWER_FAIL=1):
run_steps_minikube("skewer.yaml", debug=True)
with Minikube("skewer.yaml") as mk:
run_steps("skewer.yaml", kubeconfigs=mk.kubeconfigs, debug=True)

if __name__ == "__main__":
import sys
Expand Down

0 comments on commit b3aefd9

Please sign in to comment.