Skip to content

Commit

Permalink
simplify + metadata types enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Franr committed Nov 24, 2024
1 parent 7e2f57c commit 250534d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions leverage/containers/kubectl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from dataclasses import dataclass
from enum import Enum
from pathlib import Path

from click.exceptions import Exit
Expand All @@ -19,6 +20,10 @@ class ClusterInfo:
region: str


class MetadataTypes(Enum):
K8S_CLUSTER = "k8s-eks-cluster"


class KubeCtlContainer(TerraformContainer):
"""Container specifically tailored to run kubectl commands."""

Expand Down Expand Up @@ -86,7 +91,7 @@ def _scan_clusters(self):
"""
for root, dirs, files in os.walk(self.paths.cwd):
# exclude hidden directories
dirs[:] = [d for d in dirs if not d[0] == "."]
dirs[:] = [d for d in dirs if d[0] != "."]

for file in files:
if file != self.METADATA_FILENAME:
Expand All @@ -96,10 +101,8 @@ def _scan_clusters(self):
try:
with open(cluster_file) as cluster_yaml_file:
data = ruamel.yaml.safe_load(cluster_yaml_file)
if data["type"] != "k8s-eks-cluster":
if data.get("type") != MetadataTypes.K8S_CLUSTER:
continue
except KeyError:
continue
except Exception as exc:
logger.warning(exc)
continue
Expand Down

0 comments on commit 250534d

Please sign in to comment.