@@ -719,8 +719,11 @@ def should_job_info_be_shown(cluster_state):
719
719
720
720
721
721
def get_pod_uptime (pod_deployed_timestamp : str ):
722
- pod_creation_time = datetime .strptime (pod_deployed_timestamp , "%Y-%m-%dT%H:%M:%SZ" )
723
- pod_uptime = datetime .utcnow () - pod_creation_time
722
+ # NOTE: the k8s API returns timestamps in UTC, so we make sure to always work in UTC
723
+ pod_creation_time = datetime .strptime (
724
+ pod_deployed_timestamp , "%Y-%m-%dT%H:%M:%SZ"
725
+ ).replace (tzinfo = timezone .utc )
726
+ pod_uptime = datetime .now (timezone .utc ) - pod_creation_time
724
727
pod_uptime_total_seconds = pod_uptime .total_seconds ()
725
728
pod_uptime_days = divmod (pod_uptime_total_seconds , 86400 )
726
729
pod_uptime_hours = divmod (pod_uptime_days [1 ], 3600 )
@@ -730,7 +733,7 @@ def get_pod_uptime(pod_deployed_timestamp: str):
730
733
731
734
732
735
def append_pod_status (pod_status , output : List [str ]):
733
- output .append (f " Pods:" )
736
+ output .append (" Pods:" )
734
737
rows : List [Union [str , Tuple [str , str , str , str ]]] = [
735
738
("Pod Name" , "Host" , "Phase" , "Uptime" )
736
739
]
@@ -844,7 +847,7 @@ def _print_flink_status_from_job_manager(
844
847
# So that paasta status -v and kubectl get pods show the same consistent result.
845
848
if verbose and len (status ["pod_status" ]) > 0 :
846
849
append_pod_status (status ["pod_status" ], output )
847
- output .append (f " No other information available in non-running state" )
850
+ output .append (" No other information available in non-running state" )
848
851
return 0
849
852
850
853
if status ["state" ] == "running" :
@@ -854,7 +857,7 @@ def _print_flink_status_from_job_manager(
854
857
service = service , instance = instance , client = client
855
858
)
856
859
except Exception as e :
857
- output .append (PaastaColors .red (f "Exception when talking to the API:" ))
860
+ output .append (PaastaColors .red ("Exception when talking to the API:" ))
858
861
output .append (str (e ))
859
862
return 1
860
863
@@ -879,7 +882,7 @@ def _print_flink_status_from_job_manager(
879
882
service = service , instance = instance , client = client
880
883
)
881
884
except Exception as e :
882
- output .append (PaastaColors .red (f "Exception when talking to the API:" ))
885
+ output .append (PaastaColors .red ("Exception when talking to the API:" ))
883
886
output .append (str (e ))
884
887
return 1
885
888
@@ -890,7 +893,7 @@ def _print_flink_status_from_job_manager(
890
893
try :
891
894
jobs = a_sync .block (get_flink_job_details , service , instance , job_ids , client )
892
895
except Exception as e :
893
- output .append (PaastaColors .red (f "Exception when talking to the API:" ))
896
+ output .append (PaastaColors .red ("Exception when talking to the API:" ))
894
897
output .append (str (e ))
895
898
return 1
896
899
@@ -906,7 +909,7 @@ def _print_flink_status_from_job_manager(
906
909
max (10 , shutil .get_terminal_size ().columns - 52 ), max_job_name_length
907
910
)
908
911
909
- output .append (f " Jobs:" )
912
+ output .append (" Jobs:" )
910
913
if verbose > 1 :
911
914
output .append (
912
915
f' { "Job Name" : <{allowed_max_job_name_length }} State Job ID Started'
@@ -1313,10 +1316,10 @@ def get_replica_state(pod: KubernetesPodV2) -> ReplicaState:
1313
1316
# This logic likely needs refining
1314
1317
main_container = get_main_container (pod )
1315
1318
if main_container :
1316
- # K8s API is returning timestamps in YST , so we use now() instead of utcnow()
1319
+ # NOTE: the k8s API returns timestamps in UTC , so we make sure to always work in UTC
1317
1320
warming_up = (
1318
1321
pod .create_timestamp + main_container .healthcheck_grace_period
1319
- > datetime .now ().timestamp ()
1322
+ > datetime .now (timezone . utc ).timestamp ()
1320
1323
)
1321
1324
if pod .mesh_ready is False :
1322
1325
if main_container .state != "running" :
@@ -1418,14 +1421,17 @@ def create_replica_table(
1418
1421
)
1419
1422
if state == ReplicaState .WARMING_UP :
1420
1423
if verbose > 0 :
1421
- warmup_duration = datetime .now ().timestamp () - pod .create_timestamp
1424
+ # NOTE: the k8s API returns timestamps in UTC, so we make sure to always work in UTC
1425
+ warmup_duration = (
1426
+ datetime .now (timezone .utc ).timestamp () - pod .create_timestamp
1427
+ )
1422
1428
humanized_duration = humanize .naturaldelta (
1423
1429
timedelta (seconds = warmup_duration )
1424
1430
)
1425
1431
grace_period_remaining = (
1426
1432
pod .create_timestamp
1427
1433
+ main_container .healthcheck_grace_period
1428
- - datetime .now ().timestamp ()
1434
+ - datetime .now (timezone . utc ).timestamp ()
1429
1435
)
1430
1436
humanized_remaining = humanize .naturaldelta (
1431
1437
timedelta (seconds = grace_period_remaining )
@@ -1790,6 +1796,7 @@ def node_property_to_str(prop: Dict[str, Any], verbose: int) -> str:
1790
1796
parsed_time = datetime .strptime (value , "%Y-%m-%dT%H:%M:%SZ" ).replace (
1791
1797
tzinfo = timezone .utc
1792
1798
)
1799
+ # NOTE: the k8s API returns timestamps in UTC, so we make sure to always work in UTC
1793
1800
now = datetime .now (timezone .utc )
1794
1801
return (
1795
1802
humanize .naturaldelta (
@@ -1825,7 +1832,7 @@ def print_kafka_status(
1825
1832
desired_state = annotations .get (paasta_prefixed ("desired_state" ))
1826
1833
if desired_state is None :
1827
1834
raise ValueError (
1828
- f "expected desired state in kafka annotation, but received none"
1835
+ "expected desired state in kafka annotation, but received none"
1829
1836
)
1830
1837
output .append (f" State: { desired_state } " )
1831
1838
@@ -1851,7 +1858,7 @@ def print_kafka_status(
1851
1858
)
1852
1859
1853
1860
brokers = status ["brokers" ]
1854
- output .append (f " Brokers:" )
1861
+ output .append (" Brokers:" )
1855
1862
1856
1863
if verbose :
1857
1864
headers = ["Id" , "Phase" , "IP" , "Pod Name" , "Started" ]
@@ -1864,10 +1871,11 @@ def print_kafka_status(
1864
1871
PaastaColors .green if broker ["phase" ] == "Running" else PaastaColors .red
1865
1872
)
1866
1873
1874
+ # NOTE: the k8s API returns timestamps in UTC, so we make sure to always work in UTC
1867
1875
start_time = datetime .strptime (
1868
1876
broker ["deployed_timestamp" ], "%Y-%m-%dT%H:%M:%SZ"
1869
- )
1870
- delta = datetime .utcnow ( ) - start_time
1877
+ ). replace ( tzinfo = timezone . utc )
1878
+ delta = datetime .now ( timezone . utc ) - start_time
1871
1879
formatted_start_time = f"{ str (start_time )} ({ humanize .naturaltime (delta )} )"
1872
1880
1873
1881
if verbose :
0 commit comments