IO-K8s

 view release on metacpan or  search on metacpan

t/25_real_world.t  view on Meta::CPAN

    is($pod_spec->restartPolicy, 'Never', 'restartPolicy');

    # Multiple secretKeyRef env vars
    my $c = $pod_spec->containers->[0];
    is($c->env->[0]->valueFrom->secretKeyRef->key, 'host', 'secretKeyRef key');
    is($c->env->[1]->valueFrom->secretKeyRef->key, 'password', 'secretKeyRef password key');

    # Round-trip
    is($exported->{spec}{parallelism}, 3, 'round-trip parallelism');
    is($exported->{spec}{completions}, 10, 'round-trip completions');
};

# ============================================================================
# 22. Deployment with lifecycle hooks, topologySpreadConstraints, envFrom,
#     imagePullSecrets, terminationGracePeriodSeconds
# Source: based on real production workload patterns
# ============================================================================

subtest 'Deployment with lifecycle hooks and topologySpreadConstraints' => sub {
    my $yaml = <<'END_YAML';
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  namespace: production
  labels:
    app: web-app
    version: v3.2.1
  annotations:
    deployment.kubernetes.io/revision: "15"
    kubernetes.io/change-cause: "Update image to v3.2.1"
spec:
  replicas: 5
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
        version: v3.2.1
    spec:
      terminationGracePeriodSeconds: 60
      imagePullSecrets:
      - name: registry-credentials
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app: web-app
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: ScheduleAnyway
        labelSelector:
          matchLabels:
            app: web-app
      initContainers:
      - name: wait-for-db
        image: busybox:1.36
        command: ['sh', '-c', 'until nc -z postgres-primary 5432; do sleep 2; done']
        resources:
          requests:
            cpu: 10m
            memory: 16Mi
      containers:
      - name: web
        image: myapp/web:v3.2.1
        ports:
        - containerPort: 8080
          name: http
        - containerPort: 9090
          name: metrics
        envFrom:
        - configMapRef:
            name: web-app-config
        - secretRef:
            name: web-app-secrets
            optional: true
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "sleep 15 && kill -SIGTERM 1"]
          postStart:
            httpGet:
              path: /warmup
              port: 8080
        readinessProbe:
          httpGet:
            path: /ready
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
          failureThreshold: 3
        resources:
          requests:
            cpu: 250m
            memory: 512Mi
          limits:
            cpu: "1"
            memory: 1Gi
END_YAML

    my ($obj, $orig, $exported) = round_trip_yaml($yaml, 'Lifecycle+Topology Deployment');
    isa_ok($obj, 'IO::K8s::Api::Apps::V1::Deployment');
    is($obj->spec->replicas, 5, 'replicas');

    my $pod_spec = $obj->spec->template->spec;

    # terminationGracePeriodSeconds
    is($pod_spec->terminationGracePeriodSeconds, 60, 'terminationGracePeriodSeconds');

    # imagePullSecrets
    is(scalar @{$pod_spec->imagePullSecrets}, 1, 'imagePullSecrets count');



( run in 3.139 seconds using v1.01-cache-2.11-cpan-364913b4093 )