ksonnet / ksonnet-lib

Codegen for Kubernetes-API-compatible Jsonnet libraries
https://ksonnet.io
Apache License 2.0
444 stars 82 forks source link

Can't set deployment namespace with simple ".withNamespace" mixin #92

Open fabioy opened 6 years ago

fabioy commented 6 years ago

When using deployment object, somehow the mixins get confused, so the top level ".withNamespace" sets it for the pod template, and not the deployment:

Repro:

local appDeployment = deployment .new( "heptio-server", 4, serverContainer, params.labels) .withNamespace("heptio-svc");

Expected: deployment within given namespace.

Result: Sets the namespace in the pod spec.

Workaround:

The workaround is a bit hard to discover, but this works:

local appDeployment = deployment .new( "heptio-server", params.replicas, serverContainer, myparams.labels)+ deployment.mixin.metadata.withNamespace("heptio-svc");

askreet commented 4 years ago

AFAICT this is because scoped withX methods are used which change the mixins in the associated object. Seems to be a somewhat pervasive problem, though most easily seen in Deployment because of the nested nature of the objects. Essentially, the Deployment you get back is broken.