Skip to content

Proposal - Parameter references  #477

@dhiguero

Description

@dhiguero

Hi all! Following the conversations from the last community call, this issue is a proposal to introduce a mechanism to be able to reference items of the application structure from the component parametrization section.

Motivation

Up to this point, setting parameters on an application requires the user to fill the collection of key:value pairs that will be applied when the actual application is being "instanciated" by the runtime. While this approach works from the point of view of a user for simple cases, it introduces a problem when trying to create tooling around the usage of applications. For example, consider use cases where users want to deploy several instances of the same application.

To illustrate the current state and the proposed changes, consider a simple application with two components where "publicapi" requires a parameter to be able to connect to the "database" one. The current approach is to create a parameter and set that parameter manually as in the following example:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: two-component-app
...
spec:
  components:
    - name: publicapi
      type: internal-api
      properties: # properties targeting component parameters.
        debug: "false"
        dbhost: "database" # dbhost will be used internally to build the database connection string
    - name: database
      type: mysql # assume a mysql component as database

While this approach works for some use cases, it could be improved to improve the usability of the Application entity as describe in the following paragraphs.

Proposal

The proposal is to introduce a method by which a parameter can reference a value of the Application entity. Given the current spec, the initial proposal is to use special syntax to distinguish between referencing parameters and literal ones. Taken inspiration from the component parameter definition section, it could look like:

    - name: publicapi
      type: internal-api
      properties: # properties targeting component parameters.
        debug: "false"
        dbhost: valueRef.spec.components[1].name # use the name attribute the database component

In this case, if a parameter starts with valueRef the runtime understands that this value needs to interpreted instead of being a literal one. To improve usability further, we could also propose other syntax such as the following one, where the name of the component is used to easily identify the target component.

    - name: publicapi
      type: internal-api
      properties: # properties targeting component parameters.
        debug: "false"
        dbhost: valueRef.spec.components["database"].name # use the name attribute the database component

Benefits

This proposal is an enabler of future improvements around OAM, its runtimes, and the tools around it. To highlight some of the main benefits:

  • Facilitate parametrization from tools: From the point of view of creating tools around OAM, introducing a method to be able to understand that a parameter references another element of the application will simplify its design increasing their capabilities. In this way, it would be possible to parse an application entity and determine upfront that it contain errors without the need of deploying it. Without it, there is not enough context to determine if a parameter value is a reference to other component or just a literal value.
  • Creating instances: Some use cases will benefit from future improvements around being able to deploy several instances of an application. To do that, having a robust parameter system where services names can be distinguished from standard parameters will help simplifying the future design.
  • Reducing parametrization: In applications where multiple components require a specific parameter (e.g., database, configuration option, etc), this approach will allow setting just one of those parameters and referencing it from the other components. By following this approach, we can also reduce the errors in cases where the user mistypes some parameter in one of the components.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions