serverless / serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
Apache License 2.0
303 stars 81 forks source link

Make 'environment' schema compatible with k8s #79

Closed ccll closed 7 years ago

ccll commented 7 years ago

This fix allows the user to mount secrets/configmaps as env var. Before the fix one specifies key/value pairs as a dictionary:

  environment:
    FOO: BAR
    PASSWORD: xxxxx

After the fix the value of 'environment' key is directly passed to k8s, which allows for:

  environment:
    - name: FOO
      value: BAR
    - name: PASSWORD
      valueFrom:
        secretKeyRef:
          name: my-secret
          value: my-password
andresmgot commented 7 years ago

This will require a better handling if we want to maintain backwards compatibility:

     if (env) {
        container.env = [];
        if (_.isPlainObject(env)) {
           ... Previous approach
        } else if (_.isArray(env) {
            container.env = _.cloneDeep(env) 
        } else {
            throw error for unknown format
        }

It will also need a unit test to ensure that the behavior is what we expect. Check the existing test "should deploy a function with environment variables" (in ./test/kubelessDeploy.test.js) and create a similar one in which the environment variable is an array like in your example.

Let me know if you find any issue with that.

ccll commented 7 years ago

Oops! Backward compatibility and test case is added, and npm lint, npm test, travis build all passes now.