Skip to content

Commit

Permalink
Merge pull request #2127 from puerco/reseed
Browse files Browse the repository at this point in the history
Reduce handling of Github during stage and release
  • Loading branch information
k8s-ci-robot authored Jun 17, 2021
2 parents f35d636 + ce90c9f commit 6f0f817
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
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
}

0 comments on commit 6f0f817

Please sign in to comment.