GoogleContainerTools/skaffold

Patches operation 'add' cannot add new keys as show in the JsonPatch example

オープン

#5,766 opened on 2021/04/30

 (4 件のコメント) (3 件のリアクション) (0 人の担当者)Go (1,416 件のフォーク)batch import
has-workaroundhelp wantedkind/bugpriority/p3

Repository metrics

Stars
 (12,822 個のスター)
PR merge metrics
 (平均マージ 3d 6h) (30d で 16 merged PRs)

説明

Expected behavior

According to the patches documentation, we can use JsonPatches in profiles. According to the example in the JsonPatch documentation, it should be possible to add new keys to an object by using the add operation, simply by specifying the path to the key and the value I wanted to associate with it.

Actual behavior

Skaffold outputs the following:

parsing skaffold config: 
failed to apply profiles to config "test" defined in file "/Users/gikkman/Development/test-buildargs/skaffold.yaml": 
applying profile "load": invalid path: /build/artifacts/0/docker/buildArgs/profile. 
There's an issue with one of the profiles defined in config "test" in file "/Users/gikkman/Development/test-buildargs/skaffold.yaml"; refer to the documentation on how to author valid profiles: https://skaffold.dev/docs/environment/profiles/.

Motivation

In my case, I want several profiles that add elements to the build.artifacts.0.docker.buildArgs object, so I can utilize multiple profiles to add the necessary buildArgs without having to write out all combinations I plan to use. It is possible to set a key with an empty value under buildArgs for each key I would like to patch, but according to the documentation it should be possible to add entirely new key-value pairs using add by just specifying the path where you would like to add the new key, and supply a value (see the add options in the JsonPatch example)

If this is not intended to be possible, I think the documentation should be updated to reflect that, so the next person don't have to spend as much time to experiment with this as I have :-)

Information

  • Skaffold version: v1.23.0
  • Operating system: macOS Catalina 10.15.7
  • Installed via: Homebrew
  • Contents of skaffold.yaml and Dockerfile:

Files

skaffold.yaml

apiVersion: skaffold/v2alpha3
kind: Config

metadata:
  name: test

build:
  artifacts:
    - image: test-stuff
      docker:
        dockerfile: Dockerfile
        buildArgs:

profiles:
  - name: load
    patches:
      - op: add
        path: /build/artifacts/0/docker/buildArgs/profile
        value: "load"

  - name: dev
    patches:
      - op: add
        path: /build/artifacts/0/docker/buildArgs/build_env
        value: "dev"

Dockerfile

FROM busybox

COPY . .

ARG build_env=<<<NONE>>>
RUN echo $build_env

ARG profile=<<<NONE>>>
RUN echo $profile

Run command: skaffold build -p load,dev

コントリビューターガイド