Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock to avoid failure during clusters creation #389

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading