Skip to content
  • bryanl's avatar
    Support environment arguments in module parameters · 5b3be7a9
    bryanl authored
    
    
    It is possible that a user might want to use environment parameters
    (namespace or server) in their parameters. This would not work with
    ksonnet for two reasons:
    
    1. ksonnet didn't provide external variables with those settings
    1. params.libsonnet was evaluated as an object
    
    This change adds support for these two items.
    
    ```
    bash-3.2$ ks param list
    COMPONENT PARAM         VALUE
    ========= =====         =====
    ds        arr           [1, 2, 3, 4]
    ds        containerPort 80
    ds        image         'gcr.io/heptio-images/ks-guestbook-demo:0.1'
    ds        name          'ds'
    ds        namespace     ''
    ds        obj           { a: 'b' }
    ds        replicas      1
    ds        server        ''
    ds        servicePort   80
    ds        type          'ClusterIP'
    bash-3.2$ ks param list --env default
    COMPONENT PARAM         VALUE
    ========= =====         =====
    ds        arr           [1, 2, 3, 4]
    ds        containerPort 80
    ds        image         'gcr.io/heptio-images/ks-guestbook-demo:0.1'
    ds        name          'ds'
    ds        namespace     'default'
    ds        obj           { a: 'b' }
    ds        replicas      1
    ds        server        'https://localhost:6443'
    ds        servicePort   80
    ds        type          'ClusterIP'
    ```
    
    An example parameters file that produces the preceeding output:
    
    ```js
    local env = std.extVar("__ksonnet/environments");
    
    {
      global: {
      },
      components: {
        ds: {
          containerPort: 80,
          image: "gcr.io/heptio-images/ks-guestbook-demo:0.1",
          name: "ds",
          replicas: 1,
          servicePort: 80,
          type: "ClusterIP",
          namespace: env.namespace,
          server: env.server,
          obj: {a:"b"},
          arr: [1,2,3,4],
        },
      },
    }
    ```
    
    * note: params files aren't currently generated with the `env` local.
    
    Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
    5b3be7a9