fix(tiller): ImageRef works in raw dict positions #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "arrdem/imageref-yaml-representer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Make
ImageRefusable anywhere in a manifest — including user-composed dicts likeextra_containers=[{"image": some_ref}]— not just as theimage=kwarg on builder functions.Two commits, one story
tiller.renderYAML representer for ImageRef. ImageRef auto-unwraps fromOpaquePythonObjectat the Starlark→Python boundary, so it reachesyaml.dumpas a raw dataclass. Without a representer PyYAML emits!!python/object:tiller.types.ImageRef, which is invalid k8s YAML. Register_imageref_representerthat emitsstr(imageref)._parse_registryacceptsstr | ImageRef.inject_pull_secretsruns BEFORE render, so commit 1 alone wasn't enough — the transform sees the raw ImageRef insidecontainer["image"]and errors with'ImageRef' object has no attribute 'split'. Coerce to str at entry;ImageRef.__str__yields the canonical form the existing parsing already handles.Motivation
A downstream flowmetal Tillerfile wanted
extra_containers=[_chaos_sidecar(...)]with anImageRef-typedchaos_image. It was forced to type the input as a plainstrto dodge commit 1's YAML bug, which threw away tag/digest semantics. Both halves of this PR together restore "ImageRef just works everywhere."Test plan
tests/test_render.py:test_imageref_in_image_kwarg— baseline.test_imageref_in_extra_container— defect case + explicit!!python/objectabsence assertion.test_imageref_digest— digest form.tests/test_transforms.py:test_imageref_in_extra_container—inject_pull_secretspicks the right registry from a sidecar ImageRef.test_imageref_with_digest— same with a digest.244 tests pass in the full suite (up from 242).
Companion to the render-pipeline ImageRef representer. Before that representer landed, the only way an image value appeared in the manifest was as a string (builders called `str(image)` at their `image=` kwarg). Now that users can put an ImageRef in a raw dict position like `extra_containers=[{"image": some_ref}]`, the `inject_pull_secrets` transform — which reads container image values to pick an appropriate pull secret per registry — sees raw ImageRef instances and errors with `'ImageRef' object has no attribute 'split'`. `_parse_registry` now coerces to str at entry (ImageRef's `__str__` yields the canonical `repo:tag` or `repo@digest` form, which the existing parsing handles correctly). Two new tests in tests/test_transforms.py: - inject_pull_secrets with an ImageRef (tag form) in a sidecar container injects the matching pull secret. - Same with an ImageRef (digest form).