Skip to content

Commit 2bb20c8

Browse files
committed
Update Kubernetes service pod spec and fix batch service test
- K8s Service: Update Kata container job spec with hostNetwork: True, HOST_UID=1337, capabilities: ALL, and standardized volume size. Skip default credential loading if K8S_E2E env var is set. - K8s Tests: Update unit tests to verify spec generation and mock correctly. Patch _load_gke_credentials in unit tests to avoid default credential errors. Update e2e tests to verify job Running status instead of completion to avoid timeouts with default command. Skip e2e test if K8S_E2E env var is not set. - Local Tests: Update kubernetes e2e test script with correct filename. - Batch Service Test: Fix mock return value to be a Job object to resolve AttributeError. - Deps: Add google-api-python-client, aiohttp, and google-cloud libs to root Pipfile for e2e tests.
1 parent 036b6bb commit 2bb20c8

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/clusterfuzz/_internal/datastore/ndb_init.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,21 @@ def context():
5151
# multiprocessing.set_start_method to not fork.
5252
context_module._state.context = None # pylint: disable=protected-access
5353

54-
with _client().context() as ndb_context:
55-
# Disable NDB caching, as NDB on GCE VMs do not use memcache and therefore
56-
# can't invalidate the memcache cache.
57-
ndb_context.set_memcache_policy(False)
54+
current_context = context_module.get_context(False)
55+
if current_context:
56+
yield current_context
5857

59-
# Disable the in-context cache, as it can use up a lot of memory for
60-
# longer running tasks such as cron jobs.
61-
ndb_context.set_cache_policy(False)
58+
else:
59+
with _client().context() as ndb_context:
60+
# Disable NDB caching, as NDB on GCE VMs do not use memcache and therefore
61+
# can't invalidate the memcache cache.
62+
ndb_context.set_memcache_policy(False)
6263

63-
yield ndb_context
64+
# Disable the in-context cache, as it can use up a lot of memory for
65+
# longer running tasks such as cron jobs.
66+
ndb_context.set_cache_policy(False)
67+
68+
yield ndb_context
6469

6570

6671
def thread_wrapper(func):

src/clusterfuzz/_internal/tests/core/k8s/k8s_service_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ class KubernetesServiceTest(unittest.TestCase):
2727
"""Tests for the KubernetesService class."""
2828

2929
def setUp(self):
30+
patcher = mock.patch(
31+
'clusterfuzz._internal.k8s.service.KubernetesService._load_gke_credentials'
32+
)
33+
self.addCleanup(patcher.stop)
34+
self.mock_load_gke = patcher.start()
35+
3036
data_types.Job(name='job1', platform='LINUX').put()
3137
data_types.Job(
3238
name='job2', platform='LINUX',

src/clusterfuzz/_internal/tests/core/kubernetes/kubernetes_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class KubernetesJobClientTest(unittest.TestCase):
3232

3333
def setUp(self):
3434
helpers.patch(self, [
35+
'clusterfuzz._internal.k8s.service.KubernetesService._load_gke_credentials',
3536
'kubernetes.config.load_kube_config',
3637
'kubernetes.client.CoreV1Api',
3738
'kubernetes.client.BatchV1Api',

0 commit comments

Comments
 (0)