Versioned kyverno models for cloudcoil.
Warning
This repository is auto-generated from the cloudcoil repository. Please do not submit pull requests here. Instead, submit them to the main repository at https://github.com/cloudcoil/cloudcoil.
Note
For versioning information and compatibility, see the Versioning Guide.
Using uv (recommended):
# Install with Kyverno support
uv add cloudcoil.models.kyverno
Using pip:
pip install cloudcoil.models.kyverno
from cloudcoil import apimachinery
import cloudcoil.models.kyverno.v1 as kyverno
# Create a ClusterPolicy
policy = kyverno.ClusterPolicy(
metadata=apimachinery.ObjectMeta(name="require-labels"),
spec=kyverno.ClusterPolicySpec(
rules=[
kyverno.Rule(
name="require-team-label",
match=kyverno.Match(
resources=kyverno.Resources(
kinds=["Deployment", "StatefulSet"]
)
),
validate=kyverno.Validate(
message="The label 'team' is required",
pattern={
"metadata": {
"labels": {
"team": "*"
}
}
}
)
)
]
)
).create()
# List Policies
for pol in kyverno.ClusterPolicy.list():
print(f"Found policy: {pol.metadata.name}")
# Update a Policy
policy.spec.rules[0].validate.message = "The 'team' label is mandatory"
policy.save()
# Delete a Policy
kyverno.ClusterPolicy.delete("require-labels")
Cloudcoil provides a powerful fluent builder API for Kyverno resources with full IDE support and rich autocomplete capabilities:
from cloudcoil.models.kyverno.v1 import ClusterPolicy
# Create a ClusterPolicy using the builder
policy = (
ClusterPolicy.builder()
.metadata(lambda m: m
.name("require-labels")
)
.spec(lambda s: s
.rules([
lambda r: r
.name("require-team-label")
.match(lambda m: m
.resources(lambda res: res
.kinds(["Deployment", "StatefulSet"])
)
)
.validate(lambda v: v
.message("The label 'team' is required")
.pattern({
"metadata": {
"labels": {
"team": "*"
}
}
})
)
])
)
.build()
)
The fluent builder provides:
- β¨ Full IDE support with detailed type information
- π Rich autocomplete for all fields and nested objects
- β‘ Compile-time validation of your configuration
- π― Clear and chainable API that guides you through resource creation
For complex nested resources, Cloudcoil also provides a context manager-based builder pattern that can make the structure more clear:
from cloudcoil.models.kyverno.v1 import ClusterPolicy
# Create a policy using context managers
with ClusterPolicy.new() as policy:
with policy.metadata() as metadata:
metadata.name("require-labels")
metadata.labels({"app": "kyverno"})
with policy.spec() as spec:
with spec.rules() as rules:
with rules.add() as rule:
rule.name("require-team-label")
with rule.match() as match:
with match.resources() as resources:
resources.kinds(["Deployment", "StatefulSet"])
with rule.validate() as validate:
validate.message("The label 'team' is required")
validate.pattern({
"metadata": {
"labels": {
"team": "*"
}
}
})
final_policy = policy.build()
The context manager builder provides:
- π Clear visual nesting of resource structure
- π Automatic resource cleanup
- π― Familiar Python context manager pattern
- β¨ Same great IDE support as the fluent builder
CloudCoil's intelligent builder system automatically detects which style you're using and provides appropriate IDE support:
from cloudcoil.models.kyverno.v1 import ClusterPolicy
from cloudcoil import apimachinery
# Mixing styles lets you choose the best approach for each part
with ClusterPolicy.new() as policy:
# Direct object initialization with full type checking
policy.metadata(apimachinery.ObjectMeta(
name="require-labels",
labels={"app": "kyverno"}
))
with policy.spec() as spec:
# Fluent style for rules
spec.rules([
lambda r: r
.name("require-team-label")
.match(lambda m: m
.resources(lambda res: res
.kinds(["Deployment", "StatefulSet"])
)
)
# Context manager style for validate
.validate(lambda v: v
.message("The label 'team' is required")
.pattern({
"metadata": {
"labels": {
"team": "*"
}
}
})
)
])
final_policy = policy.build()
This flexibility allows you to:
- π Choose the most appropriate style for each part of your configuration
- π Maximize readability for both simple and complex structures
- π¨ Format your code according to your team's preferences
- π§ Get full IDE support with automatic style detection
- β¨ Enjoy rich autocomplete in all styles
- β‘ Benefit from type checking across mixed styles
- π― Receive immediate feedback on type errors
- π See documentation for all fields regardless of style
For complete documentation, visit cloudcoil.github.io/cloudcoil
Apache License, Version 2.0 - see LICENSE