8000 Merge pull request #1459 from Yashks1994/header-patch1 · palnabarun/python@46f00ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 46f00ef

Browse files
authored
Merge pull request kubernetes-client#1459 from Yashks1994/header-patch1
add examples to demonstrate the usage of dynamic client by passing custom "Accept" header
2 parents 04e62c6 + 68aba47 commit 46f00ef

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2021 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
This example demonstrates how to pass the custom header in the cluster.
17+
18+
"""
19+
20+
from kubernetes import config, dynamic
21+
from kubernetes.client import api_client
22+
23+
def main():
24+
# Creating a dynamic client
25+
client = dynamic.DynamicClient(
26+
api_client.ApiClient(configuration=config.load_kube_config())
27+
)
28+
29+
# fetching the node api
30+
api = client.resources.get(api_version="v1", kind="Node")
31+
32+
# Creating a custom header
33+
params = {'header_params': {'Accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}}
34+
35+
resp = api.get(**params)
36+
37+
# Printing the kind and apiVersion after passing new header params.
38+
print("%s\t\t\t%s" %("VERSION", "KIND"))
39+
print("%s\t\t%s" %(resp.apiVersion, resp.kind))
40+
41+
42+
if __name__ == "__main__":
43+
main()

0 commit comments

Comments
 (0)
0