Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gcp-e2e-kubernetes job #304

Merged
merged 4 commits into from Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -68,7 +68,7 @@ require (
github.com/mrunalp/fileutils v0.0.0-20200520151820-abd8a0e76976
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/mvdan/xurls v1.1.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/ginkgo v4.5.0-origin.1+incompatible
github.com/onsi/gomega v1.7.0
github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/runc v1.0.0-rc91.0.20200707015106-819fcc687efb
Expand Down Expand Up @@ -370,7 +370,7 @@ replace (
github.com/naoina/go-stringutil => github.com/naoina/go-stringutil v0.1.0
github.com/naoina/toml => github.com/naoina/toml v0.1.1
github.com/olekukonko/tablewriter => github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5
github.com/onsi/ginkgo => github.com/onsi/ginkgo v1.11.0
github.com/onsi/ginkgo => github.com/openshift/onsi-ginkgo v4.5.0-origin.1+incompatible
github.com/onsi/gomega => github.com/onsi/gomega v1.7.0
github.com/opencontainers/go-digest => github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/image-spec => github.com/opencontainers/image-spec v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -373,8 +373,6 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
Expand All @@ -398,6 +396,8 @@ github.com/openshift/golang-glog v0.0.0-20190322123450-3c92600d7533 h1:A5VovyRu3
github.com/openshift/golang-glog v0.0.0-20190322123450-3c92600d7533/go.mod h1:3sa6LKKRDnR1xy4Kn8htvPwqIOVwXh8fIU3LRY22q3U=
github.com/openshift/library-go v0.0.0-20200722204747-e3f2c82ff290 h1:x2MMkmR0gr+3UazejQcIafWCXh8d0W+6EWTtWLyGBnQ=
github.com/openshift/library-go v0.0.0-20200722204747-e3f2c82ff290/go.mod h1:/gVyoY2dl35bcCCgs+36UmGt6n/kn3f64hfDduujQ1c=
github.com/openshift/onsi-ginkgo v4.5.0-origin.1+incompatible h1:GtzyDU5vBFU40hz4GWd1qU5FJByNljWdgkM2LtdelGk=
github.com/openshift/onsi-ginkgo v4.5.0-origin.1+incompatible/go.mod h1:azqkkH4Vpp9A579CC26hicol/wViXag9rOwElif6v9E=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
Expand Down
1 change: 1 addition & 0 deletions hack/make-rules/test.sh
Expand Up @@ -52,6 +52,7 @@ kube::test::find_dirs() {
-o -path './third_party/*' \
-o -path './staging/*' \
-o -path './vendor/*' \
-o -path './openshift-hack/e2e/*' \
\) -prune \
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sed "s|^\./|${KUBE_GO_PACKAGE}/|" | LC_ALL=C sort -u

Expand Down
1 change: 1 addition & 0 deletions hack/make-rules/update.sh
Expand Up @@ -45,6 +45,7 @@ fi

# Skip bazel since it's not used downstream
BASH_TARGETS="
update-test-annotations
update-generated-protobuf
update-codegen
update-generated-runtime
Expand Down
1 change: 1 addition & 0 deletions hack/update-test-annotations.sh
1 change: 1 addition & 0 deletions hack/verify-test-annotations.sh
11 changes: 7 additions & 4 deletions openshift-hack/conformance-k8s.sh
Expand Up @@ -58,6 +58,7 @@ unschedulable="$( ( oc get nodes -o name -l 'node-role.kubernetes.io/master'; )
# Execute Kubernetes prerequisites
make WHAT=cmd/kubectl
make WHAT=test/e2e/e2e.test
make WHAT=vendor/github.com/onsi/ginkgo/ginkgo
PATH="${OS_ROOT}/_output/local/bin/$( os::build::host_platform ):${PATH}"
export PATH

Expand All @@ -72,17 +73,19 @@ rc=0
e2e_test="$( which e2e.test )"

# shellcheck disable=SC2086
${e2e_test} \
-num-nodes 1 -ginkgo.noColor '-ginkgo.focus=(\[Conformance\].*\[Serial\]|\[Serial\].*\[Conformance\])' \
ginkgo \
-nodes 1 -noColor '-focus=(\[Conformance\].*\[Serial\]|\[Serial\].*\[Conformance\])' \
${e2e_test} -- \
-report-dir "${test_report_dir}" \
-allowed-not-ready-nodes ${unschedulable} \
2>&1 | tee -a "${test_report_dir}/e2e.log" || rc=1

rename -v junit_ junit_serial_ "${test_report_dir}"/junit*.xml

# shellcheck disable=SC2086
${e2e_test} \
-num-nodes 4 -ginkgo.noColor '-ginkgo.skip=\[Serial\]' '-ginkgo.focus=\[Conformance\]' \
ginkgo \
-nodes 4 -noColor '-skip=\[Serial\]' '-focus=\[Conformance\]' \
${e2e_test} -- \
-report-dir "${test_report_dir}" \
-allowed-not-ready-nodes ${unschedulable} \
2>&1 | tee -a "${test_report_dir}/e2e.log" || rc=1
Expand Down
258 changes: 258 additions & 0 deletions openshift-hack/e2e/annotate/annotate.go
@@ -0,0 +1,258 @@
package annotate

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
"sort"
"strings"

"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/types"
)

var reHasSig = regexp.MustCompile(`\[sig-[\w-]+\]`)

// Run generates tests annotations for the targeted package.
func Run() {
if len(os.Args) != 2 && len(os.Args) != 3 {
fmt.Fprintf(os.Stderr, "error: requires exactly one argument\n")
os.Exit(1)
}
filename := os.Args[len(os.Args)-1]

generator := newGenerator()
ginkgo.WalkTests(generator.generateRename)

renamer := newRenamerFromGenerated(generator.output)
ginkgo.WalkTests(renamer.updateNodeText)
if len(renamer.missing) > 0 {
var names []string
for name := range renamer.missing {
names = append(names, name)
}
sort.Strings(names)
fmt.Fprintf(os.Stderr, "failed:\n%s\n", strings.Join(names, "\n"))
os.Exit(1)
}

// All tests must be associated with a sig (either upstream), or downstream
// If you get this error, you should add the [sig-X] tag to your test (if its
// in origin) or if it is upstream add a new rule to rules.go that assigns
// the test in question to the right sig.
//
// Upstream sigs map to teams (if you have representation on that sig, you
// own those tests in origin)
// Downstream sigs: sig-imageregistry, sig-builds, sig-devex
var errors []string
for from, to := range generator.output {
if !reHasSig.MatchString(from) && !reHasSig.MatchString(to) {
errors = append(errors, fmt.Sprintf("all tests must define a [sig-XXXX] tag or have a rule %q", from))
}
}
if len(errors) > 0 {
sort.Strings(errors)
for _, s := range errors {
fmt.Fprintf(os.Stderr, "failed: %s\n", s)
}
os.Exit(1)
}

var pairs []string
for from, to := range generator.output {
pairs = append(pairs, fmt.Sprintf("%q:\n%q,", from, to))
}
sort.Strings(pairs)
contents := fmt.Sprintf(`
package generated

import (
"fmt"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/types"
)

var annotations = map[string]string{
%s
}

func init() {
ginkgo.WalkTests(func(name, parentName string, node types.TestNode) {
combined := name
if len(parentName) > 0 {
combined = parentName + " " + combined
}
if updated, ok := annotations[combined]; ok {
node.SetText(updated)
} else {
panic(fmt.Sprintf("unable to find test %%s", combined))
}
})
}
`, strings.Join(pairs, "\n\n"))
if err := ioutil.WriteFile(filename, []byte(contents), 0644); err != nil {
fmt.Fprintf(os.Stderr, "error: %v", err)
os.Exit(1)
}
if _, err := exec.Command("gofmt", "-s", "-w", filename).Output(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v", err)
os.Exit(1)
}
}

func newGenerator() *ginkgoTestRenamer {
var allLabels []string
matches := make(map[string]*regexp.Regexp)
stringMatches := make(map[string][]string)
excludes := make(map[string]*regexp.Regexp)

for label, items := range TestMaps {
sort.Strings(items)
allLabels = append(allLabels, label)
var remain []string
for _, item := range items {
re := regexp.MustCompile(item)
if p, ok := re.LiteralPrefix(); ok {
stringMatches[label] = append(stringMatches[label], p)
} else {
remain = append(remain, item)
}
}
if len(remain) > 0 {
matches[label] = regexp.MustCompile(strings.Join(remain, `|`))
}
}
for label, items := range LabelExcludes {
sort.Strings(items)
excludes[label] = regexp.MustCompile(strings.Join(items, `|`))
}
sort.Strings(allLabels)

excludedTestsFilter := regexp.MustCompile(strings.Join(ExcludedTests, `|`))

return &ginkgoTestRenamer{
allLabels: allLabels,
stringMatches: stringMatches,
matches: matches,
excludes: excludes,
excludedTestsFilter: excludedTestsFilter,

output: make(map[string]string),
}
}

func newRenamerFromGenerated(names map[string]string) *ginkgoTestRenamer {
return &ginkgoTestRenamer{
output: names,
missing: make(map[string]struct{}),
}
}

type ginkgoTestRenamer struct {
allLabels []string
stringMatches map[string][]string
matches map[string]*regexp.Regexp
excludes map[string]*regexp.Regexp
excludedTestsFilter *regexp.Regexp

output map[string]string
missing map[string]struct{}
}

func (r *ginkgoTestRenamer) updateNodeText(name, parentName string, node types.TestNode) {
if updated, ok := r.output[combineNames(parentName, name)]; ok {
node.SetText(updated)
} else {
r.missing[combineNames(parentName, name)] = struct{}{}
}
}

func (r *ginkgoTestRenamer) generateRename(name, parentName string, node types.TestNode) {
originalName := name
combinedName := combineNames(parentName, name)

labels := ""
for {
count := 0
for _, label := range r.allLabels {
// never apply a sig label twice
if strings.HasPrefix(label, "[sig-") && strings.Contains(combinedName, "[sig-") {
continue
}
if strings.Contains(combinedName, label) {
continue
}

var hasLabel bool
for _, segment := range r.stringMatches[label] {
hasLabel = strings.Contains(combinedName, segment)
if hasLabel {
break
}
}
if !hasLabel {
if re := r.matches[label]; re != nil {
hasLabel = r.matches[label].MatchString(combinedName)
}
}

if hasLabel {
// TODO: remove when we no longer need it
if re, ok := r.excludes[label]; ok && re.MatchString(combinedName) {
continue
}
count++
labels += " " + label
combinedName += " " + label
name += " " + label
}
}
if count == 0 {
break
}
}

if !r.excludedTestsFilter.MatchString(combinedName) {
isSerial := strings.Contains(combinedName, "[Serial]")
isConformance := strings.Contains(combinedName, "[Conformance]")
switch {
case isSerial && isConformance:
name += " [Suite:openshift/conformance/serial/minimal]"
case isSerial:
name += " [Suite:openshift/conformance/serial]"
case isConformance:
name += " [Suite:openshift/conformance/parallel/minimal]"
default:
name += " [Suite:openshift/conformance/parallel]"
}
}
if isGoModulePath(node.CodeLocation().FileName, "github.com/openshift/origin", "test") && !strings.Contains(name, "[Suite:openshift") {
name += " [Suite:openshift]"
}
if isGoModulePath(node.CodeLocation().FileName, "k8s.io/kubernetes", "test/e2e") {
name += " [Suite:k8s]"
}

r.output[combineNames(parentName, originalName)] = name
}

// isGoModulePath returns true if the packagePath reported by reflection is within a
// module and given module path. When go mod is in use, module and modulePath are not
// contiguous as they were in older golang versions with vendoring, so naive contains
// tests fail.
//
// historically: ".../vendor/k8s.io/kubernetes/test/e2e"
// go.mod: "k8s.io/kubernetes@0.18.4/test/e2e"
//
func isGoModulePath(packagePath, module, modulePath string) bool {
return regexp.MustCompile(fmt.Sprintf(`\b%s(@[^/]*|)/%s\b`, regexp.QuoteMeta(module), regexp.QuoteMeta(modulePath))).MatchString(packagePath)
}

func combineNames(parentName, name string) string {
if len(parentName) == 0 {
return name
}
return parentName + " " + name
}
9 changes: 9 additions & 0 deletions openshift-hack/e2e/annotate/cmd/main.go
@@ -0,0 +1,9 @@
package main

import (
"k8s.io/kubernetes/openshift-hack/e2e/annotate"
)

func main() {
annotate.Run()
}