KusionStack / konfig

Shared repository of application models and components, and CI suite for GitOps workflows
Apache License 2.0
27 stars 32 forks source link

Conflicting values on the attribute #17

Closed LeoLiuYan closed 2 years ago

LeoLiuYan commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

konfig/appops/guestbook-frontend/base/main.k

import base.pkg.kusion_models.kube.frontend
import base.pkg.kusion_models.kube.frontend.container
import base.pkg.kusion_models.kube.frontend.container.env as e
import base.pkg.kusion_models.kube.templates.resource as res_tpl

# Application Configuration
appConfiguration: frontend.Server {
    # Main Container Configuration
    mainContainer = container.Main {
        name = "php-redis"
        env: [e.Env {
                name = "GET_HOSTS_FROM"
                value = "dns"
        }]
        ports = [{containerPort = 80}]
    }
    selector = {
        "tier" = "frontend"
    }
    podMetadata.labels: {
        "tier" = "frontend"
    }
    schedulingStrategy.resource = res_tpl.medium
}

konfig/appops/guestbook-frontend/test/main.k

import base.pkg.kusion_models.kube.frontend
import base.pkg.kusion_models.kube.frontend.container
import base.pkg.kusion_models.kube.frontend.container.env as e
import base.pkg.kusion_models.kube.templates.resource as res_tpl

# the configuration with the same attribute in base.
appConfiguration: frontend.Server {
    image = "gcr.io/google-samples/gb-frontend:v4-test"
    schedulingStrategy.resource = res_tpl.tiny

    mainContainer = container.Main {
      env: [e.Env {
          name: "TEST"
          value: "test"
      }]
    }
}

2. What did you expect to see? (Required)

Kusion compile success.

3. What did you see instead (Required)

13 |      env: [e.Env { -> Failure
      conflicting values on the attribute 'name' between {'__settings__': {'output_type': 'INLINE', '__schema_name__': 'Env', '__schema_type__': 'base.pkg.kusion_models.kube.frontend.container.env.Env', '__pkg_path__': 'base.pkg.kusion_models.kube.frontend.container.env'}, 'name': 'GET_HOSTS_FROM', 'value': 'dns', 'valueFrom': Undefined} and {'__settings__': {'output_type': 'INLINE', '__schema_name__': 'Env', '__schema_type__': 'base.pkg.kusion_models.kube.frontend.container.env.Env', '__pkg_path__': 'base.pkg.kusion_models.kube.frontend.container.env'}, 'name': 'TEST', 'value': 'test', 'valueFrom': Undefined}

4. What is your KusionStack components version? (Required)

releaseVersion: v0.5.3
gitInfo:
    latestTag: v0.5.3
    commit: 7611976b68b1a5124e801a18a94072222ea88851
    treeState: clean
buildInfo:
    goVersion: go1.17.12
    GOOS: linux
    GOARCH: amd64
    numCPU: 2
    compiler: gc
    buildTime: "2022-08-05 09:10:29"
dependency:
    kclvmgoVersion: v0.4.3-alpha.1
    kclPluginVersion: v0.4.1-alpha2
Peefy commented 2 years ago

U can write code as follows:

import base.pkg.kusion_models.kube.frontend

# The application configuration in stack will overwrite 
# the configuration with the same attribute in base.
appConfiguration: frontend.Server {
    image = "gcr.io/google-samples/gb-frontend:v4-test"
    schedulingStrategy.resource = res_tpl.tiny

    mainContainer: container.Main {
      env: [{
          name = "TEST"
          value = "test"
      }]
    }
}

Please note that mainContainer and env use : operator; name and value use = operator

Peefy commented 2 years ago

If U want to append more envs, U can write code as follows (use += operator):

import base.pkg.kusion_models.kube.frontend

# The application configuration in stack will overwrite 
# the configuration with the same attribute in base.
appConfiguration: frontend.Server {
    image = "gcr.io/google-samples/gb-frontend:v4-test"
    schedulingStrategy.resource = res_tpl.tiny

    mainContainer: container.Main {
      env += [{
          name = "TEST"
          value = "test"
      }]
    }
}
Peefy commented 2 years ago

More documents: https://kusionstack.io/docs/reference/lang/lang/tour#%E9%85%8D%E7%BD%AE%E6%93%8D%E4%BD%9C

LeoLiuYan commented 2 years ago

@Peefy THX