[goldpushk] k8s-config refactor step 3/3: Remove references to old Git repositories. Clean up.
Change-Id: I7def91aa30d280433c3d226fe9977a88f31e2c67
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/260294
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/golden/cmd/goldpushk/goldpushk/goldpushk.go b/golden/cmd/goldpushk/goldpushk/goldpushk.go
index 9fcdd73..1f5ebf1 100644
--- a/golden/cmd/goldpushk/goldpushk/goldpushk.go
+++ b/golden/cmd/goldpushk/goldpushk/goldpushk.go
@@ -69,14 +69,10 @@
uptimePollFrequencySeconds int
// Other constructor parameters.
- skiaPublicConfigRepoUrl string
- skiaCorpConfigRepoUrl string
- k8sConfigRepoUrl string
+ k8sConfigRepoUrl string
- // Checked out Git repositories.
- skiaPublicConfigCheckout *git.TempCheckout
- skiaCorpConfigCheckout *git.TempCheckout
- k8sConfigCheckout *git.TempCheckout
+ // Checked out Git repository with k8s config files.
+ k8sConfigCheckout *git.TempCheckout
// The Kubernetes cluster that the kubectl command is currently configured to use.
currentCluster cluster
@@ -86,7 +82,7 @@
}
// New is the Goldpushk constructor.
-func New(deployableUnits []DeployableUnit, canariedDeployableUnits []DeployableUnit, skiaInfraRootPath string, dryRun, noCommit bool, minUptimeSeconds, uptimePollFrequencySeconds int, skiaPublicConfigRepoUrl, skiaCorpConfigRepoUrl, k8sConfigRepoUrl string) *Goldpushk {
+func New(deployableUnits []DeployableUnit, canariedDeployableUnits []DeployableUnit, skiaInfraRootPath string, dryRun, noCommit bool, minUptimeSeconds, uptimePollFrequencySeconds int, k8sConfigRepoUrl string) *Goldpushk {
return &Goldpushk{
deployableUnits: deployableUnits,
canariedDeployableUnits: canariedDeployableUnits,
@@ -95,8 +91,6 @@
noCommit: noCommit,
minUptimeSeconds: minUptimeSeconds,
uptimePollFrequencySeconds: uptimePollFrequencySeconds,
- skiaPublicConfigRepoUrl: skiaPublicConfigRepoUrl,
- skiaCorpConfigRepoUrl: skiaCorpConfigRepoUrl,
k8sConfigRepoUrl: k8sConfigRepoUrl,
}
}
@@ -110,12 +104,10 @@
return nil
}
- // Check out Git repositories.
- if err := g.checkOutGitRepositories(ctx); err != nil {
+ // Check out k8s-config.
+ if err := g.checkOutK8sConfigRepo(ctx); err != nil {
return skerr.Wrap(err)
}
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
defer g.k8sConfigCheckout.Delete()
// Regenerate config files.
@@ -151,13 +143,11 @@
}
// Give the user a chance to examine the generated files before exiting and cleaning up the Git
- // repositories.
+ // repository.
if g.dryRun {
- fmt.Println("\nDry-run finished. Any generated files can be found in the following Git repository checkouts:")
- fmt.Printf(" %s\n", g.skiaPublicConfigCheckout.GitDir)
- fmt.Printf(" %s\n", g.skiaCorpConfigCheckout.GitDir)
+ fmt.Println("\nDry-run finished. Any generated files can be found in the k8s-config Git repository checkout below:")
fmt.Printf(" %s\n", g.k8sConfigCheckout.GitDir)
- fmt.Println("Press enter to delete the checkouts above and exit.")
+ fmt.Println("Press enter to delete the checkout above and exit.")
if _, err := fmt.Scanln(); err != nil {
return skerr.Wrap(err)
}
@@ -213,31 +203,16 @@
return true, nil
}
-// checkOutGitRepositories checks out the skia-public-config and
-// skia-corp-config Git repositories.
-func (g *Goldpushk) checkOutGitRepositories(ctx context.Context) error {
+// checkOutK8sConfigRepo checks out the k8s-config Git repository.
+func (g *Goldpushk) checkOutK8sConfigRepo(ctx context.Context) error {
fmt.Println()
var err error
- if g.skiaPublicConfigCheckout, err = checkOutSingleGitRepository(ctx, g.skiaPublicConfigRepoUrl); err != nil {
- return skerr.Wrap(err)
- }
- if g.skiaCorpConfigCheckout, err = checkOutSingleGitRepository(ctx, g.skiaCorpConfigRepoUrl); err != nil {
- return skerr.Wrap(err)
- }
- if g.k8sConfigCheckout, err = checkOutSingleGitRepository(ctx, g.k8sConfigRepoUrl); err != nil {
- return skerr.Wrap(err)
- }
- return nil
-}
-
-// checkOutSingleGitRepository checks out the Git repository at the given URL.
-func checkOutSingleGitRepository(ctx context.Context, url string) (*git.TempCheckout, error) {
- checkout, err := git.NewTempCheckout(ctx, url)
+ g.k8sConfigCheckout, err = git.NewTempCheckout(ctx, g.k8sConfigRepoUrl)
if err != nil {
- return nil, skerr.Wrapf(err, "failed to check out %s", url)
+ return skerr.Wrapf(err, "failed to check out %s", g.k8sConfigRepoUrl)
}
- fmt.Printf("Cloned Git repository %s at %s.\n", url, string(checkout.GitDir))
- return checkout, nil
+ fmt.Printf("Cloned Git repository %s at %s.\n", g.k8sConfigRepoUrl, string(g.k8sConfigCheckout.GitDir))
+ return nil
}
// regenerateConfigFiles regenerates the .yaml and .json5 files for each
@@ -249,8 +224,7 @@
// Path to the template file inside $SKIA_INFRA_ROOT.
tPath := unit.getDeploymentFileTemplatePath(g.rootPath)
- // Path to the deployment file (.yaml) we will regenerate inside the
- // corresponding skia-{public,corp}-config Git repository.
+ // Path to the deployment file (.yaml) we will regenerate inside the k8s-config Git repository.
oPath := g.getDeploymentFilePath(unit)
// Regenerate .yaml file.
@@ -260,14 +234,12 @@
// If the DeployableUnit has a ConfigMap template (as opposed to a ConfigMap
// file that already exists in $SKIA_INFRA_ROOT)), the template must be
- // expanded and saved to the corresponding skia-{public,corp}-config Git
- // repository.
+ // expanded and saved to the k8s-config Git repository.
if unit.configMapTemplate != "" {
// Path to the template file inside $SKIA_INFRA_ROOT.
tPath = unit.getConfigMapFileTemplatePath(g.rootPath)
- // Path to the ConfigMap file (.json5) to be regenerated inside the
- // corresponding skia-{public,corp}-config repository.
+ // Path to the ConfigMap file (.json5) to be regenerated inside the k8s-config Git repository.
oPath, ok := g.getConfigMapFilePath(unit)
if !ok {
return fmt.Errorf("goldpushk.getConfigMapFilePath() failed for %s; this is probably a bug", unit.CanonicalName())
@@ -284,8 +256,7 @@
}
// getDeploymentFilePath returns the path to the deployment file (.yaml) for the
-// given DeployableUnit inside the corresponding skia-{public,corp}-config Git
-// repository.
+// given DeployableUnit inside the k8s-config Git repository.
func (g *Goldpushk) getDeploymentFilePath(unit DeployableUnit) string {
return filepath.Join(g.getGitRepoSubdirPath(unit), unit.CanonicalName()+".yaml")
}
@@ -297,8 +268,8 @@
// this will be a path inside $SKIA_INFRA_ROOT.
//
// If the DeployableUnit has a ConfigMap template (e.g. gold-skia-ingestion-bt)
-// this will be a path inside the corresponding skia-{public,corp}-config Git
-// repository pointing to the expanded ConfigMap template.
+// this will be a path inside the k8s-config Git repository pointing to the expanded
+// ConfigMap template.
//
// If neither is true, it will return ("", false).
func (g *Goldpushk) getConfigMapFilePath(unit DeployableUnit) (string, bool) {
@@ -353,13 +324,10 @@
}
// commitConfigFiles prints out a summary of the changes to be committed to
-// skia-{public,corp}-config, asks for confirmation and pushes those changes.
+// k8s-config, asks for confirmation and pushes those changes.
func (g *Goldpushk) commitConfigFiles(ctx context.Context) (bool, error) {
// Print out summary of changes (git status -s).
- err := g.forAllGitRepos(func(repo *git.TempCheckout, name string) error {
- return printOutGitStatus(ctx, repo, name)
- })
- if err != nil {
+ if err := g.printOutGitStatus(ctx); err != nil {
return false, skerr.Wrap(err)
}
@@ -369,7 +337,7 @@
if g.noCommit {
reason = "no commit"
}
- fmt.Printf("\nSkipping commit step (%s)\n", reason)
+ fmt.Printf("\nSkipping commit step (%s).\n", reason)
return true, nil
}
@@ -381,48 +349,42 @@
if !ok {
return false, nil
}
+ fmt.Println()
+
+ // Skip if the k8s-config checkout has no changes (i.e. if "git status -s" prints out nothing).
+ stdout, err := g.k8sConfigCheckout.Git(ctx, "status", "-s")
+ if err != nil {
+ return false, skerr.Wrap(err)
+ }
+ if len(stdout) == 0 {
+ return true, nil
+ }
// Add, commit and push changes.
- fmt.Println()
- err = g.forAllGitRepos(func(repo *git.TempCheckout, name string) error {
- // Skip if the current repository has no changes.
- stdout, err := repo.Git(ctx, "status", "-s")
- if err != nil {
- return skerr.Wrap(err)
- }
- if len(stdout) == 0 {
- return nil
- }
-
- fmt.Printf("Pushing changes to %s.\n", name)
- if _, err := repo.Git(ctx, "add", "."); err != nil {
- return skerr.Wrap(err)
- }
- if _, err := repo.Git(ctx, "commit", "-m", "Push"); err != nil {
- return skerr.Wrap(err)
- }
- if _, err := repo.Git(ctx, "push", "origin", "master"); err != nil {
- return skerr.Wrap(err)
- }
- return nil
- })
- if err != nil {
+ fmt.Printf("Pushing changes to the k8s-config Git repository.\n")
+ if _, err := g.k8sConfigCheckout.Git(ctx, "add", "."); err != nil {
+ return false, skerr.Wrap(err)
+ }
+ if _, err := g.k8sConfigCheckout.Git(ctx, "commit", "-m", "Push"); err != nil {
+ return false, skerr.Wrap(err)
+ }
+ if _, err := g.k8sConfigCheckout.Git(ctx, "push", "origin", "master"); err != nil {
return false, skerr.Wrap(err)
}
return true, nil
}
-// printOutGitStatus runs "git status -s" on the given checkout and prints its output to stdout.
-func printOutGitStatus(ctx context.Context, checkout *git.TempCheckout, repoName string) error {
- stdout, err := checkout.Git(ctx, "status", "-s")
+// printOutGitStatus runs "git status -s" on the k8s-config checkout and prints its output to stdout.
+func (g *Goldpushk) printOutGitStatus(ctx context.Context) error {
+ stdout, err := g.k8sConfigCheckout.Git(ctx, "status", "-s")
if err != nil {
return skerr.Wrap(err)
}
if len(stdout) == 0 {
- fmt.Printf("\nNo changes to be pushed to %s.\n", repoName)
+ fmt.Printf("\nNo changes to be pushed to the k8s-config Git repository.\n")
} else {
- fmt.Printf("\nChanges to be pushed to %s:\n", repoName)
+ fmt.Printf("\nChanges to be pushed to the k8s-config Git repository.:\n")
fmt.Print(stdout)
}
return nil
@@ -910,21 +872,6 @@
return nil
}
-// forAllGitRepos applies the *git.TempCheckouts for skia-{public,corp}-config to the given
-// function.
-func (g *Goldpushk) forAllGitRepos(f func(repo *git.TempCheckout, name string) error) error {
- if err := f(g.skiaPublicConfigCheckout, "skia-public-config"); err != nil {
- return skerr.Wrap(err)
- }
- if err := f(g.skiaCorpConfigCheckout, "skia-corp-config"); err != nil {
- return skerr.Wrap(err)
- }
- if err := f(g.k8sConfigCheckout, "k8s-config"); err != nil {
- return skerr.Wrap(err)
- }
- return nil
-}
-
// cmdToDebugStr returns a human-readable string representation of an *exec.Command.
func cmdToDebugStr(cmd *exec.Command) string {
return fmt.Sprintf("%s %s", cmd.Name, strings.Join(cmd.Args, " "))
diff --git a/golden/cmd/goldpushk/goldpushk/goldpushk_test.go b/golden/cmd/goldpushk/goldpushk/goldpushk_test.go
index 293ce4d..e550a83 100644
--- a/golden/cmd/goldpushk/goldpushk/goldpushk_test.go
+++ b/golden/cmd/goldpushk/goldpushk/goldpushk_test.go
@@ -31,7 +31,7 @@
canariedDeployableUnits = appendUnit(t, canariedDeployableUnits, s, Fuchsia, IngestionBT) // Internal deployment with templated ConfigMap.
// Call code under test.
- g := New(deployableUnits, canariedDeployableUnits, "path/to/buildbot", true, true, 30, 3, "http://skia-public.com", "http://skia-corp.com", "http://k8s-config.com")
+ g := New(deployableUnits, canariedDeployableUnits, "path/to/buildbot", true, true, 30, 3, "http://k8s-config.com")
expected := &Goldpushk{
deployableUnits: deployableUnits,
@@ -41,76 +41,52 @@
noCommit: true,
minUptimeSeconds: 30,
uptimePollFrequencySeconds: 3,
- skiaPublicConfigRepoUrl: "http://skia-public.com",
- skiaCorpConfigRepoUrl: "http://skia-corp.com",
k8sConfigRepoUrl: "http://k8s-config.com",
}
require.Equal(t, expected, g)
}
-func TestGoldpushkCheckOutGitRepositories(t *testing.T) {
+func TestGoldpushkCheckOutK8sConfigGitRepository(t *testing.T) {
unittest.MediumTest(t)
unittest.LinuxOnlyTest(t)
ctx := context.Background()
- // Create two fake skia-{public,corp}-config repositories (i.e. "git init" two temp directories).
- fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig := createFakeConfigRepos(t, ctx)
- defer fakeSkiaPublicConfig.Cleanup()
- defer fakeSkiaCorpConfig.Cleanup()
+ // Create a fake k8s-config repository (i.e. "git init" a temp directory).
+ fakeK8sConfig := createFakeK8sConfigRepo(t, ctx)
defer fakeK8sConfig.Cleanup()
- // Create the goldpushk instance under test. We pass it the file://... URLs to
- // the two Git repositories created earlier.
+ // Create the goldpushk instance under test. We pass it the file://... URL to the Git repository
+ // created earlier.
g := Goldpushk{
- skiaPublicConfigRepoUrl: fakeSkiaPublicConfig.RepoUrl(),
- skiaCorpConfigRepoUrl: fakeSkiaCorpConfig.RepoUrl(),
- k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
+ k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
}
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
defer restoreStdout()
- // Check out the fake "skia-public-config" and "skia-corp-config"
- // repositories. This will clone the repositories created earlier by running
- // "git clone file://...".
- err := g.checkOutGitRepositories(ctx)
+ // Check out the fake k8s-config repository created earlier by running "git clone file://...".
+ err := g.checkOutK8sConfigRepo(ctx)
- // Assert that no errors occurred and that we have a git.TempCheckout instance
- // for each cloned repo.
+ // Assert that no errors occurred and that we have a git.TempCheckout for the cloned repo.
require.NoError(t, err)
- require.NotNil(t, g.skiaPublicConfigCheckout)
- require.NotNil(t, g.skiaCorpConfigCheckout)
require.NotNil(t, g.k8sConfigCheckout)
- // Clean up the checkouts after the test finishes.
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
+ // Clean up the checkout after the test finishes.
defer g.k8sConfigCheckout.Delete()
- // Assert that the local path to the checkouts is not the same as the local
- // path to the fake "skia-public-config" and "skia-corp-config" repos created
- // earlier. This is just a basic sanity check that ensures that we're actually
- // dealing with clones of the original repos, as opposed to the original repos
- // themselves.
- require.NotEqual(t, g.skiaPublicConfigCheckout.GitDir, fakeSkiaPublicConfig.Dir())
- require.NotEqual(t, g.skiaCorpConfigCheckout.GitDir, fakeSkiaCorpConfig.Dir())
+ // Assert that the local path to the checkout is not the same as the local path to the fake
+ // k8s-config repo created earlier. This is just a basic sanity check to ensure that we're
+ // actually dealing with a clone of the original repo, as opposed to the original repo itself.
require.NotEqual(t, g.k8sConfigCheckout.GitDir, fakeK8sConfig.Dir())
- // Read files from the checkouts.
- publicWhichRepoTxtBytes, err := ioutil.ReadFile(filepath.Join(string(g.skiaPublicConfigCheckout.GitDir), "which-repo.txt"))
- require.NoError(t, err)
- corpWhichRepoTxtBytes, err := ioutil.ReadFile(filepath.Join(string(g.skiaCorpConfigCheckout.GitDir), "which-repo.txt"))
- require.NoError(t, err)
- k8sConfigWhichRepoTxtBytes, err := ioutil.ReadFile(filepath.Join(string(g.k8sConfigCheckout.GitDir), "which-repo.txt"))
+ // Read README.md from the checkout.
+ k8sConfigReadmeMdBytes, err := ioutil.ReadFile(filepath.Join(string(g.k8sConfigCheckout.GitDir), "README.md"))
require.NoError(t, err)
- // Assert that the contents of file "which-repo.txt" on each checkout matches
- // the contents of the same file on the corresponding origin repository.
- require.Equal(t, "This is repo skia-public-config!", string(publicWhichRepoTxtBytes))
- require.Equal(t, "This is repo skia-corp-config!", string(corpWhichRepoTxtBytes))
- require.Equal(t, "This is repo k8s-config!", string(k8sConfigWhichRepoTxtBytes))
+ // Assert that file README.md has the expected contents.
+ require.Equal(t, "This is repo k8s-config!", string(k8sConfigReadmeMdBytes))
}
func TestGoldpushkGetDeploymentFilePath(t *testing.T) {
@@ -119,7 +95,7 @@
// Create the goldpushk instance under test.
g := Goldpushk{}
- addFakeConfigRepoCheckouts(&g)
+ addFakeK8sConfigRepoCheckout(&g)
// Gather the DeployableUnits we will call Goldpushk.getDeploymentFilePath() with.
s := ProductionDeployableUnits()
@@ -139,7 +115,7 @@
g := Goldpushk{
rootPath: skiaInfraRoot,
}
- addFakeConfigRepoCheckouts(&g)
+ addFakeK8sConfigRepoCheckout(&g)
// Gather the DeployableUnits we will call Goldpushk.getConfigMapFilePath() with.
s := ProductionDeployableUnits()
@@ -188,7 +164,7 @@
canariedDeployableUnits: canariedDeployableUnits,
rootPath: "/path/to/buildbot",
}
- addFakeConfigRepoCheckouts(&g)
+ addFakeK8sConfigRepoCheckout(&g)
// Set up mocks.
commandCollector := exec.CommandCollector{}
@@ -282,100 +258,28 @@
ctx := context.Background()
- // Create two fake skia-{public,corp}-config repositories (i.e. "git init" two temp directories).
- fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig := createFakeConfigRepos(t, ctx)
- defer fakeSkiaPublicConfig.Cleanup()
- defer fakeSkiaCorpConfig.Cleanup()
-
- // Assert that there is just one commit on both repositories.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
- assertNumCommits(t, ctx, fakeK8sConfig, 1)
-
- // Create the goldpushk instance under test. We pass it the file://... URLs to the two Git
- // repositories created earlier.
- g := Goldpushk{
- skiaPublicConfigRepoUrl: fakeSkiaPublicConfig.RepoUrl(),
- skiaCorpConfigRepoUrl: fakeSkiaCorpConfig.RepoUrl(),
- k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
- }
-
- // Hide goldpushk output to stdout.
- _, restoreStdout := hideStdout(t)
- defer restoreStdout()
-
- // Check out the fake "skia-public-config" and "skia-corp-config" repositories created earlier.
- // This will run "git clone file://..." for each repository.
- err := g.checkOutGitRepositories(ctx)
- require.NoError(t, err)
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
- defer g.k8sConfigCheckout.Delete()
-
- // Add changes to skia-public-config and skia-corp-config.
- writeFileIntoRepo(t, g.skiaPublicConfigCheckout, "foo.yaml", "I'm a change in skia-public-config.")
- writeFileIntoRepo(t, g.skiaCorpConfigCheckout, "bar.yaml", "I'm a change in skia-corp-config.")
- writeFileIntoRepo(t, g.k8sConfigCheckout, "baz.yaml", "I'm a change in k8s-config.")
-
- // Pretend that the user confirms the commit step.
- cleanup := fakeStdin(t, "y\n")
- defer cleanup()
-
- // Call the function under test, which will try to commit and push the changes.
- ok, err := g.commitConfigFiles(ctx)
- require.NoError(t, err)
-
- // Assert that the user confirmed the commit step.
- require.True(t, ok)
-
- // Assert that the changes were pushed to the fake skia-{public,corp}-config repositories.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 2)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 2)
- assertNumCommits(t, ctx, fakeK8sConfig, 2)
- assertRepositoryContainsFileWithContents(t, ctx, fakeSkiaPublicConfig, "foo.yaml", "I'm a change in skia-public-config.")
- assertRepositoryContainsFileWithContents(t, ctx, fakeSkiaCorpConfig, "bar.yaml", "I'm a change in skia-corp-config.")
- assertRepositoryContainsFileWithContents(t, ctx, fakeK8sConfig, "baz.yaml", "I'm a change in k8s-config.")
-}
-
-func TestCommitConfigFilesOnlyOneRepositoryIsDirty(t *testing.T) {
- unittest.MediumTest(t)
- unittest.LinuxOnlyTest(t)
-
- ctx := context.Background()
-
- // Create two fake skia-{public,corp}-config repositories (i.e. "git init" two temp directories).
- fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig := createFakeConfigRepos(t, ctx)
- defer fakeSkiaPublicConfig.Cleanup()
- defer fakeSkiaCorpConfig.Cleanup()
+ // Create a fake k8s-config repository (i.e. "git init" a temp directory).
+ fakeK8sConfig := createFakeK8sConfigRepo(t, ctx)
defer fakeK8sConfig.Cleanup()
-
- // Assert that there is just one commit on both repositories.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
assertNumCommits(t, ctx, fakeK8sConfig, 1)
- // Create the goldpushk instance under test. We pass it the file://... URLs to the two Git
- // repositories created earlier.
+ // Create the goldpushk instance under test. We pass it the file://... URL to the Git repository
+ // created earlier.
g := Goldpushk{
- skiaPublicConfigRepoUrl: fakeSkiaPublicConfig.RepoUrl(),
- skiaCorpConfigRepoUrl: fakeSkiaCorpConfig.RepoUrl(),
- k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
+ k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
}
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
defer restoreStdout()
- // Check out the fake "skia-public-config" and "skia-corp-config" repositories created earlier.
- // This will run "git clone file://..." for each repository.
- err := g.checkOutGitRepositories(ctx)
+ // Check out the fake k8s-config repository created earlier by running "git clone file://...".
+ err := g.checkOutK8sConfigRepo(ctx)
require.NoError(t, err)
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
defer g.k8sConfigCheckout.Delete()
- // Add changes to skia-corp-config only. Repository skia-public-config remains clean.
- writeFileIntoRepo(t, g.skiaCorpConfigCheckout, "foo.yaml", "I'm a change in skia-corp-config.")
+ // Add changes to the k8s-config repository checkout.
+ writeFileIntoRepo(t, g.k8sConfigCheckout, "foo.yaml", "I'm a change in k8s-config.")
// Pretend that the user confirms the commit step.
cleanup := fakeStdin(t, "y\n")
@@ -388,13 +292,9 @@
// Assert that the user confirmed the commit step.
require.True(t, ok)
- // Assert that the skia-public-config repository remains unchanged.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeK8sConfig, 1)
-
- // Assert that changes were pushed to the fake skia-corp-config repository.
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 2)
- assertRepositoryContainsFileWithContents(t, ctx, fakeSkiaCorpConfig, "foo.yaml", "I'm a change in skia-corp-config.")
+ // Assert that the changes were pushed to the fake k8s-config repository.
+ assertNumCommits(t, ctx, fakeK8sConfig, 2)
+ assertRepositoryContainsFileWithContents(t, ctx, fakeK8sConfig, "foo.yaml", "I'm a change in k8s-config.")
}
func TestCommitConfigFilesAbortedByUser(t *testing.T) {
@@ -403,41 +303,28 @@
ctx := context.Background()
- // Create two fake skia-{public,corp}-config repositories (i.e. "git init" two temp directories).
- fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig := createFakeConfigRepos(t, ctx)
- defer fakeSkiaPublicConfig.Cleanup()
- defer fakeSkiaCorpConfig.Cleanup()
+ // Create a fake k8s-config repository (i.e. "git init" a temp directory).
+ fakeK8sConfig := createFakeK8sConfigRepo(t, ctx)
defer fakeK8sConfig.Cleanup()
-
- // Assert that there is just one commit on both repositories.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
assertNumCommits(t, ctx, fakeK8sConfig, 1)
- // Create the goldpushk instance under test. We pass it the file://... URLs to the two Git
- // repositories created earlier.
+ // Create the goldpushk instance under test. We pass it the file://... URL to the Git repository
+ // created earlier.
g := Goldpushk{
- skiaPublicConfigRepoUrl: fakeSkiaPublicConfig.RepoUrl(),
- skiaCorpConfigRepoUrl: fakeSkiaCorpConfig.RepoUrl(),
- k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
+ k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
}
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
defer restoreStdout()
- // Check out the fake "skia-public-config" and "skia-corp-config" repositories created earlier.
- // This will run "git clone file://..." for each repository.
- err := g.checkOutGitRepositories(ctx)
+ // Check out the fake k8s-config repository created earlier by running "git clone file://...".
+ err := g.checkOutK8sConfigRepo(ctx)
require.NoError(t, err)
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
defer g.k8sConfigCheckout.Delete()
- // Add changes to skia-public-config and skia-corp-config.
- writeFileIntoRepo(t, g.skiaPublicConfigCheckout, "foo.yaml", "I'm a change in skia-public-config.")
- writeFileIntoRepo(t, g.skiaCorpConfigCheckout, "bar.yaml", "I'm a change in skia-corp-config.")
- writeFileIntoRepo(t, g.k8sConfigCheckout, "baz.yaml", "I'm a change in k8s-config.")
+ // Add changes to the k8s-config repository checkout.
+ writeFileIntoRepo(t, g.k8sConfigCheckout, "foo.yaml", "I'm a change in k8s-config.")
// Pretend that the user aborts the commit step.
restoreStdin := fakeStdin(t, "n\n")
@@ -450,9 +337,7 @@
// Assert that the user aborted the commit step.
require.False(t, ok)
- // Assert that no changes were pushed to skia-public-config or skia-corp-config.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
+ // Assert that no changes were pushed to the fake k8s-config repository.
assertNumCommits(t, ctx, fakeK8sConfig, 1)
}
@@ -462,51 +347,36 @@
ctx := context.Background()
- // Create two fake skia-{public,corp}-config repositories (i.e. "git init" two temp directories).
- fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig := createFakeConfigRepos(t, ctx)
- defer fakeSkiaPublicConfig.Cleanup()
- defer fakeSkiaCorpConfig.Cleanup()
+ // Create a fake k8s-config repository (i.e. "git init" a temp directory).
+ fakeK8sConfig := createFakeK8sConfigRepo(t, ctx)
defer fakeK8sConfig.Cleanup()
-
- // Assert that there is just one commit on both repositories.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
assertNumCommits(t, ctx, fakeK8sConfig, 1)
- // Create the goldpushk instance under test. We pass it the file://... URLs to the two Git
- // repositories created earlier.
+ // Create the goldpushk instance under test. We pass it the file://... URL to the Git repository
+ // created earlier.
g := Goldpushk{
- skiaPublicConfigRepoUrl: fakeSkiaPublicConfig.RepoUrl(),
- skiaCorpConfigRepoUrl: fakeSkiaCorpConfig.RepoUrl(),
- k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
- noCommit: true,
+ k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
+ noCommit: true,
}
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
defer restoreStdout()
- // Check out the fake "skia-public-config" and "skia-corp-config" repositories created earlier.
- // This will run "git clone file://..." for each repository.
- err := g.checkOutGitRepositories(ctx)
+ // Check out the fake k8s-config repository created earlier by running "git clone file://...".
+ err := g.checkOutK8sConfigRepo(ctx)
require.NoError(t, err)
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
defer g.k8sConfigCheckout.Delete()
- // Add changes to skia-public-config and skia-corp-config.
- writeFileIntoRepo(t, g.skiaPublicConfigCheckout, "foo.yaml", "I'm a change in skia-public-config.")
- writeFileIntoRepo(t, g.skiaCorpConfigCheckout, "bar.yaml", "I'm a change in skia-corp-config.")
- writeFileIntoRepo(t, g.k8sConfigCheckout, "baz.yaml", "I'm a change in k8s-config.")
+ // Add changes to the k8s-config repository checkout.
+ writeFileIntoRepo(t, g.k8sConfigCheckout, "foo.yaml", "I'm a change in k8s-config.")
// Call the function under test, which should not commit nor push any changes.
ok, err := g.commitConfigFiles(ctx)
require.NoError(t, err)
require.True(t, ok)
- // Assert that no changes were pushed to skia-public-config or skia-corp-config.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
+ // Assert that no changes were pushed to the fake k8s-config repository.
assertNumCommits(t, ctx, fakeK8sConfig, 1)
}
@@ -516,51 +386,36 @@
ctx := context.Background()
- // Create two fake skia-{public,corp}-config repositories (i.e. "git init" two temp directories).
- fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig := createFakeConfigRepos(t, ctx)
- defer fakeSkiaPublicConfig.Cleanup()
- defer fakeSkiaCorpConfig.Cleanup()
+ // Create a fake k8s-config repository (i.e. "git init" a temp directory).
+ fakeK8sConfig := createFakeK8sConfigRepo(t, ctx)
defer fakeK8sConfig.Cleanup()
-
- // Assert that there is just one commit on both repositories.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
assertNumCommits(t, ctx, fakeK8sConfig, 1)
- // Create the goldpushk instance under test. We pass it the file://... URLs to the two Git
- // repositories created earlier.
+ // Create the goldpushk instance under test. We pass it the file://... URL to the Git repository
+ // created earlier.
g := Goldpushk{
- skiaPublicConfigRepoUrl: fakeSkiaPublicConfig.RepoUrl(),
- skiaCorpConfigRepoUrl: fakeSkiaCorpConfig.RepoUrl(),
- k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
- dryRun: true,
+ k8sConfigRepoUrl: fakeK8sConfig.RepoUrl(),
+ dryRun: true,
}
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
defer restoreStdout()
- // Check out the fake "skia-public-config" and "skia-corp-config" repositories created earlier.
- // This will run "git clone file://..." for each repository.
- err := g.checkOutGitRepositories(ctx)
+ // Check out the fake k8s-config repository created earlier by running "git clone file://...".
+ err := g.checkOutK8sConfigRepo(ctx)
require.NoError(t, err)
- defer g.skiaPublicConfigCheckout.Delete()
- defer g.skiaCorpConfigCheckout.Delete()
defer g.k8sConfigCheckout.Delete()
- // Add changes to skia-public-config and skia-corp-config.
- writeFileIntoRepo(t, g.skiaPublicConfigCheckout, "foo.yaml", "I'm a change in skia-public-config.")
- writeFileIntoRepo(t, g.skiaCorpConfigCheckout, "bar.yaml", "I'm a change in skia-corp-config.")
- writeFileIntoRepo(t, g.k8sConfigCheckout, "baz.yaml", "I'm a change in k8s-config.")
+ // Add changes to the k8s-config repository checkout.
+ writeFileIntoRepo(t, g.k8sConfigCheckout, "foo.yaml", "I'm a change in k8s-config.")
// Call the function under test, which should not commit nor push any changes.
ok, err := g.commitConfigFiles(ctx)
require.NoError(t, err)
require.True(t, ok)
- // Assert that no changes were pushed to skia-public-config or skia-corp-config.
- assertNumCommits(t, ctx, fakeSkiaPublicConfig, 1)
- assertNumCommits(t, ctx, fakeSkiaCorpConfig, 1)
+ // Assert that no changes were pushed to the fake k8s-config repository.
assertNumCommits(t, ctx, fakeK8sConfig, 1)
}
@@ -608,7 +463,7 @@
// Create the goldpushk instance under test.
g := &Goldpushk{}
- addFakeConfigRepoCheckouts(g)
+ addFakeK8sConfigRepoCheckout(g)
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
@@ -658,7 +513,7 @@
g := &Goldpushk{
canariedDeployableUnits: units,
}
- addFakeConfigRepoCheckouts(g)
+ addFakeK8sConfigRepoCheckout(g)
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
@@ -749,7 +604,7 @@
g := &Goldpushk{
deployableUnits: units,
}
- addFakeConfigRepoCheckouts(g)
+ addFakeK8sConfigRepoCheckout(g)
// Hide goldpushk output to stdout.
_, restoreStdout := hideStdout(t)
@@ -1115,45 +970,28 @@
}
}
-// createFakeConfigRepos initializes two Git repositories in local temporary directories, which can
-// be used as fake skia-{public,corp}-config repositories in tests.
-func createFakeConfigRepos(t *testing.T, ctx context.Context) (fakeSkiaPublicConfig, fakeSkiaCorpConfig, fakeK8sConfig *testutils.GitBuilder) {
- // Create two fake "skia-public-config" and "skia-corp-config" Git repos on the local file system
- // (i.e. "git init" two temporary directories).
- fakeSkiaPublicConfig = testutils.GitInit(t, ctx)
- fakeSkiaCorpConfig = testutils.GitInit(t, ctx)
- fakeK8sConfig = testutils.GitInit(t, ctx)
+// createFakeK8sConfigRepo initializes a Git repository in local temporary directory which can be
+// used as fake k8s-config repository in tests.
+func createFakeK8sConfigRepo(t *testing.T, ctx context.Context) *testutils.GitBuilder {
+ // "git init" a temporary directory.
+ fakeK8sConfig := testutils.GitInit(t, ctx)
- // Populate fake repositories with a file that will make it easier to tell them apart later on.
- fakeSkiaPublicConfig.Add(ctx, "which-repo.txt", "This is repo skia-public-config!")
- fakeSkiaPublicConfig.Commit(ctx)
- fakeSkiaCorpConfig.Add(ctx, "which-repo.txt", "This is repo skia-corp-config!")
- fakeSkiaCorpConfig.Commit(ctx)
- fakeK8sConfig.Add(ctx, "which-repo.txt", "This is repo k8s-config!")
+ // Populate fake repository with a file that will make it easier to identify it later on.
+ fakeK8sConfig.Add(ctx, "README.md", "This is repo k8s-config!")
fakeK8sConfig.Commit(ctx)
- // Allow repositories to receive pushes.
- fakeSkiaPublicConfig.AcceptPushes(ctx)
- fakeSkiaCorpConfig.AcceptPushes(ctx)
+ // Allow repository to receive pushes.
fakeK8sConfig.AcceptPushes(ctx)
- return
+ return fakeK8sConfig
}
// This is intended to be used in tests that do not need to write to disk, but need a
// git.TempCheckout instance to e.g. compute a path into a checkout.
-func addFakeConfigRepoCheckouts(g *Goldpushk) {
- fakeSkiaPublicConfigCheckout := &git.TempCheckout{
- GitDir: "/path/to/skia-public-config",
- }
- fakeSkiaCorpConfigCheckout := &git.TempCheckout{
- GitDir: "/path/to/skia-corp-config",
- }
+func addFakeK8sConfigRepoCheckout(g *Goldpushk) {
fakeK8sConfigCheckout := &git.TempCheckout{
GitDir: "/path/to/k8s-config",
}
- g.skiaPublicConfigCheckout = fakeSkiaPublicConfigCheckout
- g.skiaCorpConfigCheckout = fakeSkiaCorpConfigCheckout
g.k8sConfigCheckout = fakeK8sConfigCheckout
}
diff --git a/golden/cmd/goldpushk/main.go b/golden/cmd/goldpushk/main.go
index 72d8113..b422146 100644
--- a/golden/cmd/goldpushk/main.go
+++ b/golden/cmd/goldpushk/main.go
@@ -49,10 +49,8 @@
// Environment variable with path to buildbot repository checkout directory.
skiaInfraRootEnvVar = "SKIA_INFRA_ROOT"
- // Git repositories.
- skiaPublicConfigRepoUrl = "https://skia.googlesource.com/skia-public-config"
- skiaCorpConfigRepoUrl = "https://skia.googlesource.com/skia-corp-config"
- k8sConfigRepoUrl = "https://skia.googlesource.com/k8s-config"
+ // Git repository with k8s configuration files in YAML format.
+ k8sConfigRepoUrl = "https://skia.googlesource.com/k8s-config"
)
var (
@@ -96,7 +94,7 @@
rootCmd.Flags().StringSliceVarP(&flagServices, "services", "s", []string{}, "[REQUIRED] Comma-delimited list of services to target (e.g. \"skiacorrectness,diffserver\"), or \""+all+"\" to target all services.")
rootCmd.Flags().StringSliceVarP(&flagCanaries, "canaries", "c", []string{}, "Comma-delimited subset of Gold services to use as canaries, written as instance:service pairs (e.g. \"skia:diffserver,flutter:skiacorrectness\")")
rootCmd.Flags().BoolVar(&flagDryRun, "dryrun", false, "Do everything except applying the new configuration to Kubernetes and committing changes to Git.")
- rootCmd.Flags().BoolVar(&flagNoCommit, "no-commit", false, "Do not commit configuration changes to the skia-public-config or skia-corp-config Git repositories.")
+ rootCmd.Flags().BoolVar(&flagNoCommit, "no-commit", false, "Do not commit configuration changes to the k8s-config repository.")
rootCmd.Flags().IntVar(&flagMinUptimeSeconds, "min-uptime", 30, "Minimum uptime in seconds required for all services before exiting the monitoring step.")
rootCmd.Flags().IntVar(&flagUptimePollFrequencySeconds, "poll-freq", 3, "How often to poll Kubernetes for service uptimes, in seconds.")
rootCmd.Flags().BoolVar(&flagLogToStdErr, "logtostderr", false, "Log debug information to stderr. No logs will be produced if this flag is not set.")
@@ -157,7 +155,7 @@
}
// Build goldpushk instance.
- gpk := goldpushk.New(deployableUnits, canariedDeployableUnits, skiaInfraRoot, flagDryRun, flagNoCommit, flagMinUptimeSeconds, flagUptimePollFrequencySeconds, skiaPublicConfigRepoUrl, skiaCorpConfigRepoUrl, k8sConfigRepoUrl)
+ gpk := goldpushk.New(deployableUnits, canariedDeployableUnits, skiaInfraRoot, flagDryRun, flagNoCommit, flagMinUptimeSeconds, flagUptimePollFrequencySeconds, k8sConfigRepoUrl)
// Run goldpushk.
if err = gpk.Run(context.Background()); err != nil {