Skip to content

Commit f81225f

Browse files
jordijordipiqueselles
jordi
authored andcommitted
Fix problem when adding an element on the index 0 of a list
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".
1 parent 9933ef8 commit f81225f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.github/workflows/publish-artifacts.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ jobs:
2323
make pkg
2424
mv ./dist/main ./generic-k8s-webhook-linux-${{github.ref_name}}
2525
26-
- name: Publish package
27-
uses: softprops/action-gh-release@v2
28-
with:
29-
files: generic-k8s-webhook-linux-${{github.ref_name}}
26+
# FIXME Uncomment this once we enable softprops/action-gh-release@v2
27+
# - name: Publish package
28+
# uses: softprops/action-gh-release@v2
29+
# with:
30+
# files: generic-k8s-webhook-linux-${{github.ref_name}}
3031

3132
build-and-publish-to-ghcr:
3233
# Explicitly grant the `secrets.GITHUB_TOKEN` permissions.

generic_k8s_webhook/jsonpatch_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def generate_patch(self, contexts: list[Union[list, dict]], prefix: list[str] =
7777
# The rest of non-existing keys must be part of the "values"
7878
items_to_create = self.path[len(new_path) :]
7979
for key in reversed(items_to_create):
80-
if key == "-":
80+
if key in ["-", "0"]:
8181
new_value = [new_value]
8282
else:
8383
new_value = {key: new_value}

tests/jsonpatch_test.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ test_suites:
5959
payload: { spec: {}, metadata: {} }
6060
expected_result:
6161
{ spec: { containers: [{ name: main }] }, metadata: {} }
62+
# Add an element to a non-existing list
63+
- patch:
64+
op: add
65+
path: .spec.containers.0
66+
value: { name: main }
67+
payload: { spec: {}, metadata: {} }
68+
expected_result:
69+
{ spec: { containers: [{ name: main }] }, metadata: {} }
6270
# Add a new entry on the second element of the list
6371
- patch:
6472
op: add

0 commit comments

Comments
 (0)