Skip to content

Redefine the coreCommands concept #2425

@pPrecel

Description

@pPrecel

Description:

We should redefine this concept because the coreCommands field seems to be not well designed. Thoughts:

  • actionID should be only the ID of an execution of a command
  • command name, description, descriptionLong should be defined in the configmap
  • action should be fully configured from the configmap

Actual solution example:

coreCommands: |
  - actionID: registry_config
    config: ...
  - actionID: registry_image-import
    config: ...

My propossition:

actionCommands: |
  - name: internal-config
    description: Saves Kyma registry internal connection dockerconfig to a file
    descriptionLong: Use this command to save Kyma registry internal connection dockerconfig to a file.
    action:
      functionID: registry_config
      customFlags:
      - name: pull-address
        path: ".pullAddrOnly"
        type: bool
        description: "Print pull address of the Kyma registry only"
        default: false
      - name: push-address
        path: ".pushAddrOnly"
        type: bool
        description: "Print push address of the Kyma registry only"
        default: false
      - name: output
        path: ".output"
        type: path
        description: "Path where the output file should be saved to. NOTE: docker expects the file to be named `config.json`"
        default: "."
      config:
        # name of the field in the status that contains fields like pullAddress, pushAddress, secretName
        statusSource: "internalAccess" 
        # output <- should be set by flag
        # pullAddrOnly <- should be set by flag
        # pushAddrOnly <- should be set by flag
  - name: external-config
    description: Saves Kyma registry external connection dockerconfig to a file
    descriptionLong: Use this command to save Kyma registry external connection dockerconfig to a file.
    action:
      functionID: registry_config
      customFlags:
      - name: pull-address
        path: ".pullAddrOnly"
        type: bool
        description: "Print pull address of the Kyma registry only"
        default: false
      - name: push-address
        path: ".pushAddrOnly"
        type: bool
        description: "Print push address of the Kyma registry only"
        default: false
      - name: output
        path: ".output"
        type: path
        description: "Path where the output file should be saved to. NOTE: docker expects the file to be named `config.json`"
        default: "."
      config:
        # name of the field in the status that contains fields like pullAddress, pushAddress, secretName
        statusSource: "externalAccess"
        # output <- should be set by flag
        # pullAddrOnly <- should be set by flag
        # pushAddrOnly <- should be set by flag
  - name: image-import
    description: Import image to in-cluster registry
    descriptionLong: Import image from daemon to in-cluster registry.
    action:
      functionID: registry_image-import

NOTE: this allows us to use the same actionID to configure two different sub-commands (internal-config and external-config)

For serverless:

old:

coreCommands: |
    - actionID: function_init
      config:
        defaultRuntime: nodejs22
        runtimes:
          python312:
            depsFilename: requirements.txt
            depsData: ""
            handlerFilename: handler.py
            handlerData: |
              def main(event, context):
                message = "Hello World from the Kyma Function "+context['function-name']+" running on "+context['runtime']+ "!";
                print(message)
                return message
          nodejs22:
            depsFilename: package.json
            depsData: |
              {
                "dependencies": {}
              }
            handlerFilename: handler.js
            handlerData: |
              module.exports = {
                main: async function (event, context) {
                  /*
                  If you prefer mjs import/export syntax over cjs you need to specify
                  'type': 'module'
                  in the Function dependencies (package.json) and along with that change the import/export syntax to:
                  import foo from 'foo'
                  export function main(event, context) {
                    //your logic using foo library
                    return
                  }
                  */

                  const message = `Hello World`
                    + ` from the Kyma Function ${context["function-name"]}`
                    + ` running on ${context.runtime}!`;
                  console.log(message);
                  return message;
                }
              }
          nodejs20:
            depsFilename: package.json
            depsData: |
              {
                "dependencies": {}
              }
            handlerFilename: handler.js
            handlerData: |
              module.exports = {
                main: async function (event, context) {
                  /*
                  If you prefer mjs import/export syntax over cjs you need to specify
                  'type': 'module'
                  in the Function dependencies (package.json) and along with that change the import/export syntax to:
                  import foo from 'foo'
                  export function main(event, context) {
                    //your logic using foo library
                    return
                  }
                  */

                  const message = `Hello World`
                    + ` from the Kyma Function ${context["function-name"]}`
                    + ` running on ${context.runtime}!`;
                  console.log(message);
                  return message;
                }
              }

new:

actionCommands: |
  - name: init
    description: Init source and dependencies files locally
    descriptionLong: Use this command to initialize source and dependencies files for a Function.
    action:
      functionID: function_init
      customFlags:
        - name: runtime
          path: ".useRuntime"
          type: string
          description: "Runtime for which the files are generated [ nodejs22, nodejs20, python312 ]"
          default: "nodejs22"
        - name: dir
          path: ".outputDir"
          type: path
          description: "Path to the directory where files must be created"
          default: "."
      config:
        # useRuntime <- set from flag
        # outputDir <- set from flag
        runtimes:
          ...

Changes:

  • rename coreCommands to actionCommands
  • keep descriptions and cmd name in config
  • config is the only input for action run
  • config can be updated by custom flags

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions