Merging Commands

Commands with the same name are merged by the Admin Service, such as in the following scenarios:

  • A command is registered with an AdminCommandDiscoveryEndpoint custom resource (CR) and cannot be modified outside of the application.
  • A command is registered with an AdminCommand CR from a Helm chart so modifications are overwritten by the next helm upgrade command.

Merge priority is determined by the mergePriority command attribute. The higher this value, the higher the priority that is given to the fields it defines.

The following scenarios show use of the merging capabilities.

Fixing a Command

The following command definition has an error. The resource selector uses a label simple instead of sample.

command:
  name: sample
  description: Sample Command
  resourceSelector:
    kind: pods
    labels:
      app: simple
  executor:
    executeOnPod:
      command:
        - "bin/bash"
        - "-c"
        - "simple.sh"

To correct this, create a new AdminCommand CR that has the same name as the existing command but with a higher mergePriority value and a definition of a corrected resource selector:

apiVersion: matrixx.matrixx.com/v1
kind: AdminCommand
metadata:
  name: sample-command-fix
spec:
  command:
    name: sample
    description: 
  mergePriority: 100
  resourceSelector:
    kind: pods
    labels:
      app: sample
Note: The entire resource selector is redefined because the merge replaces the entire structure. This is also true of restriction and executor sections.

The merged command is equivalent to the following:

command:
  name: sample
  description: Sample Command
  resourceSelector:
    kind: pods
    labels:
      app: sample
  executor:
    executeOnPod:
      command:
        - "bin/bash"
        - "-c"
        - "simple.sh"

Extending a Command

You can extend an existing command with a sub-command:

command:
  name: user
  description: User Commands
resourceSelector:
  kind: services
  labels:
    app: user-service
subCommands:
  - command:
      name: add
      description: Add User
    executor:
      httpEndpoint:
        url: url: http://${resource.name}.${resource.namespace}/api/user
        method: put

To add a new user delete command, create a new AdminCommand CR that has the same name as the existing command but with a higher mergePriority value and a definition of a new sub-command:

apiVersion: matrixx.matrixx.com/v1
kind: AdminCommand
metadata:
  name: user-delete
spec:
  command:
    name: user
    description: 
  mergePriority: 100
  subCommands:
  - command:
      name: delete
      description: delete User
    executor:
      httpEndpoint:
        url: url: http://${resource.name}.${resource.namespace}/api/user
        method: delete

The merged command is equivalent to the following:

command:
  name: user
  description: User Commands
resourceSelector:
  kind: services
  labels:
    app: user-service
subCommands:
  - command:
      name: add
      description: Add User
    executor:
      httpEndpoint:
        url: url: http://${resource.name}.${resource.namespace}/api/user
        method: put
  - command:
      name: delete
      description: Delete User
    executor:
      httpEndpoint:
        url: url: http://${resource.name}.${resource.namespace}/api/user
        method: delete