Skip to content

feat: control all-versions vs latest-only on helm search repo (currently always returns all) #279

@jonathanlukas

Description

@jonathanlukas

Background

Helm CLI's helm search repo returns one row per chart by default (latest version matching the version constraint), and all matching versions when -l, --versions is passed.

helm-java's current behavior is the opposite. native/internal/helm/search.go:72 calls searchIndex.AddRepo(name, index, true) unconditionally — so the index always keeps every version and the output always includes all of them. helm CLI passes all = (--versions || --version set) (search_repo.go:197) — all=false causes the index to retain only the latest per chart.

This issue tracks adding control over the toggle in the Java API.

Decision needed before implementing

Two options for the maintainer — please pick one in this thread:

  • (a) Match helm CLI semantics — default to latest-only; add .versions() to opt into all. Breaking change for existing callers who rely on receiving all versions.
  • (b) Non-breaking — keep current "all versions" as default; add .latestOnly() to opt out. Diverges from helm CLI.

Acceptance criteria

  • Java API exposes a way to toggle between latest-only and all-versions
  • Method name reflects the chosen semantic (above)
  • searchIndex.AddRepo(name, index, allVersions) receives the flag from SearchOptions
  • HelmSearchTest covers both modes against a real repo with multi-version charts

Implementation guide

Tiny change once the semantic decision lands.

Go (native/internal/helm/search.go)

  • Add Versions bool to SearchOptions.
  • Change searchIndex.AddRepo(name, index, true)searchIndex.AddRepo(name, index, options.Versions).

CGO bridge (native/main.go)

  • Add int versions; to struct SearchOptions. Pass through.

JNA (SearchOptions.java)

  • Add public int versions;. Update @Structure.FieldOrder and the constructor.

Java (SearchRepoCommand.java)

  • Add the chosen builder method (versions() or latestOnly()); set the int flag with toInt(true).

Tests

  • Location: existing helm-java/src/test/java/com/marcnuri/helm/HelmSearchTest.java.
  • The current withDefaults test uses https://charts.helm.sh/stable which has many versions per chart.
  • Add: a test asserting result size differs between latest-only and all-versions modes for the same query, e.g.:
    final int latestOnly = Helm.search().repo()./* latest mode */.call().size();
    final int allVersions = Helm.search().repo()./* all-versions mode */.call().size();
    assertThat(allVersions).isGreaterThan(latestOnly);

Contributor checklist

  • Java 8 syntax only
  • Apache 2.0 header
  • @author Javadoc tag
  • DCO sign-off
  • make build-native && ./mvnw test -pl helm-java -Dtest=HelmSearchTest green

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions