Skip to content

Commit

Permalink
Merge pull request #156 from oharan2/prefix
Browse files Browse the repository at this point in the history
Allow filter by cluster prefix
  • Loading branch information
jyejare authored Jan 30, 2025
2 parents e7e4571 + 6188149 commit c92a058
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cloudwash/entities/resources/ocps.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ def cleanup(self):

class CleanAWSOcps(CleanOCPs):
def list(self):
time_threshold = calculate_time_threshold(time_ref=settings.aws.criteria.ocps.sla)

query = " ".join([f"tag.key:{OCP_TAG_SUBSTR}*", f"region:{self.client.cleaning_region}"])
resources = self.client.list_resources(query=query)
resources = []
time_threshold = calculate_time_threshold(time_ref=settings.aws.criteria.ocps.get("SLA"))

ocp_prefix = list(settings.aws.criteria.ocps.get("OCP_PREFIXES") or [""])
for prefix in ocp_prefix:
query = " ".join(
[f"tag.key:{OCP_TAG_SUBSTR}{prefix}*", f"region:{self.client.cleaning_region}"]
)
resources.extend(self.client.list_resources(query=query))

# Prepare resources to be filtered before deletion
cluster_map = group_ocps_by_cluster(resources=resources)
Expand Down
4 changes: 4 additions & 0 deletions conf/aws.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ AWS:
# Specified as {time_value}{time_unit} format, e.g. "7d" = 7 Days
# If a time unit is not specified (the value is numeric), it will be considered as Minutes
SLA: 7d
# Specify OCP clusters prefix to filter by, for example: '["my_project_", "openshift-"]' etc..
# Regular expression based prefix is not supported
# Won't be considered if not given
OCP_PREFIXES: []
EXCEPTIONS:
VM:
# VM names that would be skipped from cleanup
Expand Down
4 changes: 4 additions & 0 deletions settings.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ AWS:
# Specified as {time_value}{time_unit} format, e.g. "7d" = 7 Days
# If a time unit is not specified (the value is numeric), it will be considered as Minutes
SLA: 7d
# Specify OCP clusters prefix to filter by, for example: ["my_project_", "openshift-"] etc..
# Regular expression based prefix is not supported
# Won't be considered if not given
OCP_PREFIXES: []
EXCEPTIONS:
VM:
# VM names that would be skipped from cleanup
Expand Down

0 comments on commit c92a058

Please sign in to comment.