Kustomize: Namespace reference using vars

Created on 7 Dec 2018  路  8Comments  路  Source: kubernetes-sigs/kustomize

Referencing the namespace using variables reports the following warning:
couldn't resolve v: {NAMESPACE noGroup_v1_NAMESPACE {metadata.name}}

When defining the namespace as a resource, the warning is omitted, though the variable not substituted (both cases). Does referencing a name require a special transformer configuration?

This is maybe related to this issue: #401

_kustomization.yaml_

namespace: somename # including or omitting this doesn't seem to make any difference
vars:
  - name: NAMEPSPACE
    objref:
      apiVersion: v1
      kind: Namespace
      name: somename

resources:
  - statefulSet.yaml
  - namespace.yaml # omit this for the warning

_statefulSet.yaml_

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: example
spec:
  template:
    metadata:
       name: example
    spec:
      containers:
      - name: proxy
        image: openshift/oauth-proxy:v1.0.0
        args:
           - -client-id=system:serviceaccount:$(NAMESPACE):somename
           - '-openshift-sar={"namespace": "$(NAMESPACE)"}'

_namespace.yaml_

apiVersion: apps/v1beta1
kind: Namespace
metadata:
  name: somename

Most helpful comment

From the original description, the variable is NAMEPSPACE with an extra P. Maybe that's the reason.

All 8 comments

@emanuelbuholzer The statefulSet.yaml you pasted here is not valid. The image should be inside an containers array, which is missing.

@Liujingfang1 Oh yes I didn't check the example good enough. I've updated the example, though the issue still remains.

@emanuelbuholzer It should work. If you are on a previous version, can you try 1.0.11?

@lichuqiang I've tested with 1.0.11 and just retried it. The issue remains.

Based on the varreference.go the kind: namespace is not yet supported. @Liujingfang1 Why do you expect it to work?

@emanuelbuholzer you should try this, works with bin from head:
kustomization.yaml

vars:
- name: NAMESPACE
  objref:
    apiVersion: apps/v1beta1
    kind: Namespace
    name: somename

From the original description, the variable is NAMEPSPACE with an extra P. Maybe that's the reason.

@Liujingfang1 - does this work ? I tried with the following vars

vars:
  - name: NAMESPACE
    objref:
      kind: Namespace
      apiVersion: v1
      name: demos-2

And I get the same error like

Error: var '{NAMESPACE ~G_v1_Namespace {metadata.name}}' cannot be mapped to a field in the set of known resources
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wuestkamp picture wuestkamp  路  3Comments

nicks picture nicks  路  3Comments

mgoodness picture mgoodness  路  4Comments

natasha41575 picture natasha41575  路  3Comments

bugbuilder picture bugbuilder  路  3Comments