| 1 | package Kubernetes::REST::CLI::Crd2Class; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | our $VERSION = '1.108'; | |||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Generate IO::K8s classes from a CustomResourceDefinition | ||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 1 | with 'Kubernetes::REST::CLI::Role::Connection'; | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use MooX::Options; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Path::Tiny qw( path ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use IO::K8s::CRD (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use IO::K8s::CRD::Emitter (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 1 | option file => ( | |||||||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 15 | format => 's', | ||||||||||||||||||||||||||||||||||
| 16 | short => 'f', | ||||||||||||||||||||||||||||||||||
| 17 | doc => 'Path to a CustomResourceDefinition YAML/JSON file', | ||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 1 | option namespace => ( | |||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 23 | format => 's', | ||||||||||||||||||||||||||||||||||
| 24 | short => 'n', | ||||||||||||||||||||||||||||||||||
| 25 | doc => 'Base package for the generated classes (default: derived from the CRD group)', | ||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 1 | option output_dir => ( | |||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 31 | format => 's', | ||||||||||||||||||||||||||||||||||
| 32 | short => 'd', | ||||||||||||||||||||||||||||||||||
| 33 | doc => 'Write the .pm files under this directory instead of printing them', | ||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 1 | option from_cluster => ( | |||||||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 39 | format => 's', | ||||||||||||||||||||||||||||||||||
| 40 | doc => 'Generate from a Kind whose CRD a live cluster already serves', | ||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | sub run { | ||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 46 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | 5 | my $from_cluster = $self->from_cluster; | |||||||||||||||||||||||||||||||||
| 49 | 5 | my $file = $self->file; | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 5 | my $crds; | |||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | if (defined $from_cluster && length $from_cluster) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $from_cluster and length $from_cluster
MC/DC50%1/2
defined $from_cluster and length $from_cluster
defined $from_cluster
length $from_cluster
Truth table66%2/3
A and B
A= defined $from_clusterB= length $from_cluster
| |||||||||||||||||||||||||||||||||||
| 53 | 2 | $crds = $self->_crds_from_cluster($from_cluster); | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | ▶ | elsif (defined $file && length $file) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $file and length $file
MC/DC50%1/2
defined $file and length $file
defined $file
length $file
Truth table66%2/3
A and B
A= defined $fileB= length $file
| |||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | croak "kube_crd2class: no such file: $file\n" unless -f $file; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | 2 | $crds = IO::K8s::CRD->load($file); | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||
| 60 | 1 | croak "kube_crd2class: no input given; pass --file/-f <crd.yaml> " | |||||||||||||||||||||||||||||||||
| 61 | . "or --from-cluster <Kind>\n"; | ||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 3 | binmode STDOUT, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 3 | my $files = $self->_render_crds($crds); | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 3 | ▶ | if (defined $self->output_dir && length $self->output_dir) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->output_dir and length $self->output_dir
MC/DC50%1/2
defined $self->output_dir and length $self->output_dir
defined $self->output_dir
length $self->output_dir
Truth table66%2/3
A and B
A= defined $self->output_dirB= length $self->output_dir
| |||||||||||||||||||||||||||||||||||
| 69 | 1 | $self->_write_files($files); | |||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||
| 72 | 2 | $self->_print_files($files); | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | 3 | return 0; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | # The CRD hashref(s) for one Kind served by the cluster, in the shape | ||||||||||||||||||||||||||||||||||
| 78 | # IO::K8s::CRD->load returns (so _render_crds drives the same pipeline as -f): | ||||||||||||||||||||||||||||||||||
| 79 | # list the cluster's CustomResourceDefinitions through the shared api, keep the | ||||||||||||||||||||||||||||||||||
| 80 | # one whose spec.names.kind matches, and normalize it through ->load - which | ||||||||||||||||||||||||||||||||||
| 81 | # takes a CustomResourceDefinition object straight, via its TO_JSON. A Kind | ||||||||||||||||||||||||||||||||||
| 82 | # served by no CRD, or by several (same kind in different groups), dies clearly. | ||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | sub _crds_from_cluster { | ||||||||||||||||||||||||||||||||
|
Subroutine
_crds_from_cluster: called CC=6 SCAR=19.5
| |||||||||||||||||||||||||||||||||||
| 84 | 3 | my ($self, $kind) = @_; | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 3 | my $list = $self->api->list('CustomResourceDefinition'); | |||||||||||||||||||||||||||||||||
| 87 | my @matches = grep { | ||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | my $names = $_->spec && $_->spec->names; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->spec && $_->spec->names
MC/DC0%0/2
$_->spec && $_->spec->names
$_->spec
$_->spec->names
Truth table33%1/3
A && B
A= $_->specB= $_->spec->names
| |||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | $names && defined $names->kind && $names->kind eq $kind; | ||||||||||||||||||||||||||||||||
|
Condition50%3/6
$names && defined $names->kind && $names->kind eq $kind
$names and defined $names->kind
MC/DC33%1/3
$names && defined $names->kind && $names->kind eq $kind
$names
defined $names->kind
$names->kind eq $kind
Truth table50%2/4
A and B && C
A= $namesB= defined $names->kindC= $names->kind eq $kind
| |||||||||||||||||||||||||||||||||||
| 90 | 3 | } @{ $list->items }; | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | croak "kube_crd2class: no CustomResourceDefinition on the cluster serves " | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 93 | . "kind '$kind'\n" unless @matches; | ||||||||||||||||||||||||||||||||||
| 94 | croak "kube_crd2class: kind '$kind' is served by more than one " | ||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | . "CustomResourceDefinition (" . join(', ', map { $_->metadata->name } @matches) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | . "); nothing here can pick between them\n" if @matches > 1; | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 2 | return IO::K8s::CRD->load($matches[0]); | |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | # An arrayref of [ relative_path, api_version, source ] blocks for every | ||||||||||||||||||||||||||||||||||
| 102 | # served version of every loaded CRD, in manifest order - the whole | ||||||||||||||||||||||||||||||||||
| 103 | # schema-to-DSL job delegated to IO::K8s (load/served_versions/generate/render). | ||||||||||||||||||||||||||||||||||
| 104 | 7 | ▶ | sub _render_crds { | ||||||||||||||||||||||||||||||||
|
Subroutine
_render_crds: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 105 | 7 | my ($self, $crds) = @_; | |||||||||||||||||||||||||||||||||
| 106 | 7 | my @out; | |||||||||||||||||||||||||||||||||
| 107 | 7 | for my $crd (@$crds) { | |||||||||||||||||||||||||||||||||
| 108 | 7 | my $ns = $self->_namespace_for($crd); | |||||||||||||||||||||||||||||||||
| 109 | 7 | my $versions = IO::K8s::CRD->served_versions($crd); | |||||||||||||||||||||||||||||||||
| 110 | # reuse_core on (D5) - a nested schema shaped like a shipped core | ||||||||||||||||||||||||||||||||||
| 111 | # class is typed as that class rather than a per-CRD copy. | ||||||||||||||||||||||||||||||||||
| 112 | 7 | my $classes = IO::K8s::CRD->generate($crd, $ns, reuse_core => 1); | |||||||||||||||||||||||||||||||||
| 113 | 7 | for my $v (@$versions) { | |||||||||||||||||||||||||||||||||
| 114 | 14 | ▶ | my $root = $classes->{ $v->{api_version} } or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | my $emitter = IO::K8s::CRD::Emitter->new( | ||||||||||||||||||||||||||||||||||
| 116 | 14 | base => $ns . '::' . ucfirst($v->{name}), | |||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||
| 118 | 14 | my $rendered = $emitter->render($root); | |||||||||||||||||||||||||||||||||
| 119 | 14 | push @out, map { [ $_, $v->{api_version}, $rendered->{$_} ] } | |||||||||||||||||||||||||||||||||
| 120 | sort keys %$rendered; | ||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||
| 123 | 7 | return \@out; | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | # The base package for one CRD: --namespace when given, otherwise | ||||||||||||||||||||||||||||||||||
| 127 | # IO::K8s::<CamelCase leading DNS label of the group>. | ||||||||||||||||||||||||||||||||||
| 128 | 7 | ▶ | sub _namespace_for { | ||||||||||||||||||||||||||||||||
|
Subroutine
_namespace_for: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||||||||
| 129 | 7 | my ($self, $crd) = @_; | |||||||||||||||||||||||||||||||||
| 130 | 7 | ▶ | return $self->namespace if defined $self->namespace && length $self->namespace; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->namespace and length $self->namespace
MC/DC50%1/2
defined $self->namespace and length $self->namespace
defined $self->namespace
length $self->namespace
Truth table66%2/3
A and B
A= defined $self->namespaceB= length $self->namespace
| |||||||||||||||||||||||||||||||||||
| 131 | 6 | ▶ | my $group = $crd->{spec}{group} // ''; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$crd->{"spec"}{"group"} // ""
MC/DC0%0/1
$crd->{"spec"}{"group"} // ""
$crd->{"spec"}{"group"}
Truth table50%1/2
A
A= $crd->{"spec"}{"group"}
| |||||||||||||||||||||||||||||||||||
| 132 | 6 | my ($label) = split /\./, $group; | |||||||||||||||||||||||||||||||||
| 133 | 6 | ▶ | $label = 'Crd' unless defined $label && length $label; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $label and length $label
MC/DC0%0/2
defined $label and length $label
defined $label
length $label
Truth table33%1/3
A and B
A= defined $labelB= length $label
| |||||||||||||||||||||||||||||||||||
| 134 | 6 | my $camel = join '', map { ucfirst } split /-/, $label; | |||||||||||||||||||||||||||||||||
| 135 | 6 | return 'IO::K8s::' . $camel; | |||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | sub _print_files { | ||||||||||||||||||||||||||||||||
|
Subroutine
_print_files: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 139 | 2 | my ($self, $files) = @_; | |||||||||||||||||||||||||||||||||
| 140 | 2 | my @blocks = @$files; | |||||||||||||||||||||||||||||||||
| 141 | 2 | for my $i (0 .. $#blocks) { | |||||||||||||||||||||||||||||||||
| 142 | 8 | my ($path, $api_version, $source) = @{ $blocks[$i] }; | |||||||||||||||||||||||||||||||||
| 143 | 8 | ▶ | print "\n" if $i; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | 8 | print '# ', ('=' x 74), "\n"; | |||||||||||||||||||||||||||||||||
| 145 | 8 | print "# $path ($api_version)\n"; | |||||||||||||||||||||||||||||||||
| 146 | 8 | print '# ', ('=' x 74), "\n"; | |||||||||||||||||||||||||||||||||
| 147 | 8 | print $source; | |||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||
| 149 | 2 | return; | |||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | sub _write_files { | ||||||||||||||||||||||||||||||||
|
Subroutine
_write_files: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 153 | 1 | my ($self, $files) = @_; | |||||||||||||||||||||||||||||||||
| 154 | 1 | my $dir = path($self->output_dir); | |||||||||||||||||||||||||||||||||
| 155 | 1 | for my $block (@$files) { | |||||||||||||||||||||||||||||||||
| 156 | 4 | my ($path, undef, $source) = @$block; | |||||||||||||||||||||||||||||||||
| 157 | 4 | my $target = $dir->child($path); | |||||||||||||||||||||||||||||||||
| 158 | 4 | $target->parent->mkpath; | |||||||||||||||||||||||||||||||||
| 159 | 4 | $target->spew_utf8($source); | |||||||||||||||||||||||||||||||||
| 160 | 4 | print STDERR "wrote $target\n"; | |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||
| 162 | 1 | return; | |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | =pod | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | Kubernetes::REST::CLI::Crd2Class - Generate IO::K8s classes from a CustomResourceDefinition | ||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | version 1.108 | ||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | use Kubernetes::REST::CLI::Crd2Class; | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | my $cli = Kubernetes::REST::CLI::Crd2Class->new_with_options; | ||||||||||||||||||||||||||||||||||
| 186 | exit $cli->run; | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | L<MooX::Options>-based class that powers the L<kube_crd2class> CLI tool: the | ||||||||||||||||||||||||||||||||||
| 191 | D15 wrapper around the D10 source emitter. It reads a | ||||||||||||||||||||||||||||||||||
| 192 | C<CustomResourceDefinition> from a file and prints, for every B<served> | ||||||||||||||||||||||||||||||||||
| 193 | version, the checked-in, documented L<IO::K8s> class source that models it - | ||||||||||||||||||||||||||||||||||
| 194 | the C<k8s> DSL block plus a POD skeleton - so a cluster's CRDs can become | ||||||||||||||||||||||||||||||||||
| 195 | typed, hand-maintained Perl classes without writing them by hand (the | ||||||||||||||||||||||||||||||||||
| 196 | kopium / C<cdk8s import> path). | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | The schema-to-DSL work is entirely L<IO::K8s>'s: L<IO::K8s::CRD/load>, | ||||||||||||||||||||||||||||||||||
| 199 | L<IO::K8s::CRD/served_versions> and L<IO::K8s::CRD/generate> build the | ||||||||||||||||||||||||||||||||||
| 200 | classes and L<IO::K8s::CRD::Emitter/render> renders them. This class is only | ||||||||||||||||||||||||||||||||||
| 201 | the CLI hull: file in, emitter, source out. | ||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | The C<-f> path never talks to a cluster: it builds the L<api|/api> lazily | ||||||||||||||||||||||||||||||||||
| 204 | through L<Kubernetes::REST::CLI::Role::Connection>, so reading a file reads no | ||||||||||||||||||||||||||||||||||
| 205 | kubeconfig. The C</from_cluster> path uses that same C<api> to list the | ||||||||||||||||||||||||||||||||||
| 206 | cluster's C<CustomResourceDefinition>s, picks the one whose C<spec.names.kind> | ||||||||||||||||||||||||||||||||||
| 207 | matches the given Kind, and feeds its manifest through the very same emitter | ||||||||||||||||||||||||||||||||||
| 208 | pipeline as C<-f> - so the two inputs produce identical source for the same | ||||||||||||||||||||||||||||||||||
| 209 | CRD. | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | =head2 file | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | Path to a file holding one or more C<CustomResourceDefinition> manifests | ||||||||||||||||||||||||||||||||||
| 214 | (YAML, possibly multi-document, or JSON). Every served version of every CRD | ||||||||||||||||||||||||||||||||||
| 215 | in the file is turned into class source. | ||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | Short option: C<-f> | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | =head2 namespace | ||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | The base package the generated classes are rendered under, without the | ||||||||||||||||||||||||||||||||||
| 222 | version segment: C<IO::K8s::MyProvider> yields C<IO::K8s::MyProvider::V1::Kind> | ||||||||||||||||||||||||||||||||||
| 223 | for a served C<v1>. When omitted a default is derived from the CRD group's | ||||||||||||||||||||||||||||||||||
| 224 | leading DNS label (C<cert-manager.io> becomes C<IO::K8s::CertManager>). Per | ||||||||||||||||||||||||||||||||||
| 225 | served version the version name is appended, C<< ucfirst >>-ed the way the | ||||||||||||||||||||||||||||||||||
| 226 | D6 provider namespaces are (C<v1alpha1> becomes C<V1alpha1>). | ||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | Short option: C<-n> | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | =head2 output_dir | ||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | When set, each rendered class is written to | ||||||||||||||||||||||||||||||||||
| 233 | F<E<lt>output_dirE<gt>/E<lt>relative/pathE<gt>.pm> (intermediate directories | ||||||||||||||||||||||||||||||||||
| 234 | created) instead of being printed to STDOUT, and the path written is logged to | ||||||||||||||||||||||||||||||||||
| 235 | STDERR. Without it every class is printed to STDOUT, each under a banner | ||||||||||||||||||||||||||||||||||
| 236 | naming its relative path and the C<apiVersion> it models. | ||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | Short option: C<-d> | ||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | =head2 from_cluster | ||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||
| 242 | A Kubernetes B<Kind> (for example C<CronTab>) that a live cluster already | ||||||||||||||||||||||||||||||||||
| 243 | serves through a C<CustomResourceDefinition>. The cluster's CRDs are listed | ||||||||||||||||||||||||||||||||||
| 244 | through L</api> and the one whose C<spec.names.kind> matches is turned into | ||||||||||||||||||||||||||||||||||
| 245 | class source for every served version, exactly as L</file> would from that | ||||||||||||||||||||||||||||||||||
| 246 | CRD's manifest. Dies clearly when no CRD - or more than one - serves the Kind. | ||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||
| 248 | Reaching the cluster needs a kubeconfig, so this path honours C<--kubeconfig> | ||||||||||||||||||||||||||||||||||
| 249 | and C<--context> from L<Kubernetes::REST::CLI::Role::Connection>; the L</file> | ||||||||||||||||||||||||||||||||||
| 250 | path reads neither. | ||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | =head2 run | ||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||
| 254 | my $exit_code = $cli->run; | ||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | Entry point called by C<bin/kube_crd2class>. Obtains one or more CRD manifests | ||||||||||||||||||||||||||||||||||
| 257 | - from L</file>, or from the cluster by Kind when L</from_cluster> is given - | ||||||||||||||||||||||||||||||||||
| 258 | and for every served version of every CRD renders the L<IO::K8s> class source | ||||||||||||||||||||||||||||||||||
| 259 | through L<IO::K8s::CRD::Emitter>, printing it to STDOUT or writing it under | ||||||||||||||||||||||||||||||||||
| 260 | L</output_dir> when that is set. Returns 0. | ||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | Dies with usage guidance when neither input is supplied, when the L</file> does | ||||||||||||||||||||||||||||||||||
| 263 | not exist, or when L</from_cluster> names a Kind the cluster does not serve | ||||||||||||||||||||||||||||||||||
| 264 | through exactly one C<CustomResourceDefinition>. | ||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||
| 268 | =over | ||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | =item * L<kube_crd2class> - The CLI tool built on this class | ||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | =item * L<IO::K8s::CRD> - Loads a CRD and generates one class per served version | ||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | =item * L<IO::K8s::CRD::Emitter> - Renders those classes as house-style source | ||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | =item * L<Kubernetes::REST> - The client whose CRD support this generates classes for | ||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | =back | ||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||
| 280 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | =head2 Issues | ||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||
| 284 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||||
| 285 | L<https://github.com/pplu/kubernetes-rest/issues>. | ||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | =head2 IRC | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | Join C<#kubernetes> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||
| 293 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | =over 4 | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | =item * | ||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||
| 303 | =item * | ||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | Jose Luis Martinez Torres <jlmartin@cpan.org> | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | =back | ||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||
| 311 | This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>. | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | The Apache License, Version 2.0, January 2004 | ||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||||||||