Skip to content

Commit 638abe2

Browse files
authored
Merge branch 'kubernetes-client:master' into master
2 parents 6b85a93 + c9db1a3 commit 638abe2

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

.readthedocs.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Read the Docs configuration file for Sphinx projects
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version and other tools you might need
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.12"
12+
# You can also specify other tool versions:
13+
# nodejs: "20"
14+
# rust: "1.70"
15+
# golang: "1.20"
16+
17+
# Build documentation in the "docs/" directory with Sphinx
18+
sphinx:
19+
configuration: doc/source/conf.py
20+
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
21+
# builder: "dirhtml"
22+
# Fail on all warnings to avoid broken references
23+
# fail_on_warning: true
24+
25+
# Optionally build your docs in additional formats such as PDF and ePub
26+
# formats:
27+
# - pdf
28+
# - epub
29+
30+
# Optional but recommended, declare the Python requirements required
31+
# to build your documentation
32+
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33+
python:
34+
install:
35+
- requirements: doc/requirements-docs.txt
36+
- requirements: test-requirements.txt
37+
38+
39+
# git clone --depth 1 https://github.com/kubernetes-client/python .
40+
# git fetch origin --force --prune --prune-tags --depth 50 refs/heads/master:refs/remotes/origin/master
41+
# git checkout --force origin/master
42+
# git clean -d -f -f
43+
# python3.7 -mvirtualenv $READTHEDOCS_VIRTUALENV_PATH
44+
# python -m pip install --upgrade --no-cache-dir pip setuptools
45+
# python -m pip install --upgrade --no-cache-dir pillow mock==1.0.1 alabaster>=0.7,<0.8,!=0.7.5 commonmark==0.9.1 recommonmark==0.5.0 sphinx<2 sphinx-rtd-theme<0.5 readthedocs-sphinx-ext<2.3 jinja2<3.1.0
46+
47+
# cat doc/source/conf.py
48+
# python -m sphinx -T -E -b html -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/html
49+
# python -m sphinx -T -E -b readthedocssinglehtmllocalmedia -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/htmlzip
50+
# python -m sphinx -T -E -b latex -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/pdf
51+
# cat latexmkrc
52+
# latexmk -r latexmkrc -pdf -f -dvi- -ps- -jobname=kubernetes -interaction=nonstopmode
53+
# python -m sphinx -T -E -b epub -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/epub

devel/debug_logging.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Enabling Debug Logging in Kubernetes Python Client
2+
3+
This document describes how to enable debug logging, view logged information, and provides examples for creating, patching, and deleting Kubernetes resources.
4+
5+
## 1. Why Enable Debug Logging?
6+
7+
Debug logging is useful for troubleshooting as it shows details like HTTP request and response headers and bodies. These details can help identify issues during interactions with the Kubernetes API server.
8+
9+
---
10+
11+
## 2. Enabling Debug Logging
12+
13+
To enable debug logging in the Kubernetes Python client, follow these steps:
14+
15+
1. **Modify the Configuration Object:**
16+
Enable debug mode by setting the `debug` attribute of the `client.Configuration` object to `True`.
17+
18+
2. **Example Code to Enable Debug Logging:**
19+
Below is an example showing how to enable debug logging:
20+
```python
21+
from kubernetes import client, config
22+
23+
# Load kube config
24+
config.load_kube_config()
25+
26+
# Enable debug logging
27+
c = client.Configuration()
28+
c.debug = True
29+
30+
# Pass the updated configuration to the API client
31+
api_client = client.ApiClient(configuration=c)
32+
33+
# Use the API client with debug logging enabled
34+
apps_v1 = client.AppsV1Api(api_client=api_client)

examples/enable_debug_logging.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2025 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+
# This example demonstrates how to enable debug logging in the Kubernetes
10+
# Python client and how it can be used for troubleshooting requests/responses.
11+
12+
from kubernetes import client, config
13+
14+
15+
def main():
16+
# Load kubeconfig from default location
17+
config.load_kube_config()
18+
19+
# Enable debug logging
20+
configuration = client.Configuration()
21+
configuration.debug = True
22+
api_client = client.ApiClient(configuration=configuration)
23+
24+
# Use AppsV1Api with debug logging enabled
25+
apps_v1 = client.AppsV1Api(api_client=api_client)
26+
27+
# Example: Create a dummy deployment (adjust namespace as needed)
28+
deployment = client.V1Deployment(
29+
api_version="apps/v1",
30+
kind="Deployment",
31+
metadata=client.V1ObjectMeta(name="debug-example"),
32+
spec=client.V1DeploymentSpec(
33+
replicas=1,
34+
selector={"matchLabels": {"app": "debug"}},
35+
template=client.V1PodTemplateSpec(
36+
metadata=client.V1ObjectMeta(labels={"app": "debug"}),
37+
spec=client.V1PodSpec(
38+
containers=[
39+
client.V1Container(
40+
name="busybox",
41+
image="busybox",
42+
command=["sh", "-c", "echo Hello, Kubernetes! && sleep 3600"]
43+
)
44+
]
45+
),
46+
),
47+
),
48+
)
49+
50+
# Create the deployment
51+
try:
52+
print("[INFO] Creating deployment...")
53+
apps_v1.create_namespaced_deployment(
54+
namespace="default", body=deployment
55+
)
56+
except client.exceptions.ApiException as e:
57+
print("[ERROR] Exception occurred:", e)
58+
59+
60+
if __name__ == "__main__":
61+
main()

0 commit comments

Comments
 (0)