acorn-io / runtime

A simple application deployment framework built on Kubernetes
https://docs.acorn.io/
Apache License 2.0
1.14k stars 102 forks source link

Not able to deploy apps with containers having env variable names with "." #2442

Closed sangee2004 closed 5 months ago

sangee2004 commented 5 months ago

acorn version - v0.10.0-rc5+e2b69a6d

Steps to reproduce the problem:

Scenario 1:

1.Deploy app with containers that have env names with "." in them

secrets: config: {
    type: "credential.acorn.io/mytestcred"
    params: {
        promptOrder: ["username", "password"]
    }
    data: {
        username:      "xyz"
        password:      ""
    }
}
containers: {
    mytest: {
        image: "nginx"
        env:{
           "username.test": "secret://config/username"
           "password.paa": "secret://config/password"
    }
}
}

App deployment fails with following error:

NAME         IMAGE          COMMIT    CREATED   ENDPOINTS                                               MESSAGE
mytestcred   cef99faebfc4             12m ago                                                           (container: mytest): pending; failed to create mytestcred-acorn-430e6f08/mytest apps/v1, Kind=Deployment for subcontext [acorn-controller] namespace [acorn] name [mytestcred]: Deployment.apps "mytest" is invalid: [spec.template.spec.containers[0].env[0].name: Invalid value: "password\\.paa": a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name',  or 'MY_ENV.NAME',  or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*'), spec.template.spec.containers[0].env[1].name: Invalid value: "username\\.test": a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name',  or 'MY_ENV.NAME',  or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')]

Scenario 2 :

  1. Deploy app with containers that have env names with "."
    args: {
    newtext: "hello2"
    number:  1
    decimal: 1.1
    }
    containers: {
    mywebnew: {
        name:  "testweb1"
        image: "nginx"
        scale: 1
        ports: publish: "80/http"
        files: {
            "/usr/share/nginx/html/index.html": args.newtext
            "/usr/share/nginx/html/test.html":  "modified"
            "/usr/share/nginx/html/test1.html": "\(args.decimal)"
            "/usr/share/nginx/html/test2.html": "new1"
        }
        env:
        {
            "test1.val": "hello"
            "test2.kk":  "hellokk"
            tt:          "ss"
        }
    }
    }
  2. Once app is deployed , i see only tt environment variable being set.
iwilltry42 commented 5 months ago

Tested the fix with both your examples and added related Unit tests - should be all good now :+1:

sangee2004 commented 5 months ago

@iwilltry42 I still dont see the env variables with "." getting set in the containers. But i dont see the deployment error I used to see earlier for scenario1

Tested with acorn version v0.10.1-rc1-8-gce008aeb+ce008aeb

Scenario 1:

1.Deploy app with containers that have env names with "." in them

secrets: config: { type: "credential.acorn.io/mytestcred" params: { promptOrder: ["username", "password"] } data: { username: "xyz" password: "" } } containers: { mytest: { image: "nginx" env:{ "username.test": "secret://config/username" "password.paa": "secret://config/password" } } }

App deployment succeeds but I dont see the environment variables username.test and password.paa being set for the container.

Scenario 2:

  1. Deploy app with containers that have env names with "."
    args: {
    newtext: "hello2"
    number:  1
    decimal: 1.1
    }
    containers: {
    mywebnew: {
        name:  "testweb1"
        image: "nginx"
        scale: 1
        ports: publish: "80/http"
        files: {
            "/usr/share/nginx/html/index.html": args.newtext
            "/usr/share/nginx/html/test.html":  "modified"
            "/usr/share/nginx/html/test1.html": "\(args.decimal)"
            "/usr/share/nginx/html/test2.html": "new1"
        }
        env:
        {
            "test1.val": "hello"
            "test2.kk":  "hellokk"
            tt:          "ss"
        }
    }
    }

Once app is deployed , i see only tt environment variable being set.

sangee2004 commented 5 months ago

Pod definition in this case includes the env variables as expected. It is not getting listed when querying for it from within the container using env command in this case.

Pod spec for scenario 1 and scenario2 from https://github.com/acorn-io/runtime/issues/2442#issuecomment-1906979405 showing the env varaibles set as expected.

scenario 1:

               "containers": [
                    {
                        "env": [
                            {
                                "name": "password.paa",
                                "valueFrom": {
                                    "secretKeyRef": {
                                        "key": "password",
                                        "name": "config"
                                    }
                                }
                            },
                            {
                                "name": "username.test",
                                "valueFrom": {
                                    "secretKeyRef": {
                                        "key": "username",
                                        "name": "config"
                                    }
                                }
                            }
                        ],

scenario 2:

            "spec": {
                "containers": [
                    {
                        "env": [
                            {
                                "name": "test1.val",
                                "value": "hello"
                            },
                            {
                                "name": "test2.kk",
                                "value": "hellokk"
                            },
                            {
                                "name": "tt",
                                "value": "ss"
                            }
                        ],