NAME

Kubernetes::REST::CLI::Crd2Class - Generate IO::K8s classes from a CustomResourceDefinition

VERSION

version 1.108

SYNOPSIS

use Kubernetes::REST::CLI::Crd2Class;

my $cli = Kubernetes::REST::CLI::Crd2Class->new_with_options;
exit $cli->run;

DESCRIPTION

MooX::Options-based class that powers the kube_crd2class CLI tool: the D15 wrapper around the D10 source emitter. It reads a CustomResourceDefinition from a file and prints, for every served version, the checked-in, documented IO::K8s class source that models it - the k8s DSL block plus a POD skeleton - so a cluster's CRDs can become typed, hand-maintained Perl classes without writing them by hand (the kopium / cdk8s import path).

The schema-to-DSL work is entirely IO::K8s's: "load" in IO::K8s::CRD, "served_versions" in IO::K8s::CRD and "generate" in IO::K8s::CRD build the classes and "render" in IO::K8s::CRD::Emitter renders them. This class is only the CLI hull: file in, emitter, source out.

The -f path never talks to a cluster: it builds the api lazily through Kubernetes::REST::CLI::Role::Connection, so reading a file reads no kubeconfig. The /from_cluster path uses that same api to list the cluster's CustomResourceDefinitions, picks the one whose spec.names.kind matches the given Kind, and feeds its manifest through the very same emitter pipeline as -f - so the two inputs produce identical source for the same CRD.

file

Path to a file holding one or more CustomResourceDefinition manifests (YAML, possibly multi-document, or JSON). Every served version of every CRD in the file is turned into class source.

Short option: -f

namespace

The base package the generated classes are rendered under, without the version segment: IO::K8s::MyProvider yields IO::K8s::MyProvider::V1::Kind for a served v1. When omitted a default is derived from the CRD group's leading DNS label (cert-manager.io becomes IO::K8s::CertManager). Per served version the version name is appended, ucfirst-ed the way the D6 provider namespaces are (v1alpha1 becomes V1alpha1).

Short option: -n

output_dir

When set, each rendered class is written to <output_dir>/<relative/path>.pm (intermediate directories created) instead of being printed to STDOUT, and the path written is logged to STDERR. Without it every class is printed to STDOUT, each under a banner naming its relative path and the apiVersion it models.

Short option: -d

from_cluster

A Kubernetes Kind (for example CronTab) that a live cluster already serves through a CustomResourceDefinition. The cluster's CRDs are listed through "api" and the one whose spec.names.kind matches is turned into class source for every served version, exactly as "file" would from that CRD's manifest. Dies clearly when no CRD - or more than one - serves the Kind.

Reaching the cluster needs a kubeconfig, so this path honours --kubeconfig and --context from Kubernetes::REST::CLI::Role::Connection; the "file" path reads neither.

run

my $exit_code = $cli->run;

Entry point called by bin/kube_crd2class. Obtains one or more CRD manifests - from "file", or from the cluster by Kind when "from_cluster" is given - and for every served version of every CRD renders the IO::K8s class source through IO::K8s::CRD::Emitter, printing it to STDOUT or writing it under "output_dir" when that is set. Returns 0.

Dies with usage guidance when neither input is supplied, when the "file" does not exist, or when "from_cluster" names a Kind the cluster does not serve through exactly one CustomResourceDefinition.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/pplu/kubernetes-rest/issues.

IRC

Join #kubernetes on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHORS

  • Torsten Raudssus <getty@cpan.org>

  • Jose Luis Martinez Torres <jlmartin@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004