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

Fix pylint warnings in ocw/lib/k8s.py #294

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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.")