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

feat(patch): allow arrays to be specified on the CLI #1056

Merged
merged 1 commit into from
Oct 27, 2023
Merged
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
23 changes: 15 additions & 8 deletions cmd/file_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{
var err error
valuesPatch.SelectorSources = cmdPatchSelectors
valuesPatch.ObjValues, valuesPatch.Remove, err = patch.ValidateValuesFlags(cmdPatchValues)
valuesPatch.ObjValues, valuesPatch.Remove, valuesPatch.ArrValues, err = patch.ValidateValuesFlags(cmdPatchValues)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:1.5.0.11)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.2.1.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.5.1.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.1.4.6)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway-dev:latest)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.6.0.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.8)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:3.0)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values) (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values) (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values) (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.8)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.0.5)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.1.4)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong:master-alpine)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.5.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.0)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.3.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:1.5.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.4.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:1.4.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.2.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values
if err != nil {
return fmt.Errorf("failed parsing '--value' entry; %w", err)
}
Expand Down Expand Up @@ -120,21 +120,30 @@
'--value' tags, or via patch files.

When using '--selector' and '--values', the items are selected by the 'selector',
which is a JSONpath query. From the array of nodes found, only the objects are updated.
The 'values' are applied on each of the JSONObjects returned by the 'selector'.
which is a JSONpath query. The 'field values' (in '<key:value>' format) are applied on
each of the JSONObjects returned by the 'selector'. The 'array values' (in
'[val1, val2]' format) are appended to each of the JSONArrays returned by the 'selector'.

Objects:

The value must be a valid JSON snippet, so use single/double quotes
The field values must be a valid JSON snippet, so use single/double quotes
appropriately. If the value is empty, the field is removed from the object.

Examples of valid values:

# set field "read_timeout" to a numeric value of 10000
--selector="$..services[*]" --value="read_timeout:10000"

# set field "_comment" to a string value
--selector="$..services[*]" --value='_comment:"comment injected by patching"'

# set field "_ignore" to an array of strings
--selector="$..services[*]" --value='_ignore:["ignore1","ignore2"]'

# remove fields "_ignore" and "_comment" from the object
--selector="$..services[*]" --value='_ignore:' --value='_comment:'

# append entries to the methods array of all route objects
--selector="$..routes[*].methods" --value='["OPTIONS"]'


Patch files have the following format (JSON or YAML) and can contain multiple
patches that are applied in order:
Expand All @@ -153,8 +162,6 @@
]
}

Arrays:

If the 'values' object instead is an array, then any arrays returned by the selectors
will get the 'values' appended to them.
`,
Expand Down
Loading