Skip to content

Commit

Permalink
Fix pylint warnings in ocw/lib/k8s.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pdostal committed Aug 10, 2023
1 parent cecc978 commit 5469af7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ocw/lib/aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ocw/lib/eks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ocw/lib/gke.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 8 additions & 8 deletions ocw/lib/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

0 comments on commit 5469af7

Please sign in to comment.