Skip to content

Commit bbdd15d

Browse files
refactor(swap_encryption): use kubernetes_commands.ApplyManifest and fix imports
Replace manual temp-file + kubectl apply in _deploy_daemonset() with PKB's kubernetes_commands.ApplyManifest(): - Remove _daemonset_yaml() helper - _deploy_daemonset() delegates to kubernetes_commands.ApplyManifest( 'cluster/swap_encryption_daemonset.yaml.j2', **kwargs) - Add kubernetes_commands import; remove vm_util import (now unused) - Fix import order: providers.gcp before resources.container_service
1 parent 8ec990b commit bbdd15d

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

perfkitbenchmarker/linux_benchmarks/swap_encryption_benchmark.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
from perfkitbenchmarker import configs
7676
from perfkitbenchmarker import errors
7777
from perfkitbenchmarker import sample
78-
from perfkitbenchmarker import vm_util
79-
from perfkitbenchmarker.resources.container_service import kubectl
8078
from perfkitbenchmarker.providers.gcp import util as gcp_util
79+
from perfkitbenchmarker.resources.container_service import kubectl
80+
from perfkitbenchmarker.resources.container_service import kubernetes_commands
8181

8282
FLAGS = flags.FLAGS
8383

@@ -405,25 +405,6 @@ def __init__(self, project: str, zone: str) -> None:
405405
self.zone = zone
406406

407407

408-
def _daemonset_yaml(image: str) -> str:
409-
"""Render the privileged benchmark DaemonSet manifest.
410-
411-
The manifest is a PKB data file rendered with Jinja2
412-
(data/cluster/swap_encryption_daemonset.yaml.j2) rather than an inline
413-
string, per PKB conventions. The DaemonSet is pinned to the benchmark
414-
nodepool via nodeSelector so it never lands on the dummy default pool.
415-
"""
416-
return vm_util.ReadAndRenderJinja2Template(
417-
'cluster/swap_encryption_daemonset.yaml.j2',
418-
ds_name=_DS_NAME,
419-
ds_namespace=_DS_NAMESPACE,
420-
ds_label=_DS_LABEL,
421-
benchmark_nodepool=_BENCHMARK_NODEPOOL,
422-
image=image,
423-
kernel_version=_KERNEL_VERSION.value,
424-
)
425-
426-
427408
def GetConfig(user_config: dict[str, Any]) -> dict[str, Any]:
428409
"""Load and return benchmark config spec."""
429410
return configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)
@@ -665,12 +646,22 @@ def Cleanup(spec: _BenchmarkSpec) -> None:
665646

666647

667648
def _deploy_daemonset() -> None:
668-
"""Apply the benchmark DaemonSet manifest to the cluster."""
669-
manifest = _daemonset_yaml(image=_DAEMONSET_IMAGE.value)
670-
with vm_util.NamedTemporaryFile(mode='w', suffix='.yaml') as f:
671-
f.write(manifest)
672-
f.close()
673-
kubectl.RunKubectlCommand(['apply', '-f', f.name])
649+
"""Apply the benchmark DaemonSet manifest to the cluster.
650+
651+
Uses kubernetes_commands.ApplyManifest which renders the Jinja2 template
652+
from perfkitbenchmarker/data/cluster/swap_encryption_daemonset.yaml.j2,
653+
writes it to a temp file, and calls kubectl apply -f — the standard PKB
654+
pattern for deploying manifests.
655+
"""
656+
kubernetes_commands.ApplyManifest(
657+
'cluster/swap_encryption_daemonset.yaml.j2',
658+
ds_name=_DS_NAME,
659+
ds_namespace=_DS_NAMESPACE,
660+
ds_label=_DS_LABEL,
661+
benchmark_nodepool=_BENCHMARK_NODEPOOL,
662+
image=_DAEMONSET_IMAGE.value,
663+
kernel_version=_KERNEL_VERSION.value,
664+
)
674665
logging.info('[swap_encryption] DaemonSet applied')
675666

676667

0 commit comments

Comments
 (0)