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

Introduce Git config URL rewrite option #937

Merged
merged 1 commit into from
Nov 25, 2021

Conversation

HeavyWombat
Copy link
Contributor

@HeavyWombat HeavyWombat commented Nov 4, 2021

Changes

There is use case that pops up more often than others and this is that a user wants to build a private repository that contains a submodule, which itself is also a private repository. Sometimes, the submodule is configured using a HTTPS URL while the main repository uses Git+SSH. This leads to errors in the Git step, because the private submodule cannot be loaded due to missing access credentials. Obviously, the HTTPS URL does not accept the Git private key that is configured. The typical local solution is to setup an insteadOf URL rewrite rule in the Git config to dynamically translate the URL types. This PR brings the same feature to the Git step. It is disabled by default.

  • Add Git wrapper command line flag to enable setting up Git config URL rewrite.

  • Add environment variable GIT_ENABLE_REWRITE_RULE to enable the feature for
    the step in the build strategy.

  • Add code to set the Git wrapper CLI flag if configured.

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

Git step now supports setting an optional rewrite rule so that HTTPS URLs are translated into Git+SSH URLs during the Git clone and Git submodule operations.

@openshift-ci openshift-ci bot added the release-note Label for when a PR has specified a release note label Nov 4, 2021
@HeavyWombat HeavyWombat mentioned this pull request Nov 4, 2021
4 tasks
cmd/git/main.go Outdated
hostname = repoURL.Host

default:
return fmt.Errorf("unknown URL type: %q", flagValues.url)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is a good idea. If you check https://stackoverflow.com/questions/31801271/what-are-the-supported-git-url-formats, then ssh:// and git:// (I think GitHub just stopped supporting it) would also be possible. We could add more cases. Anyway, imo we should just print a warning that we cannot parse it and therefore do not configure a rewrite.

Copy link
Member

Choose a reason for hiding this comment

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

GitHub did in fact stop supporting (introducing "brown outs") for git://

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed implementation to print a message in case it is an unknown or unsupported type.

@@ -68,6 +68,9 @@ const (

terminationLogPathDefault = "/dev/termination-log"
terminationLogPathEnvVar = "TERMINATION_LOG_PATH"

// environment variable for the Git rewrite setting
useGitRewriteRule = "ENABLE_GIT_REWRITE_RULE"
Copy link
Member

Choose a reason for hiding this comment

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

Please document the new environment variable in https://github.com/shipwright-io/build/blob/main/docs/configuration.md. For consistency, I would also move GIT_ to the beginning of the environment variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@SaschaSchwarze0 SaschaSchwarze0 added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 5, 2021
Copy link
Member

@gabemontero gabemontero left a comment

Choose a reason for hiding this comment

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

I'm not calling out that this PR has to take on the command line flag item I noted below

But the situation just grows ...

cmd/git/main.go Outdated
hostname = repoURL.Host

default:
return fmt.Errorf("unknown URL type: %q", flagValues.url)
Copy link
Member

Choose a reason for hiding this comment

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

GitHub did in fact stop supporting (introducing "brown outs") for git://

@@ -82,6 +83,7 @@ func init() {

// Mostly internal flag
pflag.BoolVar(&flagValues.skipValidation, "skip-validation", false, "skip pre-requisite validation")
pflag.BoolVar(&flagValues.gitURLRewrite, "git-url-rewrite", false, "set Git config to use url-insteadOf setting based on Git repository URL")
Copy link
Member

Choose a reason for hiding this comment

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

hmm ... when are we going to "bite the bullet" and start controlling behavior like this via settings in config maps vs. start up flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, I know. Do not have a good answer for that. With a config map, I think there was the discussion that this will lead to higher expectations, for example that an operator will likely assume that a change in the config map will immediately be used by the controller.

Copy link
Member

Choose a reason for hiding this comment

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

Imo the command line flags in step containers like git or mutate-image will never go away because the BuildRun pod in the user's namespace will never access a ConfigMap that represents the Shipwright configuration (in the shipwright namespace). The other question is when the environment variables on the controller yaml will get replaced by a ConfigMap. Imo this can happen at any time, though as long as it has not been done, we should not stop any feature development that by coincident needs a configuration.

Copy link
Member

Choose a reason for hiding this comment

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

a config map with the config can be created in the user's namespace by the shipwright controller, based on config (including config maps) that drive the behavior of the controller, including how it sets up the build run pod, so that the user namespace config map drives the behavior of the build run pod

such a pattern is employed in openshift builds today

as our discussion here reflects, a separate effort, including most likely an EP, should be pursued ... probably discussion in community or grooming meetings to collectively decide when we will get to this

@HeavyWombat efforts here just remind us we keep putting this off :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gabemontero The config map idea has an issue as far as I know. We just need someone to find time and the energy to do it. Independent of that, are you good to let this PR go into the main branch? Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

@HeavyWombat yeah the config map idea has been discussed, but I could not find a tracking issue (via https://github.com/shipwright-io/build/issues?q=is%3Aissue+is%3Aopen+config+in%3Atitle)

but we don't need to sort that out here

so regardless , yes, as I said before, I'm fine with the PR moving forward independent of that.

that said, non-shipwright items have popped for me and unfortunately it will be at least until second half of next week before I can do a legitimate code review (vs. the cursory scan I did last week)

if you don't want to wait that long of course assign anybody from the @sbose78 @adambkaplan @imjasonh @coreydaley @otaviof list of hatters and they can pick up

thanks

Add Git wrapper command line flag to enable setting up Git config URL rewrite.

Add environment variable `GIT_ENABLE_REWRITE_RULE` to enable the feature for
the step in the build strategy.

Add code to set the Git wrapper CLI flag if configured.

Signed-off-by: Mayukh Sarkar <mayukh.sarkar1@ibm.com>
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 5, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SaschaSchwarze0

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 5, 2021
@SaschaSchwarze0
Copy link
Member

/lgtm

We just had the next customer who used an https URL with an SSH secret. I'd like to take away their frustration finally.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 25, 2021
@openshift-merge-robot openshift-merge-robot merged commit d0f5e9b into main Nov 25, 2021
@SaschaSchwarze0 SaschaSchwarze0 deleted the add/git-rewrite-rule branch November 25, 2021 07:31
@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.7.0 milestone Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Label for when a PR has specified a release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants