Skip to content

Commit

Permalink
Use delta to get the preload images
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gu <[email protected]>
  • Loading branch information
tylergu committed Sep 11, 2024
1 parent 692d794 commit 9f68ca3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 52 deletions.
16 changes: 13 additions & 3 deletions acto/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
from acto.runner import Runner
from acto.serialization import ActoEncoder, ContextEncoder
from acto.snapshot import Snapshot
from acto.utils import delete_operator_pod, process_crd, update_preload_images
from acto.utils import delete_operator_pod, process_crd
from acto.utils.preprocess import get_existing_images
from acto.utils.thread_logger import get_thread_logger, set_thread_logger_prefix
from ssa.analysis import analyze

Expand Down Expand Up @@ -945,6 +946,11 @@ def __learn(self, context_file, helper_crd, analysis_only=False):
)

self.cluster.restart_cluster("learn", learn_kubeconfig)

existing_images = get_existing_images(
self.cluster.get_node_list("learn")
)

namespace = (
self.deploy.operator_existing_namespace or CONST.ACTO_NAMESPACE
)
Expand Down Expand Up @@ -992,9 +998,13 @@ def __learn(self, context_file, helper_crd, analysis_only=False):
"Please make sure the operator config is correct"
)

update_preload_images(
self.context, self.cluster.get_node_list("learn")
current_images = get_existing_images(
self.cluster.get_node_list("learn")
)
for current_image in current_images:
if current_image not in existing_images:
self.context["preload_images"].add(current_image)

self.cluster.delete_cluster("learn", learn_kubeconfig)

run_end_time = time.time()
Expand Down
54 changes: 5 additions & 49 deletions acto/utils/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,9 @@
from .thread_logger import get_thread_logger


def update_preload_images(context: dict, worker_list):
"""Get used images from pod"""
logger = get_thread_logger(with_prefix=False)

namespace = context.get("namespace", "")
if not namespace:
return

# block list when getting the operator specific images
k8s_images = [
"docker.io/kindest/kindnetd",
"docker.io/rancher/local-path-provisioner",
"docker.io/kindest/local-path-provisioner",
"docker.io/kindest/local-path-helper",
"k8s.gcr.io/build-image/debian-base",
"k8s.gcr.io/coredns/coredns",
"k8s.gcr.io/etcd",
"k8s.gcr.io/kube-apiserver",
"k8s.gcr.io/kube-controller-manager",
"k8s.gcr.io/kube-proxy",
"k8s.gcr.io/kube-scheduler",
"k8s.gcr.io/pause",
"docker.io/rancher/klipper-helm",
"docker.io/rancher/klipper-lb",
"docker.io/rancher/mirrored-coredns-coredns",
"docker.io/rancher/mirrored-library-busybox",
"docker.io/rancher/mirrored-library-traefik",
"docker.io/rancher/mirrored-metrics-server",
"docker.io/rancher/mirrored-paus",
# new k8s images
"registry.k8s.io/etcd",
"registry.k8s.io/kube-controller-manager",
"registry.k8s.io/pause",
"registry.k8s.io/kube-proxy",
"registry.k8s.io/coredns/coredns",
"registry.k8s.io/kube-apiserver",
"registry.k8s.io/kube-scheduler",
]

def get_existing_images(worker_list: list[str]) -> set[str]:
"""Get existing images from pods"""
existing_images = set()
for worker in worker_list:
p = subprocess.run(
[
Expand All @@ -69,18 +33,10 @@ def update_preload_images(context: dict, worker_list):
output = p.stdout.strip()
for line in output.split("\n")[1:]:
items = line.split()
if items[0] in k8s_images:
continue
if "none" not in items[1]:
image = f"{items[0]}:{items[1]}"
else:
logger.warning(
"image %s has no tag, Acto will not preload this image for this run",
items[0],
)
continue

context["preload_images"].add(image)
existing_images.add(image)
return existing_images


def process_crd(
Expand Down

0 comments on commit 9f68ca3

Please sign in to comment.