| 1 | package IO::K8s::Types; | ||
| 2 | # ABSTRACT: Type::Tiny type library for Kubernetes resources | ||
| 3 | 161 | our $VERSION = '1.112'; | |
| 4 | 161 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 161 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 161 | ▶ | use Type::Library -base, -declare => qw( IntOrStr Quantity Time Opaque ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 161 | ▶ | use Type::Utils -all; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 161 | ▶ | use Types::Standard -types; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 161 | ▶ | use Error::TypeTiny (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | # Re-export common Types::Standard types | ||
| 12 | 161 | ▶ | BEGIN { extends 'Types::Standard' } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | # Kubernetes scalar types | ||
| 15 | |||
| 16 | 161 | declare IntOrStr, as Str; | |
| 17 | |||
| 18 | # Suffix set follows apimachinery pkg/api/resource/suffix.go (decimal SI | ||
| 19 | # n u m "" k M G T P E, binary Ki..Ei, decimal exponent e/E); note the BNF | ||
| 20 | # in the quantity.go doc comment is stale and omits n and u. | ||
| 21 | declare Quantity, as Str, | ||
| 22 | 1303 | ▶ | where { /\A[+-]?(\d+\.?\d*|\d*\.\d+)([eE][+-]?\d+|Ki|Mi|Gi|Ti|Pi|Ei|[numkMGTPE])?\z/ }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 23 | 4 | ▶ | message { "Value '$_' is not a valid Kubernetes Quantity" }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 24 | |||
| 25 | declare Time, as Str, | ||
| 26 | 2604 | ▶ | where { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})\z/ }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 27 | 1 | ▶ | message { "Value '$_' is not a valid RFC3339 timestamp" }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 28 | |||
| 29 | # The free map (k191): any hash, values untyped and copied through as they | ||
| 30 | # are -- RawExtension, fieldsV1, a CRD's preserve-unknown object. The same | ||
| 31 | # check as a bare HashRef; its own name is what the k8s DSL reads to tell it | ||
| 32 | # from a string map. Deliberately not parameterizable: a map whose values | ||
| 33 | # have a type is HashRef[X], and Opaque[X] dies rather than meaning that. | ||
| 34 | # The generator is there only to refuse: without one, Type::Library gives | ||
| 35 | # the exported Opaque an empty prototype, and Opaque[Str] would be a Perl | ||
| 36 | # syntax error that never names the type. | ||
| 37 | declare Opaque, as HashRef, | ||
| 38 | 2 | ▶ | constraint_generator => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 39 | 2 | Error::TypeTiny::croak('Opaque takes no parameters: it is the free map; ' | |
| 40 | . 'declare a map with typed values as HashRef[...]'); | ||
| 41 | 161 | }; | |
| 42 | |||
| 43 | # Core V1 Types | ||
| 44 | 161 | class_type 'Pod', { class => 'IO::K8s::Api::Core::V1::Pod' }; | |
| 45 | 161 | class_type 'PodSpec', { class => 'IO::K8s::Api::Core::V1::PodSpec' }; | |
| 46 | 161 | class_type 'PodStatus', { class => 'IO::K8s::Api::Core::V1::PodStatus' }; | |
| 47 | 161 | class_type 'Container', { class => 'IO::K8s::Api::Core::V1::Container' }; | |
| 48 | 161 | class_type 'Service', { class => 'IO::K8s::Api::Core::V1::Service' }; | |
| 49 | 161 | class_type 'ServiceSpec', { class => 'IO::K8s::Api::Core::V1::ServiceSpec' }; | |
| 50 | 161 | class_type 'ConfigMap', { class => 'IO::K8s::Api::Core::V1::ConfigMap' }; | |
| 51 | 161 | class_type 'Secret', { class => 'IO::K8s::Api::Core::V1::Secret' }; | |
| 52 | 161 | class_type 'Namespace', { class => 'IO::K8s::Api::Core::V1::Namespace' }; | |
| 53 | 161 | class_type 'Node', { class => 'IO::K8s::Api::Core::V1::Node' }; | |
| 54 | 161 | class_type 'PersistentVolume', { class => 'IO::K8s::Api::Core::V1::PersistentVolume' }; | |
| 55 | 161 | class_type 'PersistentVolumeClaim', { class => 'IO::K8s::Api::Core::V1::PersistentVolumeClaim' }; | |
| 56 | |||
| 57 | # Apps V1 Types | ||
| 58 | 161 | class_type 'Deployment', { class => 'IO::K8s::Api::Apps::V1::Deployment' }; | |
| 59 | 161 | class_type 'DeploymentSpec', { class => 'IO::K8s::Api::Apps::V1::DeploymentSpec' }; | |
| 60 | 161 | class_type 'ReplicaSet', { class => 'IO::K8s::Api::Apps::V1::ReplicaSet' }; | |
| 61 | 161 | class_type 'StatefulSet', { class => 'IO::K8s::Api::Apps::V1::StatefulSet' }; | |
| 62 | 161 | class_type 'DaemonSet', { class => 'IO::K8s::Api::Apps::V1::DaemonSet' }; | |
| 63 | |||
| 64 | # Batch V1 Types | ||
| 65 | 161 | class_type 'Job', { class => 'IO::K8s::Api::Batch::V1::Job' }; | |
| 66 | 161 | class_type 'JobSpec', { class => 'IO::K8s::Api::Batch::V1::JobSpec' }; | |
| 67 | 161 | class_type 'JobStatus', { class => 'IO::K8s::Api::Batch::V1::JobStatus' }; | |
| 68 | 161 | class_type 'CronJob', { class => 'IO::K8s::Api::Batch::V1::CronJob' }; | |
| 69 | 161 | class_type 'CronJobSpec', { class => 'IO::K8s::Api::Batch::V1::CronJobSpec' }; | |
| 70 | |||
| 71 | # Networking V1 Types | ||
| 72 | 161 | class_type 'Ingress', { class => 'IO::K8s::Api::Networking::V1::Ingress' }; | |
| 73 | 161 | class_type 'IngressSpec', { class => 'IO::K8s::Api::Networking::V1::IngressSpec' }; | |
| 74 | 161 | class_type 'NetworkPolicy', { class => 'IO::K8s::Api::Networking::V1::NetworkPolicy' }; | |
| 75 | |||
| 76 | # RBAC V1 Types | ||
| 77 | 161 | class_type 'Role', { class => 'IO::K8s::Api::Rbac::V1::Role' }; | |
| 78 | 161 | class_type 'RoleBinding', { class => 'IO::K8s::Api::Rbac::V1::RoleBinding' }; | |
| 79 | 161 | class_type 'ClusterRole', { class => 'IO::K8s::Api::Rbac::V1::ClusterRole' }; | |
| 80 | 161 | class_type 'ClusterRoleBinding', { class => 'IO::K8s::Api::Rbac::V1::ClusterRoleBinding' }; | |
| 81 | |||
| 82 | # Meta V1 Types | ||
| 83 | 161 | class_type 'ObjectMeta', { class => 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::ObjectMeta' }; | |
| 84 | 161 | class_type 'LabelSelector', { class => 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::LabelSelector' }; | |
| 85 | 161 | class_type 'Status', { class => 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::Status' }; | |
| 86 | |||
| 87 | # API Extensions Types | ||
| 88 | 161 | class_type 'CustomResourceDefinition', { class => 'IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::V1::CustomResourceDefinition' }; | |
| 89 | |||
| 90 | # Export tags | ||
| 91 | 161 | our %EXPORT_TAGS = ( | |
| 92 | k8s_scalars => [qw( IntOrStr Quantity Time )], | ||
| 93 | k8s_maps => [qw( Opaque )], | ||
| 94 | core => [qw( Pod PodSpec PodStatus Container Service ServiceSpec | ||
| 95 | ConfigMap Secret Namespace Node | ||
| 96 | PersistentVolume PersistentVolumeClaim )], | ||
| 97 | apps => [qw( Deployment DeploymentSpec ReplicaSet StatefulSet DaemonSet )], | ||
| 98 | batch => [qw( Job JobSpec JobStatus CronJob CronJobSpec )], | ||
| 99 | networking => [qw( Ingress IngressSpec NetworkPolicy )], | ||
| 100 | rbac => [qw( Role RoleBinding ClusterRole ClusterRoleBinding )], | ||
| 101 | meta => [qw( ObjectMeta LabelSelector Status )], | ||
| 102 | ); | ||
| 103 | |||
| 104 | 161 | $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ]; | |
| 105 | |||
| 106 | 161 | 1; | |
| 107 | |||
| 108 | __END__ | ||