xds/cleanup: fix error datetime fromisoformat not available (#28953)

pull/28976/head
Menghan Li 3 years ago committed by GitHub
parent 0f73576b17
commit 87068e02c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      tools/run_tests/xds_k8s_test_driver/bin/cleanup/cleanup.py
  2. 1
      tools/run_tests/xds_k8s_test_driver/requirements.txt

@ -35,6 +35,7 @@ from typing import Any, List
from absl import app
from absl import flags
import dateutil
from framework import xds_flags
from framework import xds_k8s_flags
@ -49,7 +50,6 @@ Json = Any
KubernetesClientRunner = client_app.KubernetesClientRunner
KubernetesServerRunner = server_app.KubernetesServerRunner
KEEP_PERIOD = datetime.timedelta(days=7)
GCLOUD = os.environ.get('GCLOUD', 'gcloud')
GCLOUD_CMD_TIMEOUT_S = datetime.timedelta(seconds=5).total_seconds()
ZONE = 'us-central1-a'
@ -58,6 +58,12 @@ SECONDARY_ZONE = 'us-west1-b'
PSM_SECURITY_PREFIX = 'xds-k8s-security' # Prefix for gke resources to delete.
URL_MAP_TEST_PREFIX = 'interop-psm-url-map' # Prefix for url-map test resources to delete.
KEEP_PERIOD_HOURS = flags.DEFINE_integer(
"keep_hours",
default=168,
help=
"number of hours for a resource to keep. Resources older than this will be deleted. Default is 168 (7 days)"
)
DRY_RUN = flags.DEFINE_bool(
"dry_run",
default=False,
@ -103,7 +109,8 @@ def is_marked_as_keep_gke(suffix: str) -> bool:
@functools.lru_cache()
def get_expire_timestamp() -> datetime.datetime:
return datetime.datetime.now(datetime.timezone.utc) - KEEP_PERIOD
return datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(
hours=KEEP_PERIOD_HOURS.value)
def exec_gcloud(project: str, *cmds: List[str]) -> Json:
@ -337,7 +344,7 @@ def main(argv):
compute = gcp.compute.ComputeV1(gcp.api.GcpApiManager(), project)
leakedHealthChecks = []
for item in compute.list_health_check()['items']:
if datetime.datetime.fromisoformat(
if dateutil.parser.isoparse(
item['creationTimestamp']) <= get_expire_timestamp():
leakedHealthChecks.append(item)

@ -16,5 +16,6 @@ six~=1.13
tenacity~=6.2
packaging~=21.3
Pygments~=2.9
python-dateutil~=2.8
protobuf~=3.14
xds-protos~=0.0.8

Loading…
Cancel
Save