From 650456eff0364b0889d6ff186802f1bd8df58628 Mon Sep 17 00:00:00 2001 From: Petr Muller Date: Fri, 28 Jun 2019 15:15:51 +0200 Subject: [PATCH] prowgen: Remove some dead code Previously we needed to handle labels specifically in postsubmits because we were marking them with `artifacts: images`. We no longer do that, but we were still creating an empty map, passing it through and API that was more complicated than needed and copying it around. All this was removed. Also, remove one unused parameter, simplify regexes and fix a typo. --- cmd/ci-operator-prowgen/main.go | 27 ++++++++++----------------- cmd/ci-operator-prowgen/main_test.go | 13 ++++--------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/cmd/ci-operator-prowgen/main.go b/cmd/ci-operator-prowgen/main.go index 9262d03cac2..109cdbf7d38 100644 --- a/cmd/ci-operator-prowgen/main.go +++ b/cmd/ci-operator-prowgen/main.go @@ -115,7 +115,7 @@ func (o *options) process() error { // Generate a PodSpec that runs `ci-operator`, to be used in Presubmit/Postsubmit // Various pieces are derived from `org`, `repo`, `branch` and `target`. // `additionalArgs` are passed as additional arguments to `ci-operator` -func generatePodSpec(info *config.Info, target string) *kubeapi.PodSpec { +func generatePodSpec(info *config.Info) *kubeapi.PodSpec { configMapKeyRef := kubeapi.EnvVarSource{ ConfigMapKeyRef: &kubeapi.ConfigMapKeySelector{ LocalObjectReference: kubeapi.LocalObjectReference{ @@ -157,7 +157,7 @@ func generateCiOperatorPodSpec(info *config.Info, target string, additionalArgs } } - ret := generatePodSpec(info, target) + ret := generatePodSpec(info) ret.Containers[0].Command = []string{"ci-operator"} ret.Containers[0].Args = append([]string{ "--give-pr-author-access-to-namespace=true", @@ -313,7 +313,7 @@ func generatePodSpecTemplate(info *config.Info, release string, test *cioperator } func generatePodSpecRandom(info *config.Info, test *cioperatorapi.TestStepConfiguration) *kubeapi.PodSpec { - podSpec := generatePodSpec(info, test.As) + podSpec := generatePodSpec(info) for _, profile := range openshiftInstallerRandomProfiles { podSpec.Volumes = append(podSpec.Volumes, kubeapi.Volume{ Name: "cluster-profile-" + string(profile), @@ -425,20 +425,16 @@ func generatePostsubmitForTest( name string, info *config.Info, treatBranchesAsExplicit bool, - labels map[string]string, podSpec *kubeapi.PodSpec) *prowconfig.Postsubmit { - copiedLabels := make(map[string]string) - for k, v := range labels { - copiedLabels[k] = v - } - copiedLabels[jc.ProwJobLabelGenerated] = jc.Generated + labels := make(map[string]string) + labels[jc.ProwJobLabelGenerated] = jc.Generated branchName := jc.MakeRegexFilenameLabel(info.Branch) jobPrefix := fmt.Sprintf("branch-ci-%s-%s-%s-", info.Org, info.Repo, branchName) if len(info.Variant) > 0 { name = fmt.Sprintf("%s-%s", info.Variant, name) - copiedLabels[prowJobLabelVariant] = info.Variant + labels[prowJobLabelVariant] = info.Variant } jobName := fmt.Sprintf("%s%s", jobPrefix, name) if len(jobName) > 63 && len(jobPrefix) < 53 { @@ -458,7 +454,7 @@ func generatePostsubmitForTest( Agent: "kubernetes", Name: jobName, Spec: podSpec, - Labels: copiedLabels, + Labels: labels, UtilityConfig: prowconfig.UtilityConfig{ DecorationConfig: &v1.DecorationConfig{SkipCloning: &newTrue}, Decorate: true, @@ -472,7 +468,7 @@ func generatePostsubmitForTest( // should be tested, generate a following JobConfig: // // - one presubmit for each test defined in config file -// - if the config file has non-empty `images` section, generate an additinal +// - if the config file has non-empty `images` section, generate an additional // presubmit and postsubmit that has `--target=[images]`. This postsubmit // will additionally pass `--promote` to ci-operator func generateJobs( @@ -502,9 +498,6 @@ func generateJobs( } if len(configSpec.Images) > 0 { - // TODO: we should populate labels based on ci-operator characteristics - labels := map[string]string{} - // Identify which jobs need a to have a release payload explicitly requested var additionalPresubmitArgs []string if promotion.PromotesOfficialImages(configSpec) { @@ -521,7 +514,7 @@ func generateJobs( presubmits[orgrepo] = append(presubmits[orgrepo], *generatePresubmitForTest("images", info, generateCiOperatorPodSpec(info, "[images]", additionalPresubmitArgs...))) if configSpec.PromotionConfiguration != nil { - postsubmits[orgrepo] = append(postsubmits[orgrepo], *generatePostsubmitForTest("images", info, true, labels, generateCiOperatorPodSpec(info, "[images]", additionalPostsubmitArgs...))) + postsubmits[orgrepo] = append(postsubmits[orgrepo], *generatePostsubmitForTest("images", info, true, generateCiOperatorPodSpec(info, "[images]", additionalPostsubmitArgs...))) } } @@ -554,7 +547,7 @@ func getReleaseRepoDir(directory string) (string, error) { // simpleBranchRegexp matches a branch name that does not appear to be a regex (lacks wildcard, // group, or other modifiers). For instance, `master` is considered simple, `master-.*` would // not. -var simpleBranchRegexp = regexp.MustCompile(`^[\w\-\.]+$`) +var simpleBranchRegexp = regexp.MustCompile(`^[\w\-.]+$`) // makeBranchExplicit updates the provided branch to prevent wildcard matches to the given branch // if the branch value does not appear to contain an explicit regex pattern. I.e. 'master' diff --git a/cmd/ci-operator-prowgen/main_test.go b/cmd/ci-operator-prowgen/main_test.go index a96d374a5fd..509039fd8fd 100644 --- a/cmd/ci-operator-prowgen/main_test.go +++ b/cmd/ci-operator-prowgen/main_test.go @@ -504,7 +504,6 @@ func TestGeneratePostSubmitForTest(t *testing.T) { tests := []struct { name string repoInfo *config.Info - labels map[string]string treatBranchesAsExplicit bool @@ -517,7 +516,6 @@ func TestGeneratePostSubmitForTest(t *testing.T) { Repo: "repository", Branch: "branch", }, - labels: map[string]string{}, expected: &prowconfig.Postsubmit{ JobBase: prowconfig.JobBase{ @@ -540,13 +538,12 @@ func TestGeneratePostSubmitForTest(t *testing.T) { Repo: "Repository", Branch: "Branch", }, - labels: map[string]string{"artifacts": "images"}, expected: &prowconfig.Postsubmit{ JobBase: prowconfig.JobBase{ Agent: "kubernetes", Name: "branch-ci-Organization-Repository-Branch-Name", - Labels: map[string]string{"artifacts": "images", "ci-operator.openshift.io/prowgen-controlled": "true"}, + Labels: map[string]string{"ci-operator.openshift.io/prowgen-controlled": "true"}, UtilityConfig: prowconfig.UtilityConfig{ DecorationConfig: &v1.DecorationConfig{SkipCloning: &newTrue}, Decorate: true, @@ -561,7 +558,6 @@ func TestGeneratePostSubmitForTest(t *testing.T) { Repo: "Repository", Branch: "Branch", }, - labels: map[string]string{"artifacts": "images"}, treatBranchesAsExplicit: true, @@ -569,7 +565,7 @@ func TestGeneratePostSubmitForTest(t *testing.T) { JobBase: prowconfig.JobBase{ Agent: "kubernetes", Name: "branch-ci-Organization-Repository-Branch-name", - Labels: map[string]string{"artifacts": "images", "ci-operator.openshift.io/prowgen-controlled": "true"}, + Labels: map[string]string{"ci-operator.openshift.io/prowgen-controlled": "true"}, UtilityConfig: prowconfig.UtilityConfig{ DecorationConfig: &v1.DecorationConfig{SkipCloning: &newTrue}, Decorate: true, @@ -585,7 +581,6 @@ func TestGeneratePostSubmitForTest(t *testing.T) { Repo: "Repository", Branch: "Branch-.*", }, - labels: map[string]string{"artifacts": "images"}, treatBranchesAsExplicit: true, @@ -593,7 +588,7 @@ func TestGeneratePostSubmitForTest(t *testing.T) { JobBase: prowconfig.JobBase{ Agent: "kubernetes", Name: "branch-ci-Organization-Repository-Branch-name", - Labels: map[string]string{"artifacts": "images", "ci-operator.openshift.io/prowgen-controlled": "true"}, + Labels: map[string]string{"ci-operator.openshift.io/prowgen-controlled": "true"}, UtilityConfig: prowconfig.UtilityConfig{ DecorationConfig: &v1.DecorationConfig{SkipCloning: &newTrue}, Decorate: true, @@ -603,7 +598,7 @@ func TestGeneratePostSubmitForTest(t *testing.T) { }, } for _, tc := range tests { - postsubmit := generatePostsubmitForTest(tc.name, tc.repoInfo, tc.treatBranchesAsExplicit, tc.labels, nil) // podSpec tested in TestGeneratePodSpec + postsubmit := generatePostsubmitForTest(tc.name, tc.repoInfo, tc.treatBranchesAsExplicit, nil) // podSpec tested in TestGeneratePodSpec if !equality.Semantic.DeepEqual(postsubmit, tc.expected) { t.Errorf("expected postsubmit diff:\n%s", diff.ObjectDiff(tc.expected, postsubmit)) }