Skip to content

Commit 6850340

Browse files
authored
Merge pull request #1519 from roycaihw/release18
Pull master into release-18.0
2 parents 0b146c3 + 8bd7651 commit 6850340

13 files changed

+156
-14
lines changed

.github/workflows/e2e-master.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
submodules: true
2121
- name: Create Kind Cluster
22-
uses: helm/kind-action@v1.1.0
22+
uses: helm/kind-action@v1.2.0
2323
with:
2424
cluster_name: kubernetes-python-e2e-master-${{ matrix.python-version }}
2525
# The kind version to be used to spin the cluster up

.github/workflows/e2e-release-11.0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
submodules: true
2121
- name: Create Kind Cluster
22-
uses: helm/kind-action@v1.1.0
22+
uses: helm/kind-action@v1.2.0
2323
with:
2424
cluster_name: kubernetes-python-e2e-release-11.0-${{ matrix.python-version }}
2525
# The kind version to be used to spin the cluster up

.github/workflows/e2e-release-12.0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
submodules: true
2121
- name: Create Kind Cluster
22-
uses: helm/kind-action@v1.1.0
22+
uses: helm/kind-action@v1.2.0
2323
with:
2424
cluster_name: kubernetes-python-e2e-release-12.0-${{ matrix.python-version }}
2525
# The kind version to be used to spin the cluster up

.github/workflows/e2e-release-17.0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
submodules: true
2121
- name: Create Kind Cluster
22-
uses: helm/kind-action@v1.1.0
22+
uses: helm/kind-action@v1.2.0
2323
with:
2424
cluster_name: kubernetes-python-e2e-release-17.0-${{ matrix.python-version }}
2525
# The kind version to be used to spin the cluster up

.github/workflows/e2e-release-18.0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
submodules: true
2121
- name: Create Kind Cluster
22-
uses: helm/kind-action@v1.1.0
22+
uses: helm/kind-action@v1.2.0
2323
with:
2424
cluster_name: kubernetes-python-e2e-release-18.0-${{ matrix.python-version }}
2525
# The kind version to be used to spin the cluster up

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# v18.0.0-snapshot
2+
3+
Kubernetes API Version: To Be Updated
4+
5+
### Feature
6+
- Support for the dryRun parameter has been added to the dynamic client. ([kubernetes-client/python-base#247](https://github.com/kubernetes-client/python-base/pull/247), [@gravesm](https://github.com/gravesm))
7+
- The `python2` support will be removed in 18.0.0 beta release. All the tests will use `python3` versions. ([kubernetes-client/python-base#238](https://github.com/kubernetes-client/python-base/pull/238), [@Priyankasaggu11929](https://github.com/Priyankasaggu11929))
8+
- The dynamic client now supports customizing http "Accept" header through the `header_params` parameter, which can be used to customizing API server response, e.g. retrieving object metadata only. ([kubernetes-client/python-base#236](https://github.com/kubernetes-client/python-base/pull/236), [@Yashks1994](https://github.com/Yashks1994))
9+
- Allow optional list of YAML objects as param to `create_from_yaml` util [kubernetes-client/python#1403](https://github.com/kubernetes-client/python/pull/1403)
10+
11+
**Bug Fix:**
12+
- Fix empty yaml document in `create_from_yaml` [kubernetes-client/python#1506](https://github.com/kubernetes-client/python/pull/1506)
13+
114
# v18.20.0b1
215

316
Kubernetes API Version: 1.18.20

examples/pod_namespace_watch.py renamed to examples/watch/pod_namespace_watch.py

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
The script will wait for 10 events related to namespaces to occur within
1818
the `timeout_seconds` threshold and then move on to wait for another 10 events
1919
related to pods to occur within the `timeout_seconds` threshold.
20+
21+
22+
Refer to the document below to understand the server-side & client-side
23+
timeout settings for the watch request handler: ~
24+
25+
https://github.com/github.com/kubernetes-client/python/blob/master/examples/watch/timeout-settings.md
2026
"""
2127

2228
from kubernetes import client, config, watch

examples/watch/timeout-settings.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
**This documentation briefly provides information about the `server side` & `client side` connection timeout settings, in the watch request handler.**
3+
4+
---
5+
6+
There are two inputs available in the client, that could be used to set connection timeouts:
7+
8+
- `timeout_seconds`
9+
- `_request_timeout`
10+
11+
---
12+
13+
#### Sever-side timeout (`kwargs['timeout_seconds'] = n`)
14+
15+
- The value of the argument `timeout_seconds`, **n**, (which is time duration in seconds) is consumed at the server side. It is included in the request URL to the server.
16+
17+
*For eg.* ~ `https://localhost:6443/api/v1/namespaces/default/pods?labelSelector=app%3Ddemo&timeoutSeconds=100&watch=True`
18+
19+
- In case, if the `timeout_seconds` value is set, the value `n` would determine the server-side connection timeout duration.
20+
21+
*For eg.* ~ if `kwargs['timeout_seconds'] = 3600`, then the server-side connection timeout will be equal to 1 hour.
22+
23+
This timeout duration is determined by the expression ~ `timeout = time.Duration(3600) * time.seconds`, *i.e.* `timeout = 1 hour`
24+
25+
***Refer:***
26+
- *[https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L254](https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L254)*
27+
28+
- In case, if the `timeout_seconds` value is not set, then the connection timeout will be a randomized value (in seconds) between `minRequestTimeout` and 2*`minRequestTimeout`, to spread out the load.
29+
30+
It is determined using the expression ~ `timeout = time.Duration(float64(minRequestTimeout) * (rand.Float64() + 1.0))`
31+
32+
Where `minRequestTimeout` indicates the minimum number of seconds a handler must keep a request open before timing it out.
33+
34+
The default value of `minRequestTimeout` is 1800 seconds.
35+
36+
***Refer:***
37+
- *[https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L257](https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L257)*
38+
- *[https://github.com/kubernetes/kubernetes/blob/release-1.20/staging/src/k8s.io/apiserver/pkg/server/config.go#L320](https://github.com/kubernetes/kubernetes/blob/release-1.20/staging/src/k8s.io/apiserver/pkg/server/config.go#L320)*
39+
40+
- In case of a network outage, the server side timeout value will have no effect & the client will hang indefinitely without raising any exception. Note, that this is the case provided when there is no other client-side timeout (i.e., `_request_timeout`) value specified.
41+
42+
(*See the section below for information on `client side timeout`*)
43+
44+
- It is recommended to set this timeout value to a higher number such as 3600 seconds (1 hour).
45+
46+
---
47+
48+
#### Client-side timeout (`kwargs['_request_timeout'] = n`)
49+
50+
- The value of the argument `_request_timeout`, **n** (which is time duration in seconds) is set to the socket used for the connection.
51+
52+
- In case, if the `_request_timeout` value is set, this argument can accept 2 types of input values ~
53+
- float,
54+
- a tuple (with a length of 2)
55+
56+
***Refer***
57+
- *[https://github.com/kubernetes-client/python/blob/v17.17.0/kubernetes/client/api_client.py#L336-L339](https://github.com/kubernetes-client/python/blob/v17.17.0/kubernetes/client/api_client.py#L336-L339)*
58+
59+
- In case of network outage, leading to dropping all packets with no RST/FIN, the timeout value (in seconds) determined by the `request_timeout` argument, would be the time duration for how long the client will wait before dropping the connection.
60+
61+
- When the timeout happens, an exception will be raised, for eg. ~
62+
63+
`urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='localhost', port=6443): Read timed out.`
64+
65+
- In case, if the `_request_timeout` value is not set, then the default value is **`None`** & socket will have no timeout.
66+
67+
***Refer:***
68+
- *[https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout](https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout)*
69+
70+
- It is recommended to set this timeout value to a lower number (for eg. ~ maybe 60 seconds).
71+

kubernetes/client/models/v1_projected_volume_source.py

-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ def sources(self, sources):
9999
:param sources: The sources of this V1ProjectedVolumeSource. # noqa: E501
100100
:type: list[V1VolumeProjection]
101101
"""
102-
if self.local_vars_configuration.client_side_validation and sources is None: # noqa: E501
103-
raise ValueError("Invalid value for `sources`, must not be `None`") # noqa: E501
104-
105102
self._sources = sources
106103

107104
def to_dict(self):

kubernetes/e2e_test/test_utils.py

+28
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# under the License.
1414

1515
import unittest
16+
from os import path
1617

1718
import yaml
19+
1820
from kubernetes import utils, client
1921
from kubernetes.client.rest import ApiException
2022
from kubernetes.e2e_test import base
@@ -37,6 +39,7 @@ def tearDownClass(cls):
3739
k8s_client = client.api_client.ApiClient(configuration=cls.config)
3840
core_v1 = client.CoreV1Api(api_client=k8s_client)
3941
core_v1.delete_namespace(name=cls.test_namespace)
42+
4043
# Tests for creating individual API objects
4144

4245
def test_create_apps_deployment_from_yaml(self):
@@ -59,6 +62,31 @@ def test_create_apps_deployment_from_yaml(self):
5962
except ApiException:
6063
continue
6164

65+
def test_create_apps_deployment_from_yaml_object(self):
66+
"""
67+
Should be able to pass YAM objects directly to helper function.
68+
"""
69+
k8s_client = client.api_client.ApiClient(configuration=self.config)
70+
_path = self.path_prefix + "apps-deployment.yaml"
71+
with open(path.abspath(_path)) as f:
72+
yaml_objects = yaml.safe_load_all(f)
73+
utils.create_from_yaml(
74+
k8s_client,
75+
yaml_objects=yaml_objects,
76+
)
77+
app_api = client.AppsV1Api(k8s_client)
78+
dep = app_api.read_namespaced_deployment(name="nginx-app",
79+
namespace="default")
80+
self.assertIsNotNone(dep)
81+
while True:
82+
try:
83+
app_api.delete_namespaced_deployment(
84+
name="nginx-app", namespace="default",
85+
body={})
86+
break
87+
except ApiException:
88+
continue
89+
6290
def test_create_apps_deployment_from_yaml_obj(self):
6391
k8s_client = client.api_client.ApiClient(configuration=self.config)
6492
with open(self.path_prefix + "apps-deployment.yaml") as f:

kubernetes/utils/create_from_yaml.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
def create_from_yaml(
2828
k8s_client,
29-
yaml_file,
29+
yaml_file=None,
30+
yaml_objects=None,
3031
verbose=False,
3132
namespace="default",
3233
**kwargs):
@@ -36,6 +37,8 @@ def create_from_yaml(
3637
Input:
3738
yaml_file: string. Contains the path to yaml file.
3839
k8s_client: an ApiClient object, initialized with the client args.
40+
yaml_objects: List[dict]. Optional list of YAML objects; used instead
41+
of reading the `yaml_file`. Default is None.
3942
verbose: If True, print confirmation from the create action.
4043
Default is False.
4144
namespace: string. Contains the namespace to create all
@@ -62,12 +65,13 @@ def create_from_yaml(
6265
FailToCreateError which holds list of `client.rest.ApiException`
6366
instances for each object that failed to create.
6467
"""
65-
with open(path.abspath(yaml_file)) as f:
66-
yml_document_all = yaml.safe_load_all(f)
6768

69+
def create_with(objects):
6870
failures = []
6971
k8s_objects = []
70-
for yml_document in yml_document_all:
72+
for yml_document in objects:
73+
if yml_document is None:
74+
continue
7175
try:
7276
created = create_from_dict(k8s_client, yml_document, verbose,
7377
namespace=namespace,
@@ -77,9 +81,19 @@ def create_from_yaml(
7781
failures.extend(failure.api_exceptions)
7882
if failures:
7983
raise FailToCreateError(failures)
80-
8184
return k8s_objects
8285

86+
if yaml_objects:
87+
yml_document_all = yaml_objects
88+
return create_with(yml_document_all)
89+
elif yaml_file:
90+
with open(path.abspath(yaml_file)) as f:
91+
yml_document_all = yaml.safe_load_all(f)
92+
return create_with(yml_document_all)
93+
else:
94+
raise ValueError(
95+
'One of `yaml_file` or `yaml_objects` arguments must be provided')
96+
8397

8498
def create_from_dict(k8s_client, data, verbose=False, namespace='default',
8599
**kwargs):

scripts/apply-hotfixes.sh

+13
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,17 @@ else
7474
exit 1
7575
fi;
7676

77+
# Patching commits for Tolerating Null Sources on Projected Volumes
78+
# TODO: remove this patch when we release v20 clients
79+
# Ref: https://github.com/kubernetes-client/python/pull/1497
80+
git cherry-pick -n f3dbc8cbf1ab2aaf5e3bd8c0f0fc068e67823971
81+
if [ $? -eq 0 ]
82+
then
83+
echo Succesfully patched changes for Tolerating Null Sources on Projected Volumes
84+
else
85+
echo Failed to patch changes for Tolerating Null Sources on Projected Volumes
86+
git restore --staged .
87+
exit 1
88+
fi;
89+
7790
git commit -m "Apply hotfixes"

0 commit comments

Comments
 (0)