From 5469af74ca49e7b83f76af6568094bdff2388b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dost=C3=A1l?= Date: Thu, 10 Aug 2023 13:20:53 +0200 Subject: [PATCH] Fix pylint warnings in ocw/lib/k8s.py --- ocw/lib/aks.py | 2 +- ocw/lib/eks.py | 2 +- ocw/lib/gke.py | 2 +- ocw/lib/k8s.py | 16 ++++++++-------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ocw/lib/aks.py b/ocw/lib/aks.py index 18de9c00..38a9b4a7 100644 --- a/ocw/lib/aks.py +++ b/ocw/lib/aks.py @@ -53,4 +53,4 @@ def cleanup_k8s_namespaces(self): for cluster in clusters: self.log_info(f"Cleaning namespaces in AKS cluster {cluster['cluster_name']}") client = self.kubectl_client(cluster["resource_group"], cluster["cluster_name"]).CoreV1Api() - clean_namespaces(self, client, cluster["cluster_name"]) + clean_namespaces(self, client) diff --git a/ocw/lib/eks.py b/ocw/lib/eks.py index 5feb8d62..6f7b6d46 100644 --- a/ocw/lib/eks.py +++ b/ocw/lib/eks.py @@ -172,4 +172,4 @@ def cleanup_k8s_namespaces(self): for cluster_name in clusters: self.log_info(f"Cleaning namespaces in EKS cluster {cluster_name} in region {region}") client = self.kubectl_client(region, cluster_name).CoreV1Api() - clean_namespaces(self, client, cluster_name) + clean_namespaces(self, client) diff --git a/ocw/lib/gke.py b/ocw/lib/gke.py index 97ca0dca..f3d2ccdc 100644 --- a/ocw/lib/gke.py +++ b/ocw/lib/gke.py @@ -74,4 +74,4 @@ def cleanup_k8s_namespaces(self): cluster_name = cluster["name"] self.log_info(f"Cleaning namespaces in GKE cluster {cluster_name} in zone {zone}") client = self.kubectl_client(zone, cluster).CoreV1Api() - clean_namespaces(self, client, cluster_name) + clean_namespaces(self, client) diff --git a/ocw/lib/k8s.py b/ocw/lib/k8s.py index dfed0e8d..5bdc3f15 100644 --- a/ocw/lib/k8s.py +++ b/ocw/lib/k8s.py @@ -18,19 +18,19 @@ def clean_jobs(provider: Provider, client: BatchV1Api, cluster_name: str): f"with age {age} (days)") -def clean_namespaces(provider: Provider, client: CoreV1Api, cluster_name: str): +def clean_namespaces(provider: Provider, client: CoreV1Api): now = datetime.now(timezone.utc) # Retrieve the list of all namespaces namespaces = client.list_namespace(watch=False) - for ns in namespaces.items: - age = (now - ns.metadata.creation_timestamp).days - if ns.metadata.name.startswith('helm-test') and age > 7: + for namespace in namespaces.items: + age = (now - namespace.metadata.creation_timestamp).days + if namespace.metadata.name.startswith('helm-test') and age > 7: # Delete the namespace if provider.dry_run: - provider.log_info(f"Skip deleting namespace {ns.metadata.name} created {ns.metadata.creation_timestamp}") + provider.log_info(f"Skip deleting namespace {namespace.metadata.name} created {namespace.metadata.creation_timestamp}.") else: - provider.log_info(f"Deleting namespace {ns.metadata.name} created {ns.metadata.creation_timestamp}") - client.delete_namespace(ns.metadata.name) + provider.log_info(f"Deleting namespace {namespace.metadata.name} created {namespace.metadata.creation_timestamp}.") + client.delete_namespace(namespace.metadata.name) else: - provider.log_dbg(f"Namespace {ns.metadata.name} will be kept.") + provider.log_dbg(f"Namespace {namespace.metadata.name} will be kept.")