Skip to content

add support for map lists #8

Closed

Description

@thisisibrahimd

at the moment, if you want to edit an item that is in a list, you need to map it and create a one time helper for that specific key. for example, if you want to edit an env in a env list for a container you need to add the key additive keys before it, then do looping with an if statement to modify it.

local deployment = {
  apiVersion: 'apps/v1',
  kind: 'Deployment',
  metadata: {
    name: 'my-app',
  },
  spec: {
    template: {
      spec: {
        containers: [
          {
            name: 'app',
            image: 'my-app:v1',
            env: [],
          },
          {
            name: 'sidecar',
            image: 'sidecar:v1',
          },
        ],
      },
    },
  },
};

deployment + {
  spec+: {
    template+: {
      spec+: {
        containers: [
          if c.name == 'app'
          then c + {
            image: 'my-app:v2',
            env+: [
              {
                name: 'LOG_LEVEL',
                value: 'debug',
              },
            ],
          }
          else c
          for c in super.containers
        ],
      },
    },
  },
}

a one time function can be created like below but I would like this to be available as a helper for all list type in this generator.

local updateContainer(containers, containerName, changes) =
  [
    if container.name == containerName
    then container + changes
    else container
    for container in containers
  ];

deployment + {
  spec+: {
    template+: {
      spec+: {
        containers: updateContainer(
          super.containers,
          'app',
          {
            image: 'my-app:v2',
            ports+: [
              {
                containerPort: 9090,
              },
            ],
          }
        ),
      },
    },
  },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions