Skip to content

Commit

Permalink
add lock to the create_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
TZ-zzz committed May 11, 2024
1 parent e9886ea commit 1fe257f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions acto/kubernetes_engine/kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import time
from typing import Any, Dict, List
from filelock import FileLock

import kubernetes
import yaml
Expand All @@ -16,6 +17,8 @@
class Kind(base.KubernetesEngine):
"""Kind engine for provisioning Kubernetes"""

lock = FileLock("file_lock.txt.lock")

def __init__(
self,
acto_namespace: int,
Expand Down Expand Up @@ -92,6 +95,7 @@ def create_cluster(self, name: str, kubeconfig: str):
config: path of the config file for cluster
version: k8s version
"""
self.lock.acquire()
print_event("Creating a Kind cluster...")
cmd = ["kind", "create", "cluster"]

Expand Down Expand Up @@ -140,6 +144,8 @@ def create_cluster(self, name: str, kubeconfig: str):
if self._posthooks:
for posthook in self._posthooks:
posthook(apiclient=apiclient)

self.lock.release()

def load_images(self, images_archive_path: str, name: str):
logging.info("Loading preload images")
Expand Down

0 comments on commit 1fe257f

Please sign in to comment.