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

Reduce handling of Github during stage and release #2127

Merged
merged 3 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/release/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ func (a *defaultArchiverImpl) DeleteStalePasswordFiles(releaseBuildDir string) e
).RunSuccess(); err != nil {
return errors.Wrap(err, "deleting temporary password files")
}

// Delete the git remote config to avoid it ending in the stage bucket
gitConf := filepath.Join(releaseBuildDir, "k8s.io/kubernetes/.git/config")
if util.Exists(gitConf) {
if err := os.Remove(gitConf); err != nil {
return errors.Wrap(err, "deleting git remote config")
}
} else {
logrus.Warn("git configuration file not found, nothing to remove")
}

return nil
}

Expand Down
36 changes: 21 additions & 15 deletions pkg/release/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,13 @@ import (
func PrepareWorkspaceStage(directory string) error {
logrus.Infof("Preparing workspace for staging in %s", directory)
logrus.Infof("Cloning repository to %s", directory)
repo, err := git.CloneOrOpenGitHubRepo(
_, err := git.CloneOrOpenGitHubRepo(
directory, git.DefaultGithubOrg, git.DefaultGithubRepo, false,
)
if err != nil {
return errors.Wrap(err, "clone k/k repository")
}

token, ok := os.LookupEnv(github.TokenEnvKey)
if !ok {
return errors.Errorf("%s env variable is not set", github.TokenEnvKey)
}

if err := repo.SetURL(git.DefaultRemote, (&url.URL{
Scheme: "https",
User: url.UserPassword("git", token),
Host: "github.com",
Path: filepath.Join(git.DefaultGithubOrg, git.DefaultGithubRepo),
}).String()); err != nil {
return errors.Wrap(err, "changing git remote of repository")
}

// Prewarm the SPDX licenses cache. As it is one of the main
// remote operations, we do it now to have the data and fail early
// is something goes wrong.
Expand Down Expand Up @@ -105,5 +91,25 @@ func PrepareWorkspaceRelease(directory, buildVersion, bucket string) error {
return errors.Wrapf(err, "extracting %s", dst)
}

// Reset the github token in the staged k/k clone
token, ok := os.LookupEnv(github.TokenEnvKey)
if !ok {
return errors.Errorf("%s env variable is not set", github.TokenEnvKey)
}

repo, err := git.OpenRepo(directory)
if err != nil {
return errors.Wrap(err, "opening staged clone of k/k")
}

if err := repo.SetURL(git.DefaultRemote, (&url.URL{
Scheme: "https",
User: url.UserPassword("git", token),
Host: "github.com",
Path: filepath.Join(git.DefaultGithubOrg, git.DefaultGithubRepo),
}).String()); err != nil {
return errors.Wrap(err, "changing git remote of repository")
}

return nil
}