From 250534df024049eb2cd840e7d4beb6ae598212ce Mon Sep 17 00:00:00 2001 From: Francisco Rivera Date: Sun, 24 Nov 2024 18:26:49 -0300 Subject: [PATCH] simplify + metadata types enum --- leverage/containers/kubectl.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/leverage/containers/kubectl.py b/leverage/containers/kubectl.py index af131d0..66310f8 100644 --- a/leverage/containers/kubectl.py +++ b/leverage/containers/kubectl.py @@ -1,5 +1,6 @@ import os from dataclasses import dataclass +from enum import Enum from pathlib import Path from click.exceptions import Exit @@ -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.""" @@ -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: @@ -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