refactor(shim): unify config.json access via PatchConfig#722
Open
mdryaan wants to merge 1 commit into
Open
Conversation
Signed-off-by: Md Raiyan <alikhurshid842001@gmail.com>
✅ Deploy Preview for urunc canceled.
|
Contributor
Author
|
Hello @cmainas, please have look whenever you get a chance |
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.
Description
PRs #565, #657, and #702 each added shim logic that independently opens, reads, and writes
config.json. This resulted in two separate read-unmarshal-marshal-write cycles inside a singleTaskService.Createcall, a non-atomic write inguest_rootfs.go, and the same constant defined in two places.Introduce
PatchConfig(bundlePath, fn)inpkg/containerd-shim/containerd/config.goas the single entry point for allconfig.jsonmutation in the shim. It readsconfig.jsononce, appliesfnto the spec, and writes back atomically.atomicWriteFilemoves fromannotations.gointo this new file.InjectUruncAnnotationsandchooseGuestRootfsboth replace their inline I/O with aPatchConfigclosure.annotRootfsParamsis promoted tointernal/constants.AnnotRootfsParamsand the duplicate local declarations are removed.Related issues
How was this tested?
Changed files:
internal/constants/constants.go— addedAnnotRootfsParamspkg/containerd-shim/containerd/config.go— new file withPatchConfigandatomicWriteFilepkg/containerd-shim/containerd/annotations.go— removedpatchConfigJSONandatomicWriteFile,InjectUruncAnnotationsnow calls
PatchConfigpkg/containerd-shim/guest_rootfs.go— removed inline I/O andlocal constant,
chooseGuestRootfsnow callsPatchConfigpkg/unikontainers/rootfs.go— removed duplicate constantpkg/unikontainers/unikontainers.go— usesconstants.AnnotRootfsParamsVerified by code inspection that every
config.jsonopen/read/write in the shim now routes throughPatchConfig, the non atomic write inchooseGuestRootfsis replaced by the atomic write path, and the duplicate constant is eliminated. Build passes (make). Linter passes (golangci-lint run). Unit tests pass (go test ./pkg/unikontainers/...).LLM usage
N/A
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).