Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 057715a

Browse files
author
Jake Sanders
committed
refresh GCP tokens if <55 mins of life left
Signed-off-by: Jake Sanders <[email protected]>
1 parent 78472de commit 057715a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

config/kube_config.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .config_exception import ConfigException
3333
from .dateutil import UTC, format_rfc3339, parse_rfc3339
3434

35-
EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5)
35+
MINIMUM_TOKEN_TIME_REMAINING = datetime.timedelta(minutes=55)
3636
KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')
3737
_temp_files = {}
3838

@@ -62,8 +62,8 @@ def _create_temp_file_with_content(content):
6262
return name
6363

6464

65-
def _is_expired(expiry):
66-
return ((parse_rfc3339(expiry) - EXPIRY_SKEW_PREVENTION_DELAY) <=
65+
def _is_stale(expiry):
66+
return ((parse_rfc3339(expiry) - MINIMUM_TOKEN_TIME_REMAINING) <=
6767
datetime.datetime.utcnow().replace(tzinfo=UTC))
6868

6969

@@ -198,7 +198,7 @@ def _load_gcp_token(self):
198198
if (('config' not in provider) or
199199
('access-token' not in provider['config']) or
200200
('expiry' in provider['config'] and
201-
_is_expired(provider['config']['expiry']))):
201+
_is_stale(provider['config']['expiry']))):
202202
# token is not available or expired, refresh it
203203
self._refresh_gcp_token()
204204

@@ -243,7 +243,7 @@ def _load_oid_token(self):
243243
expire = jwt_attributes.get('exp')
244244

245245
if ((expire is not None) and
246-
(_is_expired(datetime.datetime.fromtimestamp(expire,
246+
(_is_stale(datetime.datetime.fromtimestamp(expire,
247247
tz=UTC)))):
248248
self._refresh_oidc(provider)
249249

0 commit comments

Comments
 (0)