Skip to content

Conversation

@Gearheads
Copy link

Summary

This PR is to allow users to provide a custom krew-index repository, in case they do not wish to upload to the public krew-index repository.

The goal is to allow users to provide the custom krew-index repository information through two new parameters:

  • upstream_krew_index_repo_owner
  • upstream_krew_index_repo_name

The GitHub Action will then determine the default branch that is configured for the custom krew-index repository, and create a PR against that default branch. Just in case the custom krew-index repository does not use the master branch.

This is very helpful for organizations that are hosting their own internal krew-index repositories, and allows them to automate their release cycles.

Fixes

#47

Please let me know if there is anything else I might be missing. 😄

//GetKrewIndexRepoName returns the krew-index repo name
func GetKrewIndexRepoName() string {
override := os.Getenv("UPSTREAM_KREW_INDEX_REPO_NAME")
override := os.Getenv("INPUT_UPSTREAM_KREW_INDEX_REPO_NAME")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code actually runs on server side (IIRC), and do not have access to the GitHub inputs. what we will have to do is to accept this input, and then pass along this info to the backend as part of request.

the backend then needs to consider 3 scenarios:

  • The override configured on server side. this should take preference over GitHub action input and defaults, as this helps with testing the server.
  • The override configured as part of GitHub action (if no override provided on server side)
  • The default values. (if no override provided at all)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @rajatjindal, thank you so much for the feedback! I have implemented the changes, and the PR should now be updated.

Please let me know if anything else needs to be changed, or if I am missing anything. 😄

//GetKrewIndexRepoOwner returns the krew-index repo owner
func GetKrewIndexRepoOwner() string {
override := os.Getenv("UPSTREAM_KREW_INDEX_REPO_OWNER")
override := os.Getenv("INPUT_UPSTREAM_KREW_INDEX_REPO_OWNER")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: r.Token})
tc := oauth2.NewClient(context.TODO(), ts)
client := github.NewClient(tc)
client := getGitHubClient(r.Token)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe have a client on Releaser object and just reuse that instead of creating here and in clonerepo function.

also it seems like could needs indentation.

Thank you @rajatjindal for the feeback. I have made a few changes based on that feeback. Some of the updates are listed below:
- updated Releaser object to have a client
- add logic to accept custom krew-index input through GitHub Action
- add logic to pass input to the backend server as part of the request
- add precedence for krew-index values with server side override having highest priority
- ran "go fmt ./..."
- ran "go vet ./..."

Signed-off-by: Casale, Robert <[email protected]>
@Gearheads
Copy link
Author

Hi @rajatjindal, apologies to bother you, just checking in to see if you have some time to review the updates I made based on your feedback?

Thank you again for your time, and effort. 😄

@rajatjindal
Copy link
Owner

Hi @rajatjindal, apologies to bother you, just checking in to see if you have some time to review the updates I made based on your feedback?

Thank you again for your time, and effort. 😄

Hi @Gearheads this is still on my mind. Apologies for the delay. I will get this tested/reviewed tomorrow.


// GetKrewIndexRepoName gets upstream_krew_index_repo_name
func (p *Provider) GetKrewIndexRepoName() string {
nameInput := getInputForAction("UPSTREAM_KREW_INDEX_REPO_NAME")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be consistent with other places, we should keep it same as the input as defined in action.yml, so kindly change it to upstream_krew_index_repo_name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem. I will update the fields to be lowercase.

@rajatjindal
Copy link
Owner

rajatjindal commented Mar 11, 2025

Hi @Gearheads

Thank you for your patience while we review this through.

tl;dr;

For custom index to work, you need following changes:

  • run your own krew-release-bot server side (I am assuming your plugin repo is private, so my bot account won't have access to it anyways)

  • When starting the krew-release-bot on server side, add following overrides that can be configured via env variables:

  • GH_TOKEN

  • UPSTREAM_KREW_INDEX_REPO_OWNER

  • UPSTREAM_KREW_INDEX_REPO_NAME

AND

KREW_RELEASE_BOT_WEBHOOK_URL - on your GitHub actions side

Detailed description:

To clarify a few things, I want to write down my thoughts on how this should work and I would love to hear your thoughts if you think some (or all) of it does not make sense.

krew-release-bot has two components:

  1. GitHub action - This runs on GitHub actions (or travis or circle) - We need the release details to be able to compile the template and render it as per the new release. This is also responsible for sending the request to the backend server.
  2. Server side - This runs on server side - This code requires details of the repo where we want to open the PR. In this case it would be custom krew-index repo owner/name and GH_TOKEN that has access to that repo.

For custom index scenario, thinking out loud. Lets say we have plugin at fidelity/my-awesome-plugin which has a krew template file. Now when we publish a new release, it will fetch the release details, and render the new template.

As a next step, the actions would now submit this request to the server side code. Now there are a couple of things to consider here:

  • The server side code has to be running with the GitHub token that has permissions to submit PR to fidelity/krew-index repo.
  • The server side needs to know that user want to submit the request to fidelity/krew-index repo

so I think we need following changes for this to work:

  • You need to run your own krew-release-bot server side (with proper auth to submit PR for fidelity/krew-index). You can use env variable GH_TOKEN when starting your server for this.
  • You need to override GitHub actions to send the request to the krew-release-bot server that you are running. You can override using environment variable KREW_RELEASE_BOT_WEBHOOK_URL when running the GitHub action.
  • You need to override Krew index repo. You can use environment variables UPSTREAM_KREW_INDEX_REPO_NAME and UPSTREAM_KREW_INDEX_REPO_OWNER for overriding these environment variables on server side.

@rajatjindal
Copy link
Owner

rajatjindal commented Mar 11, 2025

I am also happy to pair on this and get this working for you. (and in the process we can fix any issues that we might encounter).

also happy to chat on CNCF (or Kubernetes) slack regarding this. Please feel free to DM me there.

@Gearheads
Copy link
Author

Gearheads commented Jul 22, 2025

  • run your own krew-release-bot server side (I am assuming your plugin repo is private, so my bot account won't have access to it anyways)

hi @rajatjindal, apologies for the delayed response. Does this mean we need to run our own krew-release-bot on some server outside of GitHub?

I believe our custom plugin repo is currently public: https://github.com/fidelity/krew-index

I was hoping that changing the Krew index repo would be enough. What you mentioned here is what I was originally thinking of doing within our GitHub Action YAML definition:

You need to override Krew index repo. You can use environment variables UPSTREAM_KREW_INDEX_REPO_NAME and UPSTREAM_KREW_INDEX_REPO_OWNER for overriding these environment variables on server side.

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.

2 participants