IO-K8s
view release on metacpan or search on metacpan
t/24_combinations.t view on Meta::CPAN
#!/usr/bin/env perl
# Comprehensive combination & stress tests for IO::K8s
# Exercises real-world K8s resources, deep nesting, mixed construction,
# round-trip serialization, edge cases, and more.
use strict;
use warnings;
use Test::More;
use Test::Exception;
use JSON::MaybeXS;
use IO::K8s;
my $k8s = IO::K8s->new;
my $json = JSON::MaybeXS->new(utf8 => 0, canonical => 1);
# ============================================================================
# 1. Complex real-world K8s resources
# ============================================================================
subtest 'Full Deployment with init containers, multi-container, volumes, probes, resources' => sub {
my $deploy = $k8s->new_object('Deployment', {
metadata => {
name => 'webapp',
namespace => 'production',
labels => {
app => 'webapp',
version => 'v2',
'team.org' => 'platform',
},
annotations => {
'deployment.kubernetes.io/revision' => '5',
'kubectl.kubernetes.io/last-applied-configuration' => '{}',
},
},
spec => {
replicas => 3,
revisionHistoryLimit => 5,
strategy => {
type => 'RollingUpdate',
rollingUpdate => {
maxSurge => '25%',
maxUnavailable => '1',
},
},
selector => {
matchLabels => { app => 'webapp' },
},
template => {
metadata => {
labels => { app => 'webapp', version => 'v2' },
annotations => { 'prometheus.io/scrape' => 'true' },
},
spec => {
serviceAccountName => 'webapp-sa',
terminationGracePeriodSeconds => 60,
initContainers => [
{
name => 'init-db',
image => 'busybox:1.36',
command => ['/bin/sh', '-c', 'until nslookup db; do sleep 2; done'],
resources => {
requests => { cpu => '50m', memory => '64Mi' },
limits => { cpu => '100m', memory => '128Mi' },
},
},
{
name => 'init-migrations',
image => 'webapp:v2-migrate',
command => ['./migrate', '--up'],
env => [
{ name => 'DB_HOST', value => 'db.production.svc' },
{ name => 'DB_PORT', value => '5432' },
],
volumeMounts => [
{ name => 'config', mountPath => '/etc/config', readOnly => 1 },
],
},
],
containers => [
{
name => 'webapp',
image => 'webapp:v2.1.0',
imagePullPolicy => 'IfNotPresent',
ports => [
{ containerPort => 8080, name => 'http', protocol => 'TCP' },
{ containerPort => 9090, name => 'metrics', protocol => 'TCP' },
],
env => [
{ name => 'APP_ENV', value => 'production' },
{ name => 'LOG_LEVEL', value => 'info' },
{
name => 'DB_PASSWORD',
valueFrom => {
secretKeyRef => {
name => 'db-creds',
key => 'password',
},
},
},
],
resources => {
requests => { cpu => '250m', memory => '512Mi' },
limits => { cpu => '1', memory => '1Gi' },
},
livenessProbe => {
httpGet => {
path => '/healthz',
port => 'http',
},
initialDelaySeconds => 15,
periodSeconds => 20,
failureThreshold => 3,
},
readinessProbe => {
httpGet => {
path => '/readyz',
port => '8080',
},
initialDelaySeconds => 5,
( run in 0.523 second using v1.01-cache-2.11-cpan-995e09ba956 )