NAME

IO::K8s::Unstructured - Untyped Kubernetes object for a Kind nothing else resolves

VERSION

version 1.108

SYNOPSIS

use IO::K8s::Unstructured;

my $obj = IO::K8s::Unstructured->FROM_HASH({
    apiVersion => 'example.com/v1',
    kind       => 'Widget',
    metadata   => { name => 'my-widget' },
    spec       => { color => 'blue' },
});

$obj->apiVersion;      # 'example.com/v1'
$obj->kind;            # 'Widget'
$obj->metadata->name;  # 'my-widget'
$obj->TO_JSON;         # retains the 'spec' value for re-emission

# Opt-in fallback for a Kind no shipped or AutoGen'd class resolves:
my $k8s = IO::K8s->new(unknown_kinds => 'unstructured');
my $obj = $k8s->inflate($document);  # an Unstructured instead of a die

DESCRIPTION

apiVersion, kind and metadata are ordinary k8s-declared attributes here, not the fixed identity IO::K8s::Role::APIObject gives a built-in or CRD class -- there is no api_version()/kind() method pair to disagree with the document, because this class has no opinion of its own about what Kind it holds. Every other field on the wire -- spec, status, or anything else a document happens to carry -- rides in the "UNKNOWN FIELDS" in IO::K8s::Role::Resource bag exactly the way an undeclared field does on any typed class: FROM_HASH keeps it and TO_JSON re-emits the same Perl value, so an arbitrary custom resource round-trips semantically with no schema of its own. It does not preserve the original JSON or YAML bytes, whitespace or key order; to_json emits the normal canonical JSON encoding.

This is the class "inflate" in IO::K8s and "new_object" in IO::K8s build when the instance was constructed with unknown_kinds => 'unstructured' and the document's apiVersion/kind resolves to no registered class (built-in, CRD-registered, or AutoGen'd from an openapi_spec) -- see "unknown_kinds" in IO::K8s. Bare IO::K8s keeps failing closed by default; this class is never built without the caller opting in.

strict => 1 is exempted for this fallback specifically: IO::K8s localizes $IO::K8s::Resource::STRICT for the whole inflate/ new_object call, but this class has nothing else declared to check a field against -- every field beyond apiVersion/kind/metadata is precisely what it exists to preserve, so strict would otherwise make it die on the very data it is supposed to keep. A registered Kind with an unexpected field still dies under strict as normal; only the already-unresolvable-Kind fallback this class represents is exempt.

apiVersion

The document's apiVersion, taken verbatim -- ordinary data, not a fixed identity method.

kind

The document's kind, taken verbatim -- ordinary data, not a fixed identity method.

metadata

Typed the same way every top-level Kubernetes object types it: an IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::ObjectMeta.

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/pplu/io-k8s-p5/issues.

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) 2018-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004