Skip to content

Commit

Permalink
Add possibility to build custom Kubernetes forks
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed May 19, 2021
1 parent d01242d commit 2e1ce79
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 14 deletions.
3 changes: 3 additions & 0 deletions gcb/release/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "K8S_ORG=${_K8S_ORG}"
- "K8S_REPO=${_K8S_REPO}"
- "K8S_REF=${_K8S_REF}"
secretEnv:
- GITHUB_TOKEN
args:
Expand Down
3 changes: 3 additions & 0 deletions gcb/stage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "K8S_ORG=${_K8S_ORG}"
- "K8S_REPO=${_K8S_REPO}"
- "K8S_REF=${_K8S_REF}"
secretEnv:
- GITHUB_TOKEN
- DOCKERHUB_TOKEN
Expand Down
76 changes: 76 additions & 0 deletions pkg/anago/anagofakes/fake_stage_impl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/anago/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type stageImpl interface {
CurrentBranch(repo *git.Repo) (string, error)
CommitEmpty(repo *git.Repo, msg string) error
Tag(repo *git.Repo, name, message string) error
Merge(repo *git.Repo, rev string) error
CheckReleaseBucket(options *build.Options) error
DockerHubLogin() error
MakeCross(version string) error
Expand Down Expand Up @@ -213,6 +214,10 @@ func (d *defaultStageImpl) Tag(repo *git.Repo, name, message string) error {
return repo.Tag(name, message)
}

func (d *defaultStageImpl) Merge(repo *git.Repo, rev string) error {
return repo.Merge(rev)
}

func (d *defaultStageImpl) MakeCross(version string) error {
return build.NewMake().MakeCross(version)
}
Expand Down Expand Up @@ -437,6 +442,16 @@ func (d *DefaultStage) TagRepository() error {
}
}

// If a custom ref is provided, try to merge it into the release
// branch.
ref := release.GetK8sRef()
if ref != release.DefaultK8sRef {
logrus.Infof("Merging custom ref: %s", ref)
if err := d.impl.Merge(repo, git.Remotify(ref)); err != nil {
return errors.Wrap(err, "merge k8s ref")
}
}

// Tag the repository:
logrus.Infof("Tagging version %s", version)
if err := d.impl.Tag(
Expand Down
2 changes: 1 addition & 1 deletion pkg/changelog/changelogfakes/fake_impl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/gcp/gcb/gcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef string) (map[string
gcbSubs["TOOL_REPO"] = toolRepo
gcbSubs["TOOL_REF"] = toolRef

gcbSubs["K8S_ORG"] = release.GetK8sOrg()
gcbSubs["K8S_REPO"] = release.GetK8sRepo()
gcbSubs["K8S_REF"] = release.GetK8sRef()

gcpUser := g.options.GcpUser
if gcpUser == "" {
var gcpUserErr error
Expand Down
24 changes: 24 additions & 0 deletions pkg/gcp/gcb/gcb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "17",
"PATCH_VERSION_TAG": "0",
"KUBERNETES_VERSION_TAG": "1.17.0",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand All @@ -213,6 +216,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "33",
"PATCH_VERSION_TAG": "7",
"KUBERNETES_VERSION_TAG": "1.33.7",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand All @@ -237,6 +243,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "15",
"KUBERNETES_VERSION_TAG": "1.15.0-rc.2",
"PATCH_VERSION_TAG": "0",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand All @@ -261,6 +270,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "15",
"PATCH_VERSION_TAG": "1",
"KUBERNETES_VERSION_TAG": "1.15.1",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand Down Expand Up @@ -288,6 +300,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "16",
"PATCH_VERSION_TAG": "0",
"KUBERNETES_VERSION_TAG": "1.16.0",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand Down Expand Up @@ -315,6 +330,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "19",
"PATCH_VERSION_TAG": "0",
"KUBERNETES_VERSION_TAG": "1.19.0-beta.0",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand All @@ -339,6 +357,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "18",
"KUBERNETES_VERSION_TAG": "1.18.6-rc.1",
"PATCH_VERSION_TAG": "6",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
{
Expand All @@ -363,6 +384,9 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"MINOR_VERSION_TAG": "18",
"KUBERNETES_VERSION_TAG": "1.18.0-rc.1",
"PATCH_VERSION_TAG": "0",
"K8S_ORG": git.DefaultGithubOrg,
"K8S_REPO": git.DefaultGithubRepo,
"K8S_REF": git.DefaultRef,
},
},
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/license/licensefakes/fake_downloader_implementation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/license/licensefakes/fake_reader_implementation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/release/branch_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *BranchChecker) NeedsCreation(
logrus.Infof("Checking if branch %s exists on remote", branch)

output, err := r.impl.LSRemoteExec(
git.GetDefaultKubernetesRepoURL(),
git.GetRepoURL(GetK8sOrg(), GetK8sRepo(), false),
fmt.Sprintf("refs/heads/%s", branch),
)
if err != nil {
Expand Down
31 changes: 31 additions & 0 deletions pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const (
DefaultToolRepo = "release"
DefaultToolRef = git.DefaultBranch
DefaultToolOrg = git.DefaultGithubOrg

DefaultK8sOrg = git.DefaultGithubOrg
DefaultK8sRepo = git.DefaultGithubRepo
DefaultK8sRef = git.DefaultRef

// TODO(vdf): Need to reference K8s Infra project here
DefaultKubernetesStagingProject = "kubernetes-release-test"
DefaultRelengStagingProject = "k8s-staging-releng"
Expand Down Expand Up @@ -176,6 +181,32 @@ func GetToolRef() string {
return env.Default("TOOL_REF", DefaultToolRef)
}

// GetK8sOrg checks if the 'K8S_ORG' environment variable is set.
// If 'K8S_ORG' is non-empty, it returns the value. Otherwise, it returns DefaultK8sOrg.
func GetK8sOrg() string {
return env.Default("K8S_ORG", DefaultK8sOrg)
}

// GetK8sRepo checks if the 'K8S_REPO' environment variable is set.
// If 'K8S_REPO' is non-empty, it returns the value. Otherwise, it returns DefaultK8sRepo.
func GetK8sRepo() string {
return env.Default("K8S_REPO", DefaultK8sRepo)
}

// GetK8sRef checks if the 'K8S_REF' environment variable is set.
// If 'K8S_REF' is non-empty, it returns the value. Otherwise, it returns DefaultK8sRef.
func GetK8sRef() string {
return env.Default("K8S_REF", DefaultK8sRef)
}

// IsDefaultK8sUpstream returns true if GetK8sOrg(), GetK8sRepo() and
// GetK8sRef() point to their default values.
func IsDefaultK8sUpstream() bool {
return GetK8sOrg() == DefaultK8sOrg &&
GetK8sRepo() == DefaultK8sRepo &&
GetK8sRef() == DefaultK8sRef
}

// BuiltWithBazel determines whether the most recent Kubernetes release was built with Bazel.
func BuiltWithBazel(workDir string) (bool, error) {
bazelBuild := filepath.Join(workDir, BazelBuildDir, ReleaseTarsPath, KubernetesTar)
Expand Down
Loading

0 comments on commit 2e1ce79

Please sign in to comment.