Search code examples
skaffold

Is it possible to patch port forwards in a Skaffold profile


I have a port forward definition in my skaffold.yaml and I want to add another port forward if a profile is enabled. For some reason, the port forward definition provided by the profile overrides already existing port forwards instead of adding to them.

Here’s how my definition looks like:

...
profiles:
  - name: port6000
    patches:
      - op: add
        path: /portForward
        value:
          - resourceType: service
            resourceName: service6000
            namespace: default
            port: 6000
            localPort: 6001
...
portForward:
  - resourceType: service
    resourceName: service5800
    namespace: default
    port: 5800
    localPort: 5801

The problem is that when the port6000 profile is enabled port 5800 is not forwarded but port 6000 only.

Is there something wrong with this definition? When I change path to /portForward/- I’m getting line 24: cannot unmarshal !!seq into latest.PortForwardResource error. Is it possible to patch port forward definitions in profiles?


Solution

  • I got help from the Skaffold community at #skaffold channel on the Kubernetes Slack. Posting it here in case someone will face the same issue as I did.

    Here's the correct patch definition for the portForward node.

    ...
    profiles:
      - name: port6000
        patches:
          - op: add
            path: /portForward/-
            value:
              resourceType: service
              resourceName: service6000
              namespace: default
              port: 6000
              localPort: 6001
    ...
    portForward:
      - resourceType: service
        resourceName: service5800
        namespace: default
        port: 5800
        localPort: 5801
    

    Corrections made:

    1. Set path to /portForward/-
    2. Remove - from the value, it should not be a list but a record