Skip to content

Commit

Permalink
Fix problem when adding an element on the index 0 of a list
Browse files Browse the repository at this point in the history
This problem happened when the list doesn't exist on the original yaml.
In this situation, the new element was added as a dictionary of key "0".
Now, with the current fix, the list is properly created and the element
is added as a normal list element.

Apart from that, we've commented the step that pushes the self-contained
package to the release since we need to enable first
"softprops/action-gh-release@v2".
  • Loading branch information
jordi authored and jordipiqueselles committed Jul 23, 2024
1 parent 9933ef8 commit f81225f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

0 comments on commit f81225f

Please sign in to comment.