Dictionary representations of k8s resource model objects are not valid k8s resource manifest representations
See original GitHub issueMy use case is that I’d like to build up a representation of various Kubernetes resources via the classes in kubernetes.client.models
and then generate the manifest yaml files for these resources via printing to YAML files the to_dict
representations of these resource objects. However, because all the attributes are snake cased, the end YAML also has snake cased keys (which are not valid k8s manifest keys and fail validation).
Example:
with open('deployment.yaml, 'w') as outfile:
yaml.dump(deploymemnt_resource.to_dict(), outfile, default_flow_style=False)
Resulting deployment.yaml
file:
api_version: extensions/v1beta1
kind: Deployment
metadata:
name: testing
spec:
progress_deadline_seconds: 300
replicas: 1
template:
metadata:
labels:
app: testing
spec:
containers:
- name: testing
readiness_probe:
http_get:
path: /_meta/0/info
port: http
The progress_deadline_seconds
, readiness_probe
, and http_get
keys are all invalid.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Understanding Kubernetes Objects
This page explains how Kubernetes objects are represented in the Kubernetes API, and how you can express them in .yaml format.
Read more >Kubernetes API Basics - Resources, Kinds, and Objects - iximiuz
Resource types are organized into API groups, and API groups are versioned. Every resource representation follows a certain schema defined by ...
Read more >Working With Kubernetes Objects | Cheat Sheet & Tutorial
In Kubernetes, object representation is stored in a manifest, as discussed above. Each kind of object has two specific properties:.
Read more >kubernetes.core.k8s module - Ansible Documentation
Only implemented for Pod resources. If not specified, the default grace period for the object type will be used. preconditions. dictionary.
Read more >The Chart Template Developer's Guide - Helm V2
Templates generate manifest files, which are YAML-formatted resource descriptions that Kubernetes can understand. We'll look at how templates are structured ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not sure if this is canonical, but this is my approach to a similar situation.
This will create a dict.
This is a fantastic workaround, but it feels very odd that the python API for objects doesn’t know how to output itself as valid kubernetes yaml