Skip to content

Commit 597bbad

Browse files
committed
feat: preload runtimes only default apache
preload runtime is now configured to use only default apache openserverless multi arch runtimes
1 parent 8ccb046 commit 597bbad

File tree

7 files changed

+306
-66
lines changed

7 files changed

+306
-66
lines changed

deploy/nuvolaris-permissions/whisk-crd.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ spec:
8585
type: boolean
8686
slim:
8787
description: boolean flag to enable/disable nuvolaris slim mode. Defaulted to false
88-
type: boolean
88+
type: boolean
89+
preload:
90+
description: used to preload some default actions in the nuvolaris namespace. Defaulted to false
91+
type: object
92+
properties:
93+
only-apache:
94+
description: boolean flag to preload only the apache openserverless actions
95+
type: boolean
96+
required:
97+
- only-apache
8998
required:
9099
- password
91100
components:

nuvolaris/runtimes_preloader.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
def create(owner=None):
2727
logging.info(f"*** configuring runtime preloader")
28+
only_apache = cfg.get("nuvolaris.preloader.only_apache", defval=True)
2829

2930
runtimes_as_json = util.get_runtimes_json_from_config_map()
30-
data=rutil.parse_runtimes(json.loads(runtimes_as_json))
31-
31+
data=rutil.parse_runtimes(json.loads(runtimes_as_json), only_apache)
32+
3233
kust = kus.patchTemplates("runtimes", ["runtimes-job-container-attach.yaml"], data)
3334
spec = kus.kustom_list("runtimes", kust, templates=[], data=data)
3435

@@ -42,8 +43,6 @@ def create(owner=None):
4243
logging.info("*** configured runtime preloader")
4344
return res
4445

45-
46-
4746
def delete_by_owner():
4847
spec = kus.build("runtimes")
4948
res = kube.delete(spec)

nuvolaris/runtimes_util.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import nuvolaris.config as cfg
2222
import nuvolaris.util as util
2323

24-
def find_default_container(containers: list, container_name, runtime_list):
24+
def find_default_container(containers: list, container_name, runtime_list, only_apache=True):
2525
""" Scans for the inner runtime list and add an entry into the containers for the default one if any
2626
:param containers, the global containers array
2727
:param container_name, the name that will be assigned for the containers preloader
@@ -30,26 +30,28 @@ def find_default_container(containers: list, container_name, runtime_list):
3030
for runtime in runtime_list:
3131
if runtime['default']:
3232
img = runtime['image']
33-
container = {
34-
"name": container_name,
35-
"image": f"{img['prefix']}/{img['name']}:{img['tag']}"
36-
}
37-
containers.append(container)
33+
is_apache = img['prefix'] == 'apache'
34+
if not only_apache or is_apache:
35+
container = {
36+
"name": container_name,
37+
"image": f"{img['prefix']}/{img['name']}:{img['tag']}"
38+
}
39+
containers.append(container)
3840

39-
def parse_runtimes(runtimes_as_json):
41+
def parse_runtimes(runtimes_as_json, only_apache=True):
4042
""" parse an openwhisk runtimes json and returns a stuitable data structure to customize the preloader jon
4143
:param runtimes_as_json a runtime json typically extracted from a config map
4244
>>> import nuvolaris.testutil as tutil
4345
>>> runtimes_as_json = tutil.load_sample_runtimes()
4446
>>> data = parse_runtimes(runtimes_as_json)
45-
>>> len(data['containers']) == 8
47+
>>> len(data['containers']) == 5
4648
True
4749
"""
4850
data = {}
4951
containers = list()
5052

5153
for name in runtimes_as_json["runtimes"]:
52-
find_default_container(containers, name, runtimes_as_json["runtimes"][name])
54+
find_default_container(containers, name, runtimes_as_json["runtimes"][name], only_apache)
5355

5456
data['containers']=containers
5557
return data

nuvolaris/testutil.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#
1818
import yaml
1919
import re
20-
import flatdict
2120
import json
2221
import time
2322
import os
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import nuvolaris.config as cfg
2+
import nuvolaris.runtimes_preloader as preloader
3+
import nuvolaris.util as util
4+
import nuvolaris.runtimes_util as rutil
5+
import nuvolaris.testutil as tu
6+
import nuvolaris.kube as kube
7+
import json
8+
9+
def cleanup():
10+
try:
11+
get_ipython().system("kubectl -n nuvolaris delete all --all")
12+
get_ipython().system("kubectl -n nuvolaris delete pvc --all")
13+
except NameError:
14+
import subprocess
15+
subprocess.run(["kubectl", "-n", "nuvolaris", "delete", "all", "--all"], check=True)
16+
subprocess.run(["kubectl", "-n", "nuvolaris", "delete", "pvc", "--all"], check=True)
17+
18+
19+
cleanup()
20+
21+
# Test with Apache runtimes
22+
assert(cfg.configure(tu.load_sample_config()))
23+
assert(preloader.create())
24+
25+
# Wait for the job to complete
26+
while not kube.wait("job.batch/preload-runtimes", "condition=complete"): pass
27+
28+
runtimes_as_json = util.get_runtimes_json_from_config_map()
29+
data=rutil.parse_runtimes(json.loads(runtimes_as_json))
30+
31+
assert(len(data['containers']) > 0), "Expected one or more containers in the preloader data"
32+
for container in data['containers']:
33+
print(f"Container: {container['name']}, Image: {container['image']}")
34+
assert('name' in container), "Expected 'name' in container"
35+
assert('image' in container), "Expected 'image' in container"
36+
37+
count_apache = sum(1 for container in data['containers'] if container['image'].startswith('apache/'))
38+
count_non_apache = len(data['containers']) - count_apache
39+
40+
assert(count_apache > 0), "Expected at least one Apache runtime in the preloader data"
41+
assert(count_non_apache == 0), "Expected no non-Apache runtimes in the preloader data"
42+
43+
assert(preloader.delete())
44+
cleanup()

tests/kind/whisk-slim.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ spec:
6060
provisioner: auto #rancher.io/local-path
6161
ingressclass: auto #nginx
6262
ingresslb: auto #ingress-nginx/ingress-nginx-controller
63-
slim: True
64-
affinity: true
65-
tolerations: true
63+
slim: true
64+
affinity: false
65+
tolerations: false
66+
preload:
67+
only-apache: true
6668
couchdb:
6769
host: couchdb
6870
port: 5984

0 commit comments

Comments
 (0)