Skip to content

kctrl: add flags to run package repository release non-interactively - #1894

Closed
officialasishkumar wants to merge 1 commit into
carvel-dev:developfrom
officialasishkumar:kctrl-pkgrepo-release-flags
Closed

officialasishkumar wants to merge 1 commit into
carvel-dev:developfrom
officialasishkumar:kctrl-pkgrepo-release-flags

Conversation

@officialasishkumar

Copy link
Copy Markdown

What this PR does / why we need it:

kctrl package repository release always asks for the repository name and the registry URL, which makes it awkward to use in CI. This adds two flags:

kctrl package repository release --version 1.0.0 \
  --name my-repo.example.com \
  --registry-url registry.example.com/my-repo
  • A value given through a flag takes precedence over pkgrepo-build.yml and skips its prompt. The value is still saved to pkgrepo-build.yml, as a prompt answer is.
  • A value not given is still asked for, so existing interactive use does not change. --yes still accepts the defaults for anything left out.
  • An empty registry URL now fails straight away with expected registry URL to be specified (hint: use --registry-url flag). Previously --yes with no URL wrote a pkgrepo-build.yml with no image, then failed in imgpkg on an image reference of :<tag>.

The prompts moved into configureBasicInformation, so that this logic can be unit tested without kbld or imgpkg.

Which issue(s) this PR fixes:

Fixes #1276

Does this PR introduce a user-facing change?

kctrl package repository release has new --name and --registry-url flags, so it can run without prompts. An empty registry URL now fails early with a clear error.

Additional Notes for your reviewer:

The issue also suggested the short forms -n and -u. I left them out because -n means namespace across the other kctrl commands. They are easy to add if you would prefer them.

Testing:

  • New unit tests in release_test.go cover flags only, prompts only, a mix of the two, and the empty registry URL.
  • New e2e test TestPackageRepositoryReleaseNonInteractively runs with no --yes and no stdin, so any prompt would fail it. It passes against a local registry:2 with real kbld and imgpkg, and fails on a binary without this change.
  • By hand with the built binary: answering the prompts on stdin, only --registry-url with --yes, flags overriding an existing pkgrepo-build.yml, and a blank registry answer.

Not run: TestPackageRepositoryReleaseInteractively, because it needs a cluster and I did not have one available. I checked the same prompt flow by hand as listed above.

Review Checklist:
  • Follows the developer guidelines
  • Relevant tests are added or updated
  • Relevant docs in this repo added or updated (not applicable)
  • Relevant carvel.dev docs added or updated in a separate PR and there's
    a link to that PR (not done; the new flags appear in --help)
  • Code is at least as readable and maintainable as it was before this
    change

Additional documentation e.g., Proposal, usage docs, etc.:


kctrl package repository release always asks for the repository name and
the registry URL, so a CI job has to feed answers on stdin or commit a
pkgrepo-build.yml up front. With --yes and no existing file, the empty
registry URL default was accepted and the command only failed later, when
imgpkg was given an image reference of ":<tag>", having already written a
pkgrepo-build.yml with no image.

Add --name and --registry-url. A value given through a flag takes
precedence over pkgrepo-build.yml and skips its prompt. Values not given
are still asked for, so existing interactive use does not change.

Also fail early with a clear error when the registry URL ends up empty,
before anything is written to disk.

Fixes carvel-dev#1276

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

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

Allow package repository release to be used non-interactively

1 participant