Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem when adding an element on the index 0 of a list #40

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/publish-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ jobs:
make pkg
mv ./dist/main ./generic-k8s-webhook-linux-${{github.ref_name}}

- name: Publish package
uses: softprops/action-gh-release@v2
with:
files: generic-k8s-webhook-linux-${{github.ref_name}}
# FIXME Uncomment this once we enable softprops/action-gh-release@v2
# - name: Publish package
# uses: softprops/action-gh-release@v2
# with:
# files: generic-k8s-webhook-linux-${{github.ref_name}}

build-and-publish-to-ghcr:
# Explicitly grant the `secrets.GITHUB_TOKEN` permissions.
Expand Down
2 changes: 1 addition & 1 deletion generic_k8s_webhook/jsonpatch_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def generate_patch(self, contexts: list[Union[list, dict]], prefix: list[str] =
# The rest of non-existing keys must be part of the "values"
items_to_create = self.path[len(new_path) :]
for key in reversed(items_to_create):
if key == "-":
if key in ["-", "0"]:
new_value = [new_value]
else:
new_value = {key: new_value}
Expand Down
8 changes: 8 additions & 0 deletions tests/jsonpatch_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ test_suites:
payload: { spec: {}, metadata: {} }
expected_result:
{ spec: { containers: [{ name: main }] }, metadata: {} }
# Add an element to a non-existing list
- patch:
op: add
path: .spec.containers.0
value: { name: main }
payload: { spec: {}, metadata: {} }
expected_result:
{ spec: { containers: [{ name: main }] }, metadata: {} }
# Add a new entry on the second element of the list
- patch:
op: add
Expand Down
Loading