Add --layer-index and --layer-type flags to pull artifact - #5886
Add --layer-index and --layer-type flags to pull artifact#5886ruslan-shaydullin wants to merge 2 commits into
--layer-index and --layer-type flags to pull artifact#5886Conversation
The flux pull artifact command currently extracts only the first layer of the OCI manifest, which prevents pulling arbitrary layers from OCI artifacts not created by flux. The underlying oci.Client.Pull already accepts a WithPullLayerIndex option but it was not exposed to the CLI. Add a --layer-index int flag (default -1, meaning unset) wired through to oci.WithPullLayerIndex when set. The default flow is unchanged. Signed-off-by: Ruslan Shaydullin <shaydullin.r.d@outlook.com> Assisted-by: claude-code/claude-opus-4-7
|
This PR is adding |
I picked If you'd prefer the issue wording: rename to |
|
Hey @matheuscscp — circling back on this. Any leaning between the three? Keeping |
|
The original issue suggested using https://github.com/fluxcd/pkg/blob/5a7f3ce0de742b6c561a50f90940d81cf6fc698d/oci/pull.go#L50 |
|
Maybe add both since there's both in the library? |
The oci.Client.Pull option WithPullLayerType controls how the selected layer is extracted: 'tarball' untars it to a directory, 'static' copies the blob to a file, and when unset the type is detected from the layer content. Expose it as a --layer-type flag on flux pull artifact, complementing --layer-index which selects the layer to extract. Since a static layer is written to a single file, --output is validated as a file path with an existing parent directory when --layer-type=static, instead of requiring an existing directory. Signed-off-by: Ruslan Shaydullin <shaydullin.r.d@outlook.com> Assisted-by: claude-code/claude-fable-5
|
Took another look at I've pushed a commit adding |
--layer-index and --layer-type flags to pull artifact
|
@stratch1989 Can you pls share a bit how your real-world use case looks like? |
|
Candid answer: this didn't come out of an incident on my end. I picked up #4243 from the backlog because it had two things going for it — a maintainer-endorsed design sketch, and a prior attempt (#4790) that died of inactivity rather than because anyone rejected the idea. The use case I'm building for is the one @errordeveloper laid out in the issue: parity between what One thing worth flagging while we're here: |
|
Let's keep this open until we have a use case. |
Closes #4243
What
Adds
--layer-index <int>toflux pull artifact. When set, theunderlying
oci.Client.Pullis called withWithPullLayerIndex(n)sothe chosen layer is extracted instead of the default first layer. Lets
users pull arbitrary layers from OCI artifacts that were not produced
by flux.
Per review feedback, also adds
--layer-type <tarball|static>exposingWithPullLayerType. The two are orthogonal:--layer-indexselectswhich layer to pull,
--layer-typeoverrides how it is extracted —tarballuntars it to the output directory,staticcopies the blobto the output file. With
--layer-type=staticthe--outputpath isvalidated as a file path (existing parent directory) instead of an
existing directory.
Compatibility
Default flow is unchanged — without
--layer-indexthe command behavesexactly as before (extracts the first layer with
layerIndex: 0inoci.Client.Pull). Without--layer-typethe extraction mode isauto-detected from the layer content, as before.
Precedent
This continues the work from PR #4790 (closed without merge after
21 months of inactivity — no review feedback on the thread, likely
stale-bot closure). That PR no longer applies cleanly because of
unrelated refactors in
pull_artifact.go, so this is rewritten fromscratch using the same flag name.
Tests
The new
internal/flags.LayerTypeflag type has a table test followingthe existing
internal/flagsconvention. No existingpull_artifact_test.goin the repo; the CLI wiring itself follows theexisting pull_artifact precedent of no test file. Happy to add coverage
if maintainers prefer.
Local testing notes
On Apple Silicon the Makefile's
setup-envtest use latest --arch=amd64step fails (
bad CPU type in executable). Ran envtest manually with--arch=arm64andKUBEBUILDER_ASSETSpointed at the arm64 dir; thefull
cmd/flux/...test suite passes. CI on linux/amd64 should beunaffected.