Skip to content

Add examples for kubesdk usage#16

Draft
VNadygin wants to merge 23 commits intopuzl-cloud:mainfrom
VNadygin:examples/quickstart
Draft

Add examples for kubesdk usage#16
VNadygin wants to merge 23 commits intopuzl-cloud:mainfrom
VNadygin:examples/quickstart

Conversation

@VNadygin
Copy link

@VNadygin VNadygin commented Dec 4, 2025

Summary

Comprehensive examples demonstrating kubesdk features:

# Example Description
01 quickstart.py Basic CRUD operations with ConfigMaps
02 authentication.py Login patterns: default, specific context, custom path
03 request_config.py Timeouts, retries, and logging configuration
04 deployments.py Deployment management: create, scale, rolling updates
05 watching.py Real-time resource streaming with watch
06 patching.py Strategic merge patch, JSON patch, selective field updates
07 multi_cluster.py Working with multiple clusters via server= parameter
08 error_handling.py Typed exceptions, return_api_exceptions pattern
09 batch_operations.py Parallel operations with asyncio.gather
10 custom_resources.py CRD example with CloudNativePG Cluster

Also includes:

  • examples/README.md with key patterns and usage guide
  • Migration guide for v0.1.0 compatibility

Test plan

  • All 10 examples tested against minikube cluster
  • Verified resources are created/updated/deleted in Kubernetes
  • Verified compatibility with upcoming v0.1.0 (PR v0.1.0 #18)

Demonstrates:
- Creating, reading, updating, and deleting ConfigMaps
- Listing resources with filtering
- Using create_or_update_k8s_resource for upsert operations
- Proper async/await patterns with kubesdk
@VNadygin VNadygin force-pushed the examples/quickstart branch from b9fca21 to 325fc86 Compare December 5, 2025 12:53
@VNadygin VNadygin changed the title Add quickstart example demonstrating basic CRUD operations Add examples for kubesdk usage Dec 5, 2025
Documents required changes to examples when upgrading to kubesdk v0.1.0:
- path_picker module removed, exports moved to root
- new replace_() function for deep nested updates
- updated import patterns for consistency
@nik-paushkin nik-paushkin marked this pull request as draft December 10, 2025 15:05
@nik-paushkin nik-paushkin self-requested a review December 10, 2025 15:05
- add proper return type hints to all functions
- remove unnecessary namespace fetch in authentication example (login checks API access)
- remove unused imports: NotFoundError, DeleteOptions
- add 03_request_config.py: timeouts, retries, logging configuration
- rename 03_deployments.py -> 04_deployments.py
- rename 04_watching.py -> 05_watching.py

New order:
  01_quickstart - CRUD basics
  02_authentication - login patterns
  03_request_config - client configuration
  04_deployments - complex resources + patching
  05_watching - event streaming
Covers:
- strategic merge patch with built_from_latest
- selective field updates with path picker
- nested field updates
- full replacement (PUT) with force=True
- JSON patch with conflict guards
- conflict handling with retry pattern
import asyncio
import os

from kubesdk.login import login, KubeConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from kubesdk import login, KubeConfig, ServerInfo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nik-paushkin Updated, as well as in other example

Covers:
- connecting to clusters via kubeconfig contexts
- server= parameter for targeting specific clusters
- parallel queries across clusters
Shows: typed exceptions, return_api_exceptions, Status object parsing,
batch error aggregation, and login error handling
Demonstrates asyncio.gather for parallel operations and label selectors
for batch queries
Shows how to define K8sResource class for CRDs and perform CRUD operations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is basic Python, isn't needed here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is basic Python, isn't needed as a separate example

patch_strategies_: ClassVar[set] = {PatchRequestType.merge}

metadata: ObjectMeta = field(default_factory=ObjectMeta)
spec: dict | None = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a valid spec, but I'm gonna write a separate md file on extending kubesdk with CRDs anyway

await default_login()

# Check connection details
await check_connection_info()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it and why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nik-paushkin Removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be merged into auth example

# Check connection details
await check_connection_info()

# Uncomment to test other patterns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be no "uncomment something" sections in examples

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nik-paushkin Removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments