Skip to content

Commit

Permalink
Enforcement of single-default in Configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
chases2 committed Jul 26, 2019
1 parent 8880fc2 commit 5bd162c
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 166 deletions.
39 changes: 0 additions & 39 deletions config/testgrids/config.yaml
Expand Up @@ -9,47 +9,8 @@
# 3. Run config_test.go to make sure the config is valid.
#

# Default testgroup and dashboardtab, please do not change them
default_test_group:
days_of_results: 14 # Number of days of test results to gather and serve.
tests_name_policy: 2 # replace the name of the test
ignore_pending: false # Show in-progress tests.
column_header:
- configuration_value: Commit # Shows the commit number on column header
- configuration_value: infra-commit
num_columns_recent: 10
use_kubernetes_client: true # These two fields are deprecated and should always be true
is_external: true
alert_stale_results_hours: 0 # Don't alert for staleness by default.
num_failures_to_alert: 3 # Consider a test failed if it has 3 or more consecutive failures.
num_passes_to_disable_alert: 1 # Consider a failing test passing if it has 1 or more consecutive passes.
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.

default_dashboard_tab:
open_test_template: # The URL template to visit after clicking on a cell
url: https://prow.k8s.io/view/gcs/<gcs_prefix>/<changelist>
file_bug_template: # The URL template to visit when filing a bug
url: https://github.com/kubernetes/kubernetes/issues/new
options:
- key: title
value: 'E2E: <test-name>'
- key: body
value: <test-url>
attach_bug_template: # The URL template to visit when attaching a bug
url: # empty
options: #empty
results_text: See these results on Prow # Text to show in the about menu as a link to another view of the results
results_url_template: # The URL template to visit after clicking
url: https://prow.k8s.io/job-history/<gcs_prefix>
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.
num_columns_recent: 10
code_search_url_template: # The URL template to visit when searching for changelists
url: https://github.com/kubernetes/kubernetes/compare/<start-custom-0>...<end-custom-0>

#
# Start testgroups
#

# NOTE: If you're adding a periodic or postsubmit and don't want to specially configure your test
# group, you don't need to add it here: we implicitly assume a testgroup exists for all periodics
# and postsubmits. You still need to add presubmits here, and all jobs still need to be added to a
Expand Down
38 changes: 38 additions & 0 deletions config/testgrids/default.yaml
@@ -0,0 +1,38 @@
# Default testgroup and dashboardtab, please do not change them
# In this repository, if you don't set something in your configuration file or prow job, it will use the value here

default_test_group:
days_of_results: 14 # Number of days of test results to gather and serve.
tests_name_policy: 2 # replace the name of the test
ignore_pending: false # Show in-progress tests.
column_header:
- configuration_value: Commit # Shows the commit number on column header
- configuration_value: infra-commit
num_columns_recent: 10
use_kubernetes_client: true # These two fields are deprecated and should always be true
is_external: true
alert_stale_results_hours: 0 # Don't alert for staleness by default.
num_failures_to_alert: 3 # Consider a test failed if it has 3 or more consecutive failures.
num_passes_to_disable_alert: 1 # Consider a failing test passing if it has 1 or more consecutive passes.
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.

default_dashboard_tab:
open_test_template: # The URL template to visit after clicking on a cell
url: https://prow.k8s.io/view/gcs/<gcs_prefix>/<changelist>
file_bug_template: # The URL template to visit when filing a bug
url: https://github.com/kubernetes/kubernetes/issues/new
options:
- key: title
value: 'E2E: <test-name>'
- key: body
value: <test-url>
attach_bug_template: # The URL template to visit when attaching a bug
url: # empty
options: #empty
results_text: See these results on Prow # Text to show in the about menu as a link to another view of the results
results_url_template: # The URL template to visit after clicking
url: https://prow.k8s.io/job-history/<gcs_prefix>
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.
num_columns_recent: 10
code_search_url_template: # The URL template to visit when searching for changelists
url: https://github.com/kubernetes/kubernetes/compare/<start-custom-0>...<end-custom-0>
37 changes: 0 additions & 37 deletions config/testgrids/generated-test-config.yaml
@@ -1,42 +1,5 @@
# AUTO-GENERATED by experiment/generate_tests.py - DO NOT EDIT.

default_test_group:
days_of_results: 14 # Number of days of test results to gather and serve.
tests_name_policy: 2 # replace the name of the test
ignore_pending: false # Show in-progress tests.
column_header:
- configuration_value: Commit # Shows the commit number on column header
- configuration_value: infra-commit
num_columns_recent: 10
use_kubernetes_client: true # These two fields are deprecated and should always be true
is_external: true
alert_stale_results_hours: 0 # Don't alert for staleness by default.
num_failures_to_alert: 3 # Consider a test failed if it has 3 or more consecutive failures.
num_passes_to_disable_alert: 1 # A failing test passes if it has 1 or more consecutive passes.
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.

default_dashboard_tab:
open_test_template: # The URL template to visit after clicking on a cell
url: https://prow.k8s.io/view/gcs/<gcs_prefix>/<changelist>
file_bug_template: # The URL template to visit when filing a bug
url: https://github.com/kubernetes/kubernetes/issues/new
options:
- key: title
value: 'E2E: <test-name>'
- key: body
value: <test-url>
attach_bug_template: # The URL template to visit when attaching a bug
url: # empty
options: #empty
results_text: See these results on Prow # Shown in the about menu as a link to view the results
results_url_template: # The URL template to visit after clicking
url: https://prow.k8s.io/job-history/<gcs_prefix>
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.
num_columns_recent: 10
code_search_url_template: # The URL template to visit when searching for changelists
url: https://github.com/kubernetes/kubernetes/compare/<start-custom-0>...<end-custom-0>


test_groups:
- name: ci-kubernetes-e2e-gke-cos2-k8sstable1-slow
gcs_prefix: kubernetes-jenkins/logs/ci-kubernetes-e2e-gke-cos2-k8sstable1-slow
Expand Down
42 changes: 1 addition & 41 deletions experiment/generate_tests.py
Expand Up @@ -63,46 +63,6 @@

COMMENT = 'AUTO-GENERATED by experiment/generate_tests.py - DO NOT EDIT.'

TESTGRID_CONFIG_PREAMBLE = COMMENT + """
default_test_group:
days_of_results: 14 # Number of days of test results to gather and serve.
tests_name_policy: 2 # replace the name of the test
ignore_pending: false # Show in-progress tests.
column_header:
- configuration_value: Commit # Shows the commit number on column header
- configuration_value: infra-commit
num_columns_recent: 10
use_kubernetes_client: true # These two fields are deprecated and should always be true
is_external: true
alert_stale_results_hours: 0 # Don't alert for staleness by default.
num_failures_to_alert: 3 # Consider a test failed if it has 3 or more consecutive failures.
num_passes_to_disable_alert: 1 # A failing test passes if it has 1 or more consecutive passes.
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.
default_dashboard_tab:
open_test_template: # The URL template to visit after clicking on a cell
url: https://prow.k8s.io/view/gcs/<gcs_prefix>/<changelist>
file_bug_template: # The URL template to visit when filing a bug
url: https://github.com/kubernetes/kubernetes/issues/new
options:
- key: title
value: 'E2E: <test-name>'
- key: body
value: <test-url>
attach_bug_template: # The URL template to visit when attaching a bug
url: # empty
options: #empty
results_text: See these results on Prow # Shown in the about menu as a link to view the results
results_url_template: # The URL template to visit after clicking
url: https://prow.k8s.io/job-history/<gcs_prefix>
code_search_path: github.com/kubernetes/kubernetes/search # URL for regression search links.
num_columns_recent: 10
code_search_url_template: # The URL template to visit when searching for changelists
url: https://github.com/kubernetes/kubernetes/compare/<start-custom-0>...<end-custom-0>
"""


def get_sha1_hash(data):
"""Returns the SHA1 hash of the specified data."""
sha1_hash = hashlib.sha1()
Expand Down Expand Up @@ -131,7 +91,7 @@ def write_prow_configs_file(output_file, job_defs):
def write_testgrid_config_file(output_file, testgrid_config):
"""Writes the TestGrid test group configurations into output_file."""
with open(output_file, 'w') as fp:
fp.write('# ' + TESTGRID_CONFIG_PREAMBLE + '\n\n')
fp.write('# ' + COMMENT + '\n\n')
yaml.dump(
testgrid_config, fp, Dumper=yaml.RoundTripDumper, width=float("inf"))

Expand Down
22 changes: 16 additions & 6 deletions testgrid/cmd/configurator/config_test.go
Expand Up @@ -18,14 +18,14 @@ package main

import (
"fmt"
"io/ioutil"
"net/mail"
"os"
"path/filepath"
"regexp"
"strings"
"testing"

"path/filepath"

"k8s.io/apimachinery/pkg/util/sets"

prow_config "k8s.io/test-infra/prow/config"
Expand Down Expand Up @@ -64,8 +64,9 @@ var (
)

const (
prowPath = "../../../prow/config.yaml"
jobPath = "../../../config/jobs"
prowPath = "../../../prow/config.yaml"
jobPath = "../../../config/jobs"
defaultPath = "../../../config/testgrids/default.yaml"
)

// Shared testgrid config, loaded at TestMain.
Expand All @@ -74,8 +75,17 @@ var cfg *config_pb.Configuration
func TestMain(m *testing.M) {
//make sure we can parse configurations
yamlFiles := []string{"../../../config/testgrids"}
c, err := readConfig(yamlFiles)

var c Config
b, err := ioutil.ReadFile(defaultPath)
if err != nil {
fmt.Printf("Could not read default config: %v", err)
}
if err := c.UpdateDefaults(b); err != nil {
fmt.Printf("Could not update defaults: %v", err)
}

if err := readToConfig(&c, yamlFiles); err != nil {
fmt.Printf("Could not read testgrid config: %v", err)
os.Exit(1)
}
Expand All @@ -86,7 +96,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

if err := applyProwjobAnnotations(c, pca, true); err != nil {
if err := applyProwjobAnnotations(&c, pca); err != nil {
fmt.Printf("Couldn't apply prowjob annotations: %v", err)
os.Exit(1)
}
Expand Down
45 changes: 28 additions & 17 deletions testgrid/cmd/configurator/main.go
Expand Up @@ -62,6 +62,7 @@ type options struct {
writeYAML bool
prowConfig string
prowJobConfig string
defaultYAML string
}

func gatherOptions() (options, error) {
Expand All @@ -76,6 +77,7 @@ func gatherOptions() (options, error) {
flag.Var(&o.inputs, "yaml", "comma-separated list of input YAML files or directories")
flag.StringVar(&o.prowConfig, "prow-config", "", "path to the prow config file. Required by --prow-job-config")
flag.StringVar(&o.prowJobConfig, "prow-job-config", "", "path to the prow job config. If specified, incorporates testgrid annotations on prowjobs. Requires --prow-config.")
flag.StringVar(&o.defaultYAML, "default", "", "path to default settings; required for proto outputs")
flag.Parse()
if len(o.inputs) == 0 || o.inputs[0] == "" {
return o, errors.New("--yaml must include at least one file")
Expand All @@ -90,6 +92,10 @@ func gatherOptions() (options, error) {
if (o.prowConfig == "") != (o.prowJobConfig == "") {
return o, errors.New("--prow-config and --prow-job-config must be specified together")
}
if o.defaultYAML == "" && !o.writeYAML {
logrus.Warnf("--default not explicitly specified; assuming %s", o.inputs[0])
o.defaultYAML = o.inputs[0]
}
return o, nil
}

Expand Down Expand Up @@ -161,8 +167,7 @@ func announceProwChanges(ctx context.Context, pca *prowConfig.Agent, channel cha
}
}

func readConfig(paths []string) (*Config, error) {
var c Config
func readToConfig(c *Config, paths []string) error {
err := walkForYAMLFiles(paths, func(path string, info os.FileInfo) error {
// Read YAML file and update config
b, err := ioutil.ReadFile(path)
Expand All @@ -176,10 +181,7 @@ func readConfig(paths []string) (*Config, error) {
return nil
})

if err != nil {
return nil, err
}
return &c, nil
return err
}

// walks through paths and directories, calling the passed function on each YAML file
Expand Down Expand Up @@ -232,32 +234,41 @@ func write(ctx context.Context, client *storage.Client, path string, bytes []byt
}

func marshallYAML(c *Config) ([]byte, error) {
defBytes, err := yaml.Marshal(c.defaultConfig)
if err != nil {
return nil, fmt.Errorf("could not write default config to yaml: %v", err)
}
conBytes, err := yaml.Marshal(c.config)
bytes, err := yaml.Marshal(c.config)
if err != nil {
return nil, fmt.Errorf("could not write config to yaml: %v", err)
}
return append(defBytes, conBytes...), nil
return bytes, nil
}

// Ignores what changed for now and recomputes everything
func doOneshot(ctx context.Context, client *storage.Client, opt options, prowConfigAgent *prowConfig.Agent) error {
// Ignore what changed for now and just recompute everything
c, err := readConfig(opt.inputs)

// Read Data Sources: Default, YAML configs, Prow Annotations
var c Config
if opt.defaultYAML != "" {
b, err := ioutil.ReadFile(opt.defaultYAML)
if err != nil {
return err
}
if err := c.UpdateDefaults(b); err != nil {
return err
}
}

err := readToConfig(&c, opt.inputs)
if err != nil {
return fmt.Errorf("could not read config: %v", err)
}

if err := applyProwjobAnnotations(c, prowConfigAgent, !opt.writeYAML); err != nil {
if err := applyProwjobAnnotations(&c, prowConfigAgent); err != nil {
return fmt.Errorf("could not apply prowjob annotations: %v", err)
}

// Print proto if requested
if opt.printText {
if opt.writeYAML {
b, err := marshallYAML(c)
b, err := marshallYAML(&c)
if err != nil {
return fmt.Errorf("could not print yaml config: %v", err)
}
Expand All @@ -272,7 +283,7 @@ func doOneshot(ctx context.Context, client *storage.Client, opt options, prowCon
var b []byte
var err error
if opt.writeYAML {
b, err = marshallYAML(c)
b, err = marshallYAML(&c)
} else {
b, err = c.MarshalBytes()
}
Expand Down

0 comments on commit 5bd162c

Please sign in to comment.