Skip to main content

Versioned istio models for cloudcoil

Project description

cloudcoil-models-istio

Versioned istio models for cloudcoil.

🔧 Installation

Using uv (recommended):

# Install with Istio support
uv add cloudcoil.models.istio

Using pip:

pip install cloudcoil.models.istio

💡 Examples

Using Istio Models

from cloudcoil import apimachinery
from cloudcoil.models.istio import networking

# Create a Gateway
gateway = networking.v1.Gateway(
    metadata=apimachinery.ObjectMeta(name="main-gateway"),
    spec=networking.v1.GatewaySpec(
        selector={"istio": "ingressgateway"},
        servers=[networking.v1.Server(
            port=networking.v1.PortModel(
                number=80,
                name="http",
                protocol="HTTP"
            ),
            hosts=["*.example.com"]
        )]
    )
).create()

# Create a VirtualService
virtual_service = networking.v1.VirtualService(
    metadata=apimachinery.ObjectMeta(name="website"),
    spec=networking.v1.VirtualServiceSpec(
        hosts=["website.example.com"],
        gateways=["main-gateway"],
        http=[networking.v1.HttpModel(
            route=[networking.v1.Route(
                destination=networking.v1.Destination(
                    host="website-svc",
                    port=networking.v1.Port(number=8080)
                )
            )]
        )]
    )
).create()

# List Virtual Services
for vs in networking.v1.VirtualService.list():
    print(f"Found VirtualService: {vs.metadata.name}")

Using the Fluent Builder API

from cloudcoil.models.istio import networking

# Create a Gateway using the fluent builder
gateway = (
    networking.v1.Gateway.builder()
    .metadata(lambda metadata: metadata
        .name("main-gateway")
        .namespace("default")
    )
    .spec(lambda gateway_spec: gateway_spec
        .selector({"istio": "ingressgateway"})
        .servers(lambda servers: servers.add(
            lambda server: server
            .port(lambda port: port
                .number(80)
                .name("http")
                .protocol("HTTP")
            )
            .hosts(["*.example.com"])
        ))
    )
    .build()
)

Using the Context Manager Builder API

from cloudcoil.models.istio import networking

# Create a Gateway using context managers
with networking.v1.Gateway.new() as gateway:
    with gateway.metadata() as metadata:
        metadata.name("main-gateway")
        metadata.namespace("default")
    
    with gateway.spec() as spec:
        spec.selector({"istio": "ingressgateway"})
        
        with spec.servers() as server_list:
            with server_list.add() as server:
                with server.port() as port:
                    port.number(80)
                    port.name("http")
                    port.protocol("HTTP")
                server.hosts(["*.example.com"])

# Create a VirtualService using context managers
with networking.v1.VirtualService.new() as vs:
    with vs.metadata() as metadata:
        metadata.name("website")
        metadata.namespace("default")
    
    with vs.spec() as vs_spec:
        vs_spec.hosts(["website.example.com"])
        vs_spec.gateways(["main-gateway"])
        
        with vs_spec.http() as http_list:
            with http_list.add() as route:
                with route.route() as route_list:
                    with route_list.add() as weight:
                        with weight.destination() as dest:
                            dest.host("website-svc")
                            with dest.port() as dest_port:
                                dest_port.number(8080)

final_vs = vs.build()

Mixing Builder Styles

from cloudcoil.models.istio import networking
from cloudcoil import apimachinery

# Create a Gateway mixing different builder styles
with networking.v1.Gateway.new() as gateway:
    # Direct object initialization
    gateway.metadata(apimachinery.ObjectMeta(
        name="main-gateway",
        namespace="default"
    ))
    
    with gateway.spec() as spec:
        # Simple field assignment
        spec.selector({"istio": "ingressgateway"})
        
        # Fluent style for complex structures
        spec.servers([
            networking.v1.Server(
                port=networking.v1.Port(
                    number=80,
                    name="http",
                    protocol="HTTP"
                ),
                hosts=["*.example.com"]
            )
        ])

final_gateway = gateway.build()

# Create a VirtualService mixing styles
with networking.v1.VirtualService.new() as vs:
    vs.metadata(lambda m: m
        .name("website")
        .namespace("default")
    )
    
    with vs.spec() as spec:
        # Simple assignments
        spec.hosts(["website.example.com"])
        spec.gateways(["main-gateway"])
        
        # Context managers for deep nesting
        with spec.http() as http_list:
            with http_list.add() as route:
                # Fluent style for route configuration
                route.route(lambda routes: routes
                    .add(lambda w: w
                        .destination(lambda d: d
                            .host("website-svc")
                            .port(lambda p: p.number(8080))
                        )
                    )
                )

final_vs = vs.build()

The builder system 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
  • 🔀 Flexibility to mix different builder styles

📚 Documentation

For complete documentation, visit cloudcoil.github.io/cloudcoil

📜 License

Apache License, Version 2.0 - see LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudcoil_models_istio-1.24.2.0.tar.gz (217.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudcoil_models_istio-1.24.2.0-py3-none-any.whl (165.2 kB view details)

Uploaded Python 3

File details

Details for the file cloudcoil_models_istio-1.24.2.0.tar.gz.

File metadata

File hashes

Hashes for cloudcoil_models_istio-1.24.2.0.tar.gz
Algorithm Hash digest
SHA256 4ffbbffed1102b2162739192a1297a0f589997895c47f4183d1fda4830bec8b7
MD5 f2ddafa0026700ca98d77ba314e609e2
BLAKE2b-256 e4a5d74009ef142dbededdd09fac70bce7adac9234da1a74fe18902ebef9d3c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for cloudcoil_models_istio-1.24.2.0.tar.gz:

Publisher: pypi_publish.yml on cloudcoil/models-istio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cloudcoil_models_istio-1.24.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudcoil_models_istio-1.24.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74914af8553151237614494ac266964f667d7cd22f14190c9257ca9443be6a33
MD5 8fc3e836b2324c913bd55c64aa649160
BLAKE2b-256 cf17e73575c6cad5480ce1d774cf2080659ce3287e091792cf96c0cdc488b09c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cloudcoil_models_istio-1.24.2.0-py3-none-any.whl:

Publisher: pypi_publish.yml on cloudcoil/models-istio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page