forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ksonnet utilities for testing. (kubeflow#271)
* ksonnet utilities for testing. * Create a new module ks_util for common utilities related to ksonnet. * Move the function get_ksonnet_cmd from run_e2e_workflow.py into ks_util * We want to reuse this function e.g. to submit TFJobs as part of E2E testing. * Move setup_ks_app from https://github.com/kubeflow/tf-operator/blob/master/py/ks_util.py so it can be reused by other tests not just tf-operator. * Fix. * Update setup_ks_app to use the new command. * Add missing yaml import. * Fix lint.
- Loading branch information
1 parent
ac58d1c
commit bccafbf
Showing
2 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Utilities for working with ksonnet in the tests.""" | ||
|
||
import filelock | ||
import logging | ||
import os | ||
import re | ||
import subprocess | ||
import yaml | ||
|
||
from kubeflow.testing import util | ||
|
||
def setup_ks_app(app_dir, env, namespace, component, params, ks_cmd=None): | ||
"""Setup the ksonnet app""" | ||
|
||
if not ks_cmd: | ||
ks_cmd = get_ksonnet_cmd(app_dir) | ||
|
||
lock_file = os.path.join(app_dir, "app.lock") | ||
logging.info("Acquiring lock on file: %s", lock_file) | ||
lock = filelock.FileLock(lock_file, timeout=60) | ||
with lock: | ||
# Create a new environment for this run | ||
try: | ||
util.run([ks_cmd, "env", "add", env, "--namespace=" + namespace], | ||
cwd=app_dir) | ||
except subprocess.CalledProcessError as e: | ||
if not re.search(".*environment.*already exists.*", e.output): | ||
raise | ||
|
||
for pair in params.split(","): | ||
k, v = pair.split("=", 1) | ||
util.run([ks_cmd, "param", "set", "--env=" + env, component, k, v], | ||
cwd=app_dir) | ||
|
||
def get_ksonnet_cmd(app_dir): | ||
"""Get the ksonnet command based on the apiVersion in app.yaml. | ||
Args: | ||
app_dir: Directory of the ksonnet application. | ||
Returns: | ||
ks_cmd: Path to the ks binary to use. | ||
""" | ||
app_yaml_file = app_dir + "/app.yaml" | ||
with open(app_yaml_file) as app_yaml: | ||
results = yaml.load(app_yaml) | ||
|
||
if results["apiVersion"] == "0.1.0": | ||
return "ks" | ||
|
||
if results["apiVersion"] == "0.2.0": | ||
return "ks-12" | ||
|
||
# For compatibility reasons we'll keep the default cmd as "ks". | ||
return "ks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters