|
32 | 32 | from .config_exception import ConfigException
|
33 | 33 | from .dateutil import UTC, format_rfc3339, parse_rfc3339
|
34 | 34 |
|
35 |
| -EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5) |
| 35 | +EXPIRY_TIME_SKEW = datetime.timedelta(minutes=5) |
| 36 | +MINIMUM_GCP_TOKEN_TIME_REMAINING = datetime.timedelta(minutes=55) |
36 | 37 | KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')
|
37 | 38 | _temp_files = {}
|
38 | 39 |
|
@@ -62,8 +63,14 @@ def _create_temp_file_with_content(content):
|
62 | 63 | return name
|
63 | 64 |
|
64 | 65 |
|
| 66 | +def _is_stale(expiry): |
| 67 | + return _has_min_lifespan(expiry, MINIMUM_GCP_TOKEN_TIME_REMAINING) |
| 68 | + |
65 | 69 | def _is_expired(expiry):
|
66 |
| - return ((parse_rfc3339(expiry) - EXPIRY_SKEW_PREVENTION_DELAY) <= |
| 70 | + return _has_min_lifespan(expiry, EXPIRY_TIME_SKEW) |
| 71 | + |
| 72 | +def _has_min_lifespan(expiry, min_lifespan): |
| 73 | + return ((parse_rfc3339(expiry) - min_lifespan) <= |
67 | 74 | datetime.datetime.utcnow().replace(tzinfo=UTC))
|
68 | 75 |
|
69 | 76 |
|
@@ -198,7 +205,7 @@ def _load_gcp_token(self):
|
198 | 205 | if (('config' not in provider) or
|
199 | 206 | ('access-token' not in provider['config']) or
|
200 | 207 | ('expiry' in provider['config'] and
|
201 |
| - _is_expired(provider['config']['expiry']))): |
| 208 | + _is_stale(provider['config']['expiry']))): |
202 | 209 | # token is not available or expired, refresh it
|
203 | 210 | self._refresh_gcp_token()
|
204 | 211 |
|
|
0 commit comments