Skip to content

feat(oci): allow host-less repos complemented by the KPM_REG envvar#346

Open
cjuega wants to merge 1 commit into
kcl-lang:mainfrom
cjuega:main
Open

feat(oci): allow host-less repos complemented by the KPM_REG envvar#346
cjuega wants to merge 1 commit into
kcl-lang:mainfrom
cjuega:main

Conversation

@cjuega

@cjuega cjuega commented Jun 26, 2026

Copy link
Copy Markdown

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

2. What is the scope of this PR (e.g. component or file name):

cmd/kcl/commands/args.go, cmd/kcl/commands/mod_add.go, cmd/kcl/commands/args_test.go

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

Allow --oci to accept a bare repository path with no scheme and no host
(e.g. myorg/kcl-templates/utils). When url.Parse returns an empty scheme
the argument is now treated as a host-less reference and an Oci source is
built with RegFromEnv: true, so KPM resolves the registry at runtime from the
KPM_REG environment variable or DefaultOciRegistry.

Previously, the same input would fall into the scheme-rewriting branch, which
prepended oci:// to an already schemeless string and produced a malformed URL.

This is useful for multi-account or air-gapped deployments where the same
kcl.mod must work against different registries without being modified:

export KPM_REG=123456789012.dkr.ecr.eu-west-1.amazonaws.com
kcl mod add --oci myorg/kcl-templates/utils --tag 0.2.0

Full OCI URLs (oci://ghcr.io/..., https://ghcr.io/...) are unaffected.

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

The existing behaviour for fully-qualified OCI URLs is preserved unchanged.
The new code path is only reached when url.Parse returns an empty scheme,
which previously produced a malformed URL and would have errored downstream.

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

Four unit tests added in cmd/kcl/commands/args_test.go:

Test What it covers
TestParseSourceFromArgs_HostlessOci Bare path → RegFromEnv=true, registry empty
TestParseSourceFromArgs_HostnameWithoutScheme ghcr.io/… without scheme → treated as bare path (Go's url.Parse cannot detect a host without ://); documents the edge-case behaviour explicitly
TestParseSourceFromArgs_FullOciUrl Full oci://host/repo URL → Reg populated, RegFromEnv=false (regression guard)
TestParseSourceFromArgs_HostlessOciWithModSpec Positional name:version + host-less --oci → both Oci and ModSpec fields populated correctly

@cjuega

cjuega commented Jun 26, 2026

Copy link
Copy Markdown
Author

Be aware we need the changes in this PR before merging this. So we still have to bump kpm once the aforementioned change is released

Signed-off-by: Carlos Juega <carlosjuegasi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant