Skip to content

Commit

Permalink
Remove the logic to set go version via Prow jobs (#2148)
Browse files Browse the repository at this point in the history
* remove the logic to set go version via Prow jobs

* move cleanups to the config generator tool
  • Loading branch information
chizhg authored Jun 4, 2020
1 parent c658e22 commit 18020c5
Show file tree
Hide file tree
Showing 9 changed files with 760 additions and 4,973 deletions.
154 changes: 0 additions & 154 deletions config/prod/prow/config_knative.yaml

Large diffs are not rendered by default.

5,354 changes: 758 additions & 4,596 deletions config/prod/prow/jobs/config.yaml

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions config/staging/prow/config_staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,24 @@ presubmits:
knative-prow-robot/serving:
- build-tests: true
dot-dev: true
go114: true
- unit-tests: true
dot-dev: true
go114: true
- integration-tests: true
dot-dev: true
go114: true

knative-prow-robot/test-infra:
- build-tests: true
dot-dev: true
go114: true
- unit-tests: true
dot-dev: true
go114: true
- integration-tests: true
dot-dev: true
go114: true

periodics:
knative-prow-robot/serving:
- continuous: false
dot-dev: true
go114: true

knative-prow-robot/test-infra:
- continuous: false
dot-dev: true
go114: true
12 changes: 0 additions & 12 deletions config/staging/prow/jobs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ presubmits:
mountPath: /etc/test-account
readOnly: true
env:
- name: GO_VERSION
value: go1.14
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/test-account/service-account.json
- name: E2E_CLUSTER_REGION
Expand Down Expand Up @@ -84,8 +82,6 @@ presubmits:
mountPath: /etc/test-account
readOnly: true
env:
- name: GO_VERSION
value: go1.14
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/test-account/service-account.json
- name: E2E_CLUSTER_REGION
Expand Down Expand Up @@ -123,8 +119,6 @@ presubmits:
mountPath: /etc/test-account
readOnly: true
env:
- name: GO_VERSION
value: go1.14
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/test-account/service-account.json
- name: E2E_CLUSTER_REGION
Expand Down Expand Up @@ -163,8 +157,6 @@ presubmits:
mountPath: /etc/test-account
readOnly: true
env:
- name: GO_VERSION
value: go1.14
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/test-account/service-account.json
- name: E2E_CLUSTER_REGION
Expand Down Expand Up @@ -202,8 +194,6 @@ presubmits:
mountPath: /etc/test-account
readOnly: true
env:
- name: GO_VERSION
value: go1.14
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/test-account/service-account.json
- name: E2E_CLUSTER_REGION
Expand Down Expand Up @@ -241,8 +231,6 @@ presubmits:
mountPath: /etc/test-account
readOnly: true
env:
- name: GO_VERSION
value: go1.14
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/test-account/service-account.json
- name: E2E_CLUSTER_REGION
Expand Down
188 changes: 1 addition & 187 deletions tools/config-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ type repositoryData struct {
GoCoverageThreshold int
Processed bool
DotDev bool
Go114 bool
Go113Branches []string
}

// prowConfigTemplateData contains basic data about Prow.
Expand Down Expand Up @@ -310,96 +308,6 @@ func exclusiveSlices(a1, a2 []string) []string {
return res
}

// strip out all suffixes from the image name
func stripSuffixFromImageName(name string, suffixes []string) string {
parts := strings.SplitN(name, ":", 2)
if len(parts) != 2 {
log.Fatalf("image name should contain ':': %q", name)
}
for _, s := range suffixes {
if strings.HasSuffix(parts[0], s) {
parts[0] = strings.TrimSuffix(parts[0], s)
}
}
return strings.Join(parts, ":")
}

// add suffix to the image name
// e.g. if suffix = "-go112", then [IMAGE]:[DIGEST]-> [IMAGE]-go112:[DIGEST]
func addSuffixToImageName(name string, suffix string) string {
parts := strings.SplitN(name, ":", 2)
if len(parts) != 2 {
log.Fatalf("image name should contain ':': %q", name)
}
if !strings.HasSuffix(parts[0], suffix) {
parts[0] = fmt.Sprintf("%s%s", parts[0], suffix)
}
return strings.Join(parts, ":")
}

// Consolidate whitelisted and skipped branches with newly added
// whitelisted/skipped. To make the logic easier to maintain, this function
// makes the assumption that the outcome follows these rules:
// - Special branch logics always apply on master and future branches
// Based on the previous rule, if there is a special branch logic, the 2 Prow
// jobs that serves different branches become:
// - Standard job definition:
// - whitelisted: [release-0.1]
// - skipped: []
// - Standard job definition + branch special logic #1:
// - whitelisted: []
// - skipped: [release-0.1]
// And when there is a new special logic comes up with different list of release
// branches to exclude, for example [release-0.1, release-0.2], then the desired
// outcome becomes:
// - Standard job definition:
// - whitelisted: [release-0.1]
// - skipped: []
// - Standard job definition + branch special logic #1: (This will never run)
// - whitelisted: []
// - skipped: []
// - Standard job definition + branch special logic #2:
// - whitelisted: [release-0.2]
// - skipped: []
// - Standard job definition + branch special logic #1 + branch special logic #2:
// - whitelisted: []
// - skipped: [release-0.1, release-0.2]
// Noted that only jobs with all special branch logics have something in
// skipped, while all other jobs only have whitelisted. This rule also applies
// when there is a third branch specific logic and so on.
// This function takes the logic above, and determines whether generate
// whitelisted or skipped as output.
func consolidateBranches(whitelisted []string, skipped []string, newWhitelisted []string, newSkipped []string) ([]string, []string) {
var combinedWhitelisted, combinedSkipped []string

// Do the legacy part(old branches):
if len(newWhitelisted) > 0 {
if len(skipped) > 0 {
// - if previous is skipped(latest), then minus the skipped from current
// branches, as we want to run exclusive on branches supported currently
combinedWhitelisted = exclusiveSlices(newWhitelisted, skipped)
} else if len(whitelisted) > 0 {
// - if previous is include, then find their intersections, as these are the
// real supported branches
combinedWhitelisted = intersectSlices(newWhitelisted, whitelisted)
} else {
combinedWhitelisted = newWhitelisted
}
} else if len(newSkipped) > 0 { // Then do the pos part(latest)
if len(skipped) > 0 {
// - if previous is skipped(latest), then find the combination, as we want to
// skip all non-supported
combinedSkipped = combineSlices(newSkipped, skipped)
} else if len(whitelisted) > 0 {
// - if previous is include, then minus current branches from included
combinedWhitelisted = exclusiveSlices(whitelisted, newSkipped)
} else {
combinedSkipped = newSkipped
}
}
return combinedWhitelisted, combinedSkipped
}

// Config generation functions.

// newbaseProwJobTemplateData returns a baseProwJobTemplateData type with its initial, default values.
Expand Down Expand Up @@ -464,17 +372,6 @@ func (data *baseProwJobTemplateData) addEnvToJob(key, value string) {
data.Env = append(data.Env, envNameToKey(key), envValueToValue(value))
}

func (data *baseProwJobTemplateData) SetGoVersion(version GoVersion) {
envKey := envNameToKey("GO_VERSION")
for i, key := range data.Env {
if key == envKey {
data.Env[i+1] = envValueToValue(version.String())
return
}
}
data.addEnvToJob("GO_VERSION", version.String())
}

// addLabelToJob adds extra labels to a job
func addLabelToJob(data *baseProwJobTemplateData, key, value string) {
(*data).Labels = append((*data).Labels, []string{key + ": " + value}...)
Expand Down Expand Up @@ -553,7 +450,7 @@ func setResourcesReqForJob(res yaml.MapSlice, data *baseProwJobTemplateData) {
// parseBasicJobConfigOverrides updates the given baseProwJobTemplateData with any base option present in the given config.
func parseBasicJobConfigOverrides(data *baseProwJobTemplateData, config yaml.MapSlice) {
(*data).ExtraRefs = append((*data).ExtraRefs, " base_ref: "+(*data).RepoBranch)
var needDotdev, needGo114 bool
var needDotdev bool
for i, item := range config {
switch item.Key {
case "skip_branches":
Expand Down Expand Up @@ -581,26 +478,12 @@ func parseBasicJobConfigOverrides(data *baseProwJobTemplateData, config yaml.Map
repositories[i].DotDev = true
}
}
case "go114":
needGo114 = true
for i, repo := range repositories {
if path.Base(repo.Name) == (*data).RepoName {
repositories[i].Go114 = true
data.RepoNameForJob = fmt.Sprintf("%s-%s", (*data).OrgName, (*data).RepoName)
}
}
case "performance":
for i, repo := range repositories {
if path.Base(repo.Name) == (*data).RepoName {
repositories[i].EnablePerformanceTests = true
}
}
case "go113-branches":
for i, repo := range repositories {
if path.Base(repo.Name) == (*data).RepoName {
repositories[i].Go113Branches = getStringArray(item.Value)
}
}
case "env-vars":
addExtraEnvVarsToJob(getStringArray(item.Value), data)
case "optional":
Expand All @@ -621,9 +504,6 @@ func parseBasicJobConfigOverrides(data *baseProwJobTemplateData, config yaml.Map
(*data).PathAlias = "path_alias: knative.dev/" + (*data).RepoName
(*data).ExtraRefs = append((*data).ExtraRefs, " "+(*data).PathAlias)
}
if needGo114 {
data.SetGoVersion(GoVersion{1, 14})
}
// Override any values if provided by command-line flags.
if timeoutOverride > 0 {
(*data).Timeout = timeoutOverride
Expand Down Expand Up @@ -830,72 +710,6 @@ func getBase(data interface{}) *baseProwJobTemplateData {
return base
}

// recursiveSBL recursively going through specialBranchLogic, and generate job
// at last. Use `i` to keeps track of current index in sbs to be used
func recursiveSBL(repoName string, data interface{}, generateOneJob func(data interface{}), sbs []specialBranchLogic, i int) {
// Base case, all special branch logics have been applied
if i == len(sbs) {
// If there is no branch left, this job shouldn't be generated at all
if len(getBase(data).Branches) > 0 || len(getBase(data).SkipBranches) > 0 {
generateOneJob(data)
}
return
}

sb := sbs[i]
base := getBase(data)

origBranches, origSkipBranches := base.Branches, base.SkipBranches
// Do legacy branches first
base.Branches, base.SkipBranches = consolidateBranches(origBranches, origSkipBranches, sb.branches, []string{})
recursiveSBL(repoName, data, generateOneJob, sbs, i+1)
// Then do latest branches
base.Branches, base.SkipBranches = consolidateBranches(origBranches, origSkipBranches, []string{}, sb.branches)
sb.opsNew(base)
recursiveSBL(repoName, data, generateOneJob, sbs, i+1)
sb.restore(base)
}

// executeJobTemplateWrapper takes in consideration of repo settings, decides how many variants of the
// same job needs to be generated and generates them.
func executeJobTemplateWrapper(repoName string, data interface{}, generateOneJob func(data interface{})) {
var sbs []specialBranchLogic

switch data.(type) {
case *postsubmitJobTemplateData:
if strings.HasSuffix(data.(*postsubmitJobTemplateData).PostsubmitJobName, "go-coverage") {
generateOneJob(data)
return
}
}

var go113Branches []string
// Find out if Go113Branches is set in repo settings
for _, repo := range repositories {
if repo.Name == repoName {
if len(repo.Go113Branches) > 0 {
go113Branches = repo.Go113Branches
}
}
}
if len(go113Branches) > 0 {
sbs = append(sbs, specialBranchLogic{
branches: go113Branches,
opsNew: func(base *baseProwJobTemplateData) {
base.SetGoVersion(GoVersion{1, 14})
},
restore: func(base *baseProwJobTemplateData) {
},
})
}

if len(sbs) == 0 { // Generate single job if there is no special branch logic
generateOneJob(data)
} else {
recursiveSBL(repoName, data, generateOneJob, sbs, 0)
}
}

// executeTemplate outputs the given job template with the given data, respecting any filtering.
func executeJobTemplate(name, templ, title, repoName, jobName string, groupByRepo bool, data interface{}) {
if jobNameFilter != "" && jobNameFilter != jobName {
Expand Down
7 changes: 0 additions & 7 deletions tools/config-generator/perf_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ func perfClusterReconcilePostsubmitJob(jobNamePostFix, command string, args []st

func perfClusterBaseProwJob(command string, args []string, fullRepoName, sa string) baseProwJobTemplateData {
base := newbaseProwJobTemplateData(fullRepoName)
for _, repo := range repositories {
if fullRepoName == repo.Name && repo.Go114 {
base.SetGoVersion(GoVersion{1, 14})
break
}
}

base.Command = command
base.Args = args
addVolumeToJob(&base, "/etc/performance-test", sa, true, "")
Expand Down
3 changes: 0 additions & 3 deletions tools/config-generator/periodic_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ func generateGoCoveragePeriodic(title string, repoName string, _ yaml.MapSlice)
if repo.DotDev {
data.Base.ExtraRefs = append(data.Base.ExtraRefs, " path_alias: knative.dev/"+path.Base(repoName))
}
if repo.Go114 {
data.Base.SetGoVersion(GoVersion{1, 14})
}
addExtraEnvVarsToJob(extraEnvVars, &data.Base)
addMonitoringPubsubLabelsToJob(&data.Base, data.PeriodicJobName)
configureServiceAccountForJob(&data.Base)
Expand Down
3 changes: 0 additions & 3 deletions tools/config-generator/postsubmit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func generateGoCoveragePostsubmit(title, repoName string, _ yaml.MapSlice) {
if repo.Name == repoName && repo.DotDev {
data.Base.PathAlias = "path_alias: knative.dev/" + path.Base(repoName)
}
if repo.Name == repoName && repo.Go114 {
data.Base.SetGoVersion(GoVersion{1, 14})
}
}
addExtraEnvVarsToJob(extraEnvVars, &data.Base)
configureServiceAccountForJob(&data.Base)
Expand Down
4 changes: 1 addition & 3 deletions tools/config-generator/presubmit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ func generatePresubmit(title string, repoName string, presubmitConfig yaml.MapSl
jobName := data.PresubmitPullJobName

// This is where the data actually gets written out
executeJobTemplateWrapper(repoName, &data, func(data interface{}) {
executeJobTemplate("presubmit", jobTemplate, title, repoName, jobName, true, data)
})
executeJobTemplate("presubmit", jobTemplate, title, repoName, jobName, true, data)

// Generate config for pull-knative-serving-go-coverage-dev right after pull-knative-serving-go-coverage,
// this job is mainly for debugging purpose.
Expand Down

0 comments on commit 18020c5

Please sign in to comment.