bitnami / kube-libsonnet

Bitnami's jsonnet library for building Kubernetes manifests
https://bitnami.com
Apache License 2.0
172 stars 49 forks source link

Pod evaluation fails when more than one container is defined #44

Closed xvuko closed 4 years ago

xvuko commented 4 years ago

Steps to reproduce:

  1. create pod with more than one container

Evaluation of this fails when put in tests directory:

local kube = import "../kube.libsonnet";
local simple_validate = (import "test-simple-validate.pass.jsonnet").items_;
simple_validate {
  pod+: {
    spec+: {
      containers_: {
        first: kube.Container("first") { image: "nginx" },
        second: kube.Container("second") { image: "nginx" },
      },
    },
  },
}

Cause

in kube.jibsonnet:

PodSpec: {
    // The 'first' container is used in various defaults in k8s.
    local container_names = std.objectFields(self.containers_),
    default_container:: if std.length(container_names) > 1 then "default" else container_names[0] 
    [...]
}

"default" as default_container should be used when std.length(container_names) < 1. In current code container_names[0] is used when container_names is empty.

xvuko commented 4 years ago

My bad. When there are multiple containers in one Pod one of them should be named default or default_container should be overridden.