Skip to content

Commit

Permalink
Merge pull request #2215 from showjason/replace-utcnow-with-now
Browse files Browse the repository at this point in the history
replace utcnow with now, due to utcnow will be deprecated
  • Loading branch information
k8s-ci-robot committed Apr 2, 2024
2 parents 851dc2a + 07c94fb commit e0234d3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions examples/deployment_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def restart_deployment(api, deployment):
# update `spec.template.metadata` section
# to add `kubectl.kubernetes.io/restartedAt` annotation
deployment.spec.template.metadata.annotations = {
"kubectl.kubernetes.io/restartedAt": datetime.datetime.utcnow()
.replace(tzinfo=pytz.UTC)
"kubectl.kubernetes.io/restartedAt": datetime.datetime.now(tz=pytz.UTC)
.isoformat()
}

Expand Down
3 changes: 1 addition & 2 deletions examples/dynamic-client/deployment_rolling_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def main():

deployment_manifest["spec"]["template"]["metadata"] = {
"annotations": {
"kubectl.kubernetes.io/restartedAt": datetime.datetime.utcnow()
.replace(tzinfo=pytz.UTC)
"kubectl.kubernetes.io/restartedAt": datetime.datetime.now(tz=pytz.UTC)
.isoformat()
}
}
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/base/config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _create_temp_file_with_content(content, temp_file_path=None):

def _is_expired(expiry):
return ((parse_rfc3339(expiry) - EXPIRY_SKEW_PREVENTION_DELAY) <=
datetime.datetime.utcnow().replace(tzinfo=UTC))
datetime.datetime.now(tz=UTC))


class FileOrData(object):
Expand Down
14 changes: 7 additions & 7 deletions kubernetes/base/config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from kubernetes.client import Configuration

from .config_exception import ConfigException
from .dateutil import format_rfc3339, parse_rfc3339
from .dateutil import UTC, format_rfc3339, parse_rfc3339
from .kube_config import (ENV_KUBECONFIG_PATH_SEPARATOR, CommandTokenSource,
ConfigNode, FileOrData, KubeConfigLoader,
KubeConfigMerger, _cleanup_temp_files,
Expand Down Expand Up @@ -89,10 +89,10 @@ def _raise_exception(st):
TEST_PASSWORD = "pass"
# token for me:pass
TEST_BASIC_TOKEN = "Basic bWU6cGFzcw=="
DATETIME_EXPIRY_PAST = datetime.datetime.utcnow(
) - datetime.timedelta(minutes=PAST_EXPIRY_TIMEDELTA)
DATETIME_EXPIRY_FUTURE = datetime.datetime.utcnow(
) + datetime.timedelta(minutes=FUTURE_EXPIRY_TIMEDELTA)
DATETIME_EXPIRY_PAST = datetime.datetime.now(tz=UTC
).replace(tzinfo=None) - datetime.timedelta(minutes=PAST_EXPIRY_TIMEDELTA)
DATETIME_EXPIRY_FUTURE = datetime.datetime.now(tz=UTC
).replace(tzinfo=None) + datetime.timedelta(minutes=FUTURE_EXPIRY_TIMEDELTA)
TEST_TOKEN_EXPIRY_PAST = _format_expiry_datetime(DATETIME_EXPIRY_PAST)

TEST_SSL_HOST = "https://test-host"
Expand Down Expand Up @@ -1028,7 +1028,7 @@ def test_load_gcp_token_no_refresh(self):
def test_load_gcp_token_with_refresh(self):
def cred(): return None
cred.token = TEST_ANOTHER_DATA_BASE64
cred.expiry = datetime.datetime.utcnow()
cred.expiry = datetime.datetime.now(tz=UTC).replace(tzinfo=None)

loader = KubeConfigLoader(
config_dict=self.TEST_KUBE_CONFIG,
Expand Down Expand Up @@ -1124,7 +1124,6 @@ def test_oidc_with_idp_ca_file_refresh(self, mock_ApiClient, mock_OAuth2Session)
active_context="expired_oidc_with_idp_ca_file",
)


self.assertTrue(loader._load_auth_provider_token())
self.assertEqual("Bearer abc123", loader.token)

Expand Down Expand Up @@ -1529,6 +1528,7 @@ def test_user_exec_auth_certificates(self, mock):
@mock.patch('kubernetes.config.kube_config.ExecProvider.run', autospec=True)
def test_user_exec_cwd(self, mock):
capture = {}

def capture_cwd(exec_provider):
capture['cwd'] = exec_provider.cwd
mock.side_effect = capture_cwd
Expand Down

0 comments on commit e0234d3

Please sign in to comment.