Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier way of passing parameters to config or env. or output #169

Open
mikkelhegn opened this issue Sep 27, 2019 · 0 comments
Open

Easier way of passing parameters to config or env. or output #169

mikkelhegn opened this issue Sep 27, 2019 · 0 comments
Labels
Milestone

Comments

@mikkelhegn
Copy link
Contributor

Having worked through a bit more complex application configuration file, I ended up repeating a lot of lines in the application configuration to simply pass parameters through to environment variables in a component. I also lacked the ability to describe an object type of variable (e.g. a database connection string, consisting of dbname, servername etc.)

I was lead to how CNAB defined parameters and definitions, and think that we can adopt a slightly simplified version of that concept. This might also help with #1

CNAB: https://github.com/deislabs/cnab-spec/blob/master/101-bundle-json.md#definitions

Benefits:

  • Parameter objects types
  • Directing parameters in app config to env and config directly
  • Parameter boundaries (e.g. min/max for int.)

Example - current model

apiVersion: core.hydra.io/v1alpha1
kind: Component
metadata:
  name: bikesharing.bikes.io/users
  labels:
    app: bikesharing
  annotations:
    version: 1.0.0
    description: WebAPI to control users in the system
spec:
  workloadType: core.hydra.io/v1alpha1.Service
  osType: linux
  parameters:
  - name: sqlUsername
    description: SQL DB username
    type: string
    required: true
    default: SA
  - name: sqlServer
    description: SQL DB server
    type: string
    required: true
  - name: sqlDatabase
    description: SQL DB name
    type: string
    required: true
    default: bikesharing
  - name: sqlTable
    description: DQL table name
    type: string
    required: true
    default: Users
  - name: api_gateway
    description: the API gateway dns name
    type: string
    required: true
  containers:
  - name: users
    image: azdspublic/bikesharing-users:build.20190426.1
    resources:
      cpu: 
        required: 0.1
      memory: 
        required: 100M
    ports: 
    - name: http-api
      containerPort: 80
      protocol: TCP
    env:
    - name: sql_username
      fromParam: sqlUsername
    - name: env.sql_server
      fromParam: sqlServer
    - name: sql_database
      fromParam: sqlDatabase
    - name: sql_table
      fromParam: sqlTable
    - name: api_gateway
      fromParam: api_gateway
---------
apiVersion: core.hydra.io/v1alpha1
kind: ApplicationConfiguration
metadata:
  name: BikeSharing-deployment
  annotations:
    version: v1.0.0
    description: BikeSharing production deployment
spec:
  variables:
    - name: sqlServerName
      value: sql-database
    - name: sqlServerTable
      value: myTable
  components:
    - componentName: bikesharing.bikes.io/users
      instanceName: users
      parameterValues:
        - name: sqlUsername
          value: "[fromVariable(sqlPassword)]"
        - name: sqlServer
          value: "[fromVariable(sqlServerName)]"
      traits:
        - name: users_scaler
          type: core.hydra.io/v1alpha1.ManualScaler
            properties:
              - name: replicacount
                value:  "[fromVariable(users_replicaCount)]"

Example - new model

apiVersion: core.hydra.io/v1alpha1
kind: Component
metadata:
  name: bikesharing.bikes.io/users
  labels:
    app: bikesharing
  annotations:
    version: 1.0.0
    description: WebAPI to control users in the system
spec:
  workloadType: core.hydra.io/v1alpha1.Service
  osType: linux
  parameters:
  - name: sqlConnectionString
    description: SQL database connectionstring
    type: object
        sqlDatabase: string <--- Object fields
        sqlServer: string
        sqlTable: string
    required: true
    destination:
        env:
            sqlDatabase: sql_database <--- Translates to an env named `sql_database`
            sqlServer: sql_server
            sqlTable: sql_table
  - name: api_gateway
    description: the API gateway dns name
    type: string
    required: true
    destination:
        config: api_gateway <---- Translates to a config named api_gateway
  - name: api_gateway
    description: the API gateway dns name
    type: int
        min: 1 <--- Types can have rules
        max: 5
    required: true
    destination:
        config: api_gateway <---- Translates to a config named api_gateway
        out: api_gateway <---- output from the deployment
  containers:
  - name: users
    image: azdspublic/bikesharing-users:build.20190426.1
    resources:
      cpu: 
        required: 0.1
      memory: 
        required: 100M
    ports: 
    - name: http-api
      containerPort: 80
      protocol: TCP
---------
apiVersion: core.hydra.io/v1alpha1
kind: ApplicationConfiguration
metadata:
  name: BikeSharing-deployment
  annotations:
    version: v1.0.0
    description: BikeSharing production deployment
spec:
  variables:
    - name: sqlConnectionString
      destinations:
        users.sqlConnectionString.sqlDatabase: myDB <--- [instanceName.parameter.objectfield]:[value]
        users.sqlConnectionString.sqlServer: myServer
        users.sqlConnectionString.sqlTable: myTable
    - name: api_gateway
      destinations:
        users.api_gateway: api.gateway <--- [instanceName.parameter]:[value]
    - name users_replicaCount
      value: 1 <--- As today for value substitution in other parts of the component configuration
  components:
    - componentName: bikesharing.bikes.io/users
      instanceName: users
      traits:
        - name: users_scaler
          type: core.hydra.io/v1alpha1.ManualScaler
            properties:
              - name: replicacount
                value:  "[fromVariable(users_replicaCount)]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants