Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: Fix error msg when the Git token doesn't match the repo owner #4324

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

somtochiama
Copy link
Member

@somtochiama somtochiama commented Oct 12, 2023

When running flux bootstrap with the wrong user (and the repository already exists) returns this confusing error because
ggp tries to create the repository under the authenticated user.

flux bootstrap github --owner=soule --token-auth --repository=fleet-infra --personal
► connecting to github.com
✗ failed to create new Git repository "https://github.com/soule/fleet-infra": multiple errors occurred:
- POST https://api.github.com/user/repos: 422 Repository creation failed. [{Resource:Repository Field:name Code:custom Message:name already exists on this account}]
- resource already exists, cannot create object. Use Reconcile() to create it idempotently

With these changes, we give a better error

./bin/flux bootstrap github --owner=soule --token-auth --repository=fleet-infraxx --personal
► connecting to github.com
✗ failed to create new Git repository "https://github.com/soule/fleet-infraxx": the specified owner 'soule' doesn't match the identity associated with the given token

Closes: #3867

@somtochiama somtochiama changed the title Update go-git-providers to v0.19.1 Return better error when wrong user is passed in (along with --personal flag Oct 12, 2023
@makkes
Copy link
Member

makkes commented Oct 12, 2023

This is much better than before. One thing we could still improve on would be that the message ✗ failed to create new Git repository "https://github.com/soule/fleet-infraxx": incorrect owner 'soule' passed in isn't very actionable because the user did want to create the repo under that user's account so strictly speaking it's not an "incorrect owner", is it?

@stefanprodan stefanprodan changed the title Return better error when wrong user is passed in (along with --personal flag bootstrap: Fix error msg when the Git token doesn't match the repo owner Oct 12, 2023
@stefanprodan stefanprodan added the area/bootstrap Bootstrap related issues and pull requests label Oct 12, 2023
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

Please squash the two commits.

@stefanprodan stefanprodan added the backport:release/v2.1.x To be backported to release/v2.1.x label Oct 12, 2023
@somtochiama
Copy link
Member Author

somtochiama commented Oct 12, 2023

because the user did want to create the repo under that user's account so strictly speaking it's not an "incorrect owner", is it?

More like the wrong string is passed into the --owner flag. We can check for the error and return a better error msg.
@makkes Is something like please pass correct username when using --personal flag better?
and I have updated the description. This is the error that is returned: incorrect user 'soule' provided

stefanprodan
stefanprodan previously approved these changes Oct 12, 2023
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @somtochiama 🏅

@stefanprodan
Copy link
Member

stefanprodan commented Oct 12, 2023

Maybe the specified owner X doesn't match the identity associated with the given token is more accurate?

@stefanprodan
Copy link
Member

@somtochiama please make the changes upstream, we'll do another patch release of ggp then you can update this PR.

@stefanprodan stefanprodan dismissed their stale review October 12, 2023 10:32

needs changes upstream

Signed-off-by: Somtochi Onyekwere <[email protected]>
@stefanprodan stefanprodan merged commit be03ca3 into fluxcd:main Oct 12, 2023
7 checks passed
@fluxcdbot
Copy link
Member

Successfully created backport PR for release/v2.1.x:

@stefanprodan stefanprodan mentioned this pull request Oct 12, 2023
13 tasks
nrdufour added a commit to nrdufour/home-ops that referenced this pull request Oct 13, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [fluxcd/flux2](https://github.com/fluxcd/flux2) | Kustomization | patch | `v2.1.1` -> `v2.1.2` |

---

> ⚠ **Warning**
>
> Some dependencies could not be looked up. Check the warning logs for more information.

---

### Release Notes

<details>
<summary>fluxcd/flux2 (fluxcd/flux2)</summary>

### [`v2.1.2`](https://github.com/fluxcd/flux2/releases/tag/v2.1.2)

[Compare Source](fluxcd/flux2@v2.1.1...v2.1.2)

#### Highlights

Flux `v2.1.2` is a patch release which comes with various fixes. Users are encouraged to upgrade for the best experience.

##### Fixes

-   Ensures faster recovery of `Kustomization` and `HelmRelease` resources when the source-controller has restarted and is working on restoring the storage.
-   Prevent source-controller from failing to reconcile `OCIRepositories` when artifacts contain symlinks.
-   Addresses issue with helm-controller miss-labeling Custom Resource Definitions.
-   Detect immutable field errors in Google Cloud resources managed by Flux `Kustomizations`.
-   Better error reporting for `flux bootstrap` when the owner doesn't match the identity associated with the given token.
-   Allow `flux pull artifact` to fetch OCI artifacts produced by other tools.

#### Components changelog

-   source-controller [v1.1.2](https://github.com/fluxcd/source-controller/blob/v1.1.2/CHANGELOG.md)
-   kustomize-controller [v1.1.1](https://github.com/fluxcd/kustomize-controller/blob/v1.1.1/CHANGELOG.md)
-   helm-controller [v0.36.2](https://github.com/fluxcd/helm-controller/blob/v0.36.2/CHANGELOG.md)

#### CLI Changelog

-   PR [#&#8203;4324](fluxcd/flux2#4324) - [@&#8203;somtochiama](https://github.com/somtochiama) - bootstrap: Fix error msg when the Git token doesn't match the repo owner
-   PR [#&#8203;4323](fluxcd/flux2#4323) - [@&#8203;stefanprodan](https://github.com/stefanprodan) - e2e: Update Go dependencies
-   PR [#&#8203;4313](fluxcd/flux2#4313) - [@&#8203;fluxcdbot](https://github.com/fluxcdbot) - Update toolkit components
-   PR [#&#8203;4296](fluxcd/flux2#4296) - [@&#8203;Skarlso](https://github.com/Skarlso) - fix: only wait for changeset if the result is not empty
-   PR [#&#8203;4285](fluxcd/flux2#4285) - [@&#8203;matheuscscp](https://github.com/matheuscscp) - Add badge for SLSA Level 3
-   PR [#&#8203;4284](fluxcd/flux2#4284) - [@&#8203;errordeveloper](https://github.com/errordeveloper) - Make `flux pull` work for OCI artifacts produced by other tools

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMy4wIiwidXBkYXRlZEluVmVyIjoiMzcuMTMuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Reviewed-on: https://git.home/nrdufour/home-ops/pulls/143
Co-authored-by: Renovate <[email protected]>
Co-committed-by: Renovate <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bootstrap Bootstrap related issues and pull requests backport:release/v2.1.x To be backported to release/v2.1.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flux bootstrap gitlab ignores --owner when creating the repo
4 participants