GoogleContainerTools / GoogleContainerTools/skaffold

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

Open
#5,766 4 comments 3 reactions 0 assignees View on GitHub
has-workaround help wanted kind/bug priority/p3
Dominant language
Go
Stars
15.9k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

### Expected behavior
According to the [patches documentation](https://skaffold.dev/docs/environment/profiles/#override-via-patches), we can use JsonPatches in profiles. According to the [example](http://jsonpatch.com/#simple-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](http://jsonpatch.com/#the-patch))

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`
```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`
```Dockerfile
FROM busybox

COPY . .

ARG build_env=<<>>
RUN echo $build_env

ARG profile=<<>>
RUN echo $profile
```
Run command:
`skaffold build -p load,dev`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.