Repository navigation
fix(profiles): allow patches to add into empty maps and lists - #10195
Open
bhargavikvmpl-2001 wants to merge 2 commits into
Open
bhargavikvmpl-2001 wants to merge 2 commits into
bhargavikvmpl-2001 wants to merge 2 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
applyProfile re-marshals the parsed config before applying JSON patches.
Because fields such as docker.buildArgs and helm.releases are omitempty,
an empty collection the user declared (`buildArgs: {}`, `releases: []`)
was dropped from the document, so an `add` into it failed with
"invalid path".
Marshal the config for patching so that empty but non-nil maps and
slices are kept. nil collections are still omitted, so output for
configs without explicit empty collections is unchanged.
Fixes GoogleContainerTools#5766
Fixes GoogleContainerTools#8637
bhargavikvmpl-2001
force-pushed
the
fix/profile-patch-add-into-empty-collections
branch
from
September 29, 2026 22:03
2dd4df3 to
e8ae4c0
Compare
Author
|
Hi maintainers, could someone approve the workflow runs for this PR? As a first-time contributor, the unit, integration and lint workflows are waiting for approval. Locally, the unit tests ( |
Allow 2026 in the boilerplate year check so new files with a 2026 copyright header pass hack/boilerplate.sh, and use reflect.Pointer instead of the deprecated reflect.Ptr alias flagged by govet.
bhargavikvmpl-2001
force-pushed
the
fix/profile-patch-add-into-empty-collections
branch
from
October 4, 2026 23:16
a891460 to
a288034
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #5766
Fixes: #8637
Description
applyProfilere-marshals the parsedSkaffoldConfigto YAML before applying profile patches. Fields such asdocker.buildArgsandhelm.releasesareomitempty, so an empty collection the user declared (buildArgs: {},releases: []) is dropped from that document. Anaddinto it then fails withinvalid path, because the parent no longer exists. Theyaml-patchlibrary itself handlesaddcorrectly; the parent is just missing by the time it runs.This PR adds
marshalForPatching, which encodes the config to ayaml.Nodeand then walks the struct alongside the node tree to restore maps and slices that are empty but non-nil. A YAML{}/[]decodes to a non-nil empty value, while an unset field staysnil, so only collections the user actually wrote come back. Types with a customMarshalYAMLare left alone.A note on the approach: in my comment on #5766 I suggested patching the original YAML node. That doesn't work, because profile fields are overlaid onto the struct before patches run, and older configs are upgraded first. Keeping user-declared empty collections gets the same result without those problems.
User facing changes
Before: with
buildArgs: {}(orreleases: []),op: addto/build/artifacts/0/docker/buildArgs/profile(or/deploy/helm/releases/-) fails withinvalid path.After: the patch applies, including when several profiles each add into the same empty collection.
A bare
buildArgs:(YAML null) still has no parent to add into, consistent with RFC 6902;buildArgs: {}is the way to declare an empty map.Testing
TestApplyPatchIntoEmptyCollectionscovers both issues, including two profiles adding into the same emptybuildArgs. It fails onmainwith the error from Patches operation 'add' cannot add new keys as show in the JsonPatch example #5766 and passes with this change.TestMarshalForPatchingchecks that nil collections are still omitted, an empty map is kept, and an empty slice inside an otherwise empty struct is kept.integration/examplesandintegration/testdatathat parse at the latest schema,marshalForPatchingoutput is byte-identical toyaml.Marshal.go test ./pkg/skaffold/schema/... ./pkg/skaffold/parser/...,go vetandgofmtpass.