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

[BV-599] Kubeconfig helper #281

Merged
merged 19 commits into from
Feb 14, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
simplify + metadata types enum
  • Loading branch information
Franr committed Nov 24, 2024
commit 250534df024049eb2cd840e7d4beb6ae598212ce
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
Loading