Skip to content

Commit 83565d5

Browse files
Merge pull request #2255 from smg247/native-skips
TRT-2066: Use OTE generated labels for skips in test-kubernetes-e2e.sh
2 parents 76a7b99 + 162e867 commit 83565d5

File tree

7 files changed

+81
-29
lines changed

7 files changed

+81
-29
lines changed

.openshift-tests-extension/openshift_payload_hyperkube.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80076,4 +80076,4 @@
8007680076
"source": "openshift:payload:hyperkube",
8007780077
"lifecycle": "blocking"
8007880078
}
80079-
]
80079+
]

openshift-hack/cmd/k8s-tests-ext/environment_selectors.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package main
22

3-
import et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
3+
import (
4+
"fmt"
5+
6+
et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
7+
)
48

59
// addEnvironmentSelectors adds the environmentSelector field to appropriate specs to facilitate including or excluding
610
// them based on attributes of the cluster they are running on
@@ -16,11 +20,11 @@ func addEnvironmentSelectors(specs et.ExtensionTestSpecs) {
1620
specs.SelectAny([]et.SelectFunction{ // Since these must use "NameContainsAll" they cannot be included in filterByPlatform
1721
et.NameContainsAll("[sig-network] LoadBalancers [Feature:LoadBalancer]", "UDP"),
1822
et.NameContainsAll("[sig-network] LoadBalancers [Feature:LoadBalancer]", "session affinity"),
19-
}).Exclude(et.PlatformEquals("aws"))
23+
}).Exclude(et.PlatformEquals("aws")).AddLabel("[Skipped:aws]")
2024

2125
specs.SelectAny([]et.SelectFunction{ // Since these must use "NameContainsAll" they cannot be included in filterByNetwork
2226
et.NameContainsAll("NetworkPolicy", "named port"),
23-
}).Exclude(et.NetworkEquals("OVNKubernetes"))
27+
}).Exclude(et.NetworkEquals("OVNKubernetes")).AddLabel("[Skipped:Network/OVNKubernetes]")
2428
}
2529

2630
// filterByPlatform is a helper function to do, simple, "NameContains" filtering on tests by platform
@@ -127,7 +131,9 @@ func filterByPlatform(specs et.ExtensionTestSpecs) {
127131
selectFunctions = append(selectFunctions, et.NameContains(exclusion))
128132
}
129133

130-
specs.SelectAny(selectFunctions).Exclude(et.PlatformEquals(platform))
134+
specs.SelectAny(selectFunctions).
135+
Exclude(et.PlatformEquals(platform)).
136+
AddLabel(fmt.Sprintf("[Skipped:%s]", platform))
131137
}
132138
}
133139

@@ -169,7 +175,9 @@ func filterByExternalConnectivity(specs et.ExtensionTestSpecs) {
169175
selectFunctions = append(selectFunctions, et.NameContains(exclusion))
170176
}
171177

172-
specs.SelectAny(selectFunctions).Exclude(et.ExternalConnectivityEquals(externalConnectivity))
178+
specs.SelectAny(selectFunctions).
179+
Exclude(et.ExternalConnectivityEquals(externalConnectivity)).
180+
AddLabel(fmt.Sprintf("[Skipped:%s]", externalConnectivity))
173181
}
174182
}
175183

@@ -198,7 +206,9 @@ func filterByTopology(specs et.ExtensionTestSpecs) {
198206
selectFunctions = append(selectFunctions, et.NameContains(exclusion))
199207
}
200208

201-
specs.SelectAny(selectFunctions).Exclude(et.TopologyEquals(topology))
209+
specs.SelectAny(selectFunctions).
210+
Exclude(et.TopologyEquals(topology)).
211+
AddLabel(fmt.Sprintf("[Skipped:%s]", topology))
202212
}
203213
}
204214

@@ -217,7 +227,9 @@ func filterByNoOptionalCapabilities(specs et.ExtensionTestSpecs) {
217227
for _, exclusion := range exclusions {
218228
selectFunctions = append(selectFunctions, et.NameContains(exclusion))
219229
}
220-
specs.SelectAny(selectFunctions).Exclude(et.NoOptionalCapabilitiesExist())
230+
specs.SelectAny(selectFunctions).
231+
Exclude(et.NoOptionalCapabilitiesExist()).
232+
AddLabel("[Skipped:NoOptionalCapabilities]")
221233
}
222234

223235
// filterByNetwork is a helper function to do, simple, "NameContains" filtering on tests by network
@@ -230,6 +242,8 @@ func filterByNetwork(specs et.ExtensionTestSpecs) {
230242
selectFunctions = append(selectFunctions, et.NameContains(exclusion))
231243
}
232244

233-
specs.SelectAny(selectFunctions).Exclude(et.NetworkEquals(network))
245+
specs.SelectAny(selectFunctions).
246+
Exclude(et.NetworkEquals(network)).
247+
AddLabel(fmt.Sprintf("[Skipped:%s]", network))
234248
}
235249
}

openshift-hack/cmd/k8s-tests-ext/k8s-tests.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"flag"
55
"os"
66
"reflect"
7+
"strconv"
78

9+
et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
810
"k8s.io/kubernetes/openshift-hack/e2e/annotate/generated"
911
"k8s.io/kubernetes/test/e2e/framework"
1012

@@ -14,7 +16,6 @@ import (
1416
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
1517
"github.com/openshift-eng/openshift-tests-extension/pkg/extension"
1618
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
17-
et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
1819
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
1920
v "github.com/openshift-eng/openshift-tests-extension/pkg/version"
2021

@@ -97,11 +98,21 @@ func main() {
9798
// the environmental skip code from the enhancement once its implemented.
9899
// - Make sure to account for test renames that occur because of removal of these
99100
// annotations
100-
specs.Walk(func(spec *et.ExtensionTestSpec) {
101-
if annotations, ok := generated.Annotations[spec.Name]; ok {
102-
spec.Name += annotations
101+
var omitAnnotations bool
102+
omitAnnotationsVal := os.Getenv("OMIT_ANNOTATIONS")
103+
if omitAnnotationsVal != "" {
104+
omitAnnotations, err = strconv.ParseBool(omitAnnotationsVal)
105+
if err != nil {
106+
panic("Failed to parse OMIT_ANNOTATIONS: " + err.Error())
103107
}
104-
})
108+
}
109+
if !omitAnnotations {
110+
specs.Walk(func(spec *et.ExtensionTestSpec) {
111+
if annotations, ok := generated.Annotations[spec.Name]; ok {
112+
spec.Name += annotations
113+
}
114+
})
115+
}
105116

106117
specs = filterOutDisabledSpecs(specs)
107118
addLabelsToSpecs(specs)

openshift-hack/cmd/k8s-tests-ext/labels.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
func addLabelsToSpecs(specs et.ExtensionTestSpecs) {
88
var namesByLabel = map[string][]string{
99
// tests too slow to be part of conformance
10-
"Slow": {
10+
"[Slow]": {
1111
"[sig-scalability]", // disable from the default set for now
1212
"should create and stop a working application", // Inordinately slow tests
1313

@@ -16,13 +16,13 @@ func addLabelsToSpecs(specs et.ExtensionTestSpecs) {
1616
"validates that there exists conflict between pods with same hostPort and protocol but one using 0.0.0.0 hostIP", // 5m, really?
1717
},
1818
// tests that are known flaky
19-
"Flaky": {
19+
"[Flaky]": {
2020
"Job should run a job to completion when tasks sometimes fail and are not locally restarted", // seems flaky, also may require too many resources
2121
// TODO(node): test works when run alone, but not in the suite in CI
2222
"[Feature:HPA] Horizontal pod autoscaling (scale resource: CPU) [sig-autoscaling] ReplicationController light Should scale from 1 pod to 2 pods",
2323
},
2424
// tests that must be run without competition
25-
"Serial": {
25+
"[Serial]": {
2626
"[Disruptive]",
2727
"[Feature:Performance]", // requires isolation
2828

openshift-hack/e2e/kube_e2e_test.go

+34-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package e2e
22

3-
//go:generate go run -mod vendor ./annotate/cmd -- ./annotate/generated/zz_generated.annotations.go
4-
53
// This file duplicates most of test/e2e/e2e_test.go but limits the included
64
// tests (via include.go) to tests that are relevant to openshift.
75

86
import (
97
"context"
8+
"encoding/json"
109
"flag"
1110
"fmt"
1211
"math/rand"
1312
"os"
13+
"os/exec"
1414
"strings"
1515
"testing"
1616
"time"
1717

18+
et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
1819
"gopkg.in/yaml.v2"
19-
2020
// Never, ever remove the line with "/ginkgo". Without it,
2121
// the ginkgo test runner will not detect that this
2222
// directory contains a Ginkgo test suite.
@@ -35,9 +35,6 @@ import (
3535
e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests"
3636
testfixtures "k8s.io/kubernetes/test/fixtures"
3737
"k8s.io/kubernetes/test/utils/image"
38-
39-
// Ensure test annotation
40-
"k8s.io/kubernetes/openshift-hack/e2e/annotate/generated"
4138
)
4239

4340
func TestMain(m *testing.M) {
@@ -109,17 +106,43 @@ func TestMain(m *testing.M) {
109106
}
110107

111108
func TestE2E(t *testing.T) {
112-
// TODO(soltysh): this is raw copy from end of openshift-hack/e2e/annotate/generated/zz_generated.annotations.go
113-
// https://issues.redhat.com/browse/OCPBUGS-25641
109+
// In order to properly skip tests, we must add the labels that the OTE external binary supplies to the test name
110+
// This will then be used by Ginkgo to skip specific tests
111+
oteCmd := exec.Command("k8s-tests-ext", "list", "tests")
112+
// We can't have OTE also add annotations to the spec names to map to labels, or they won't match the actual spec names
113+
//TODO(sgoeddel): once annotation logic is removed, this can be as well
114+
oteCmd.Env = append(oteCmd.Env, "OMIT_ANNOTATIONS=true")
115+
oteCmd.Stderr = os.Stderr
116+
output, err := oteCmd.Output()
117+
if err != nil {
118+
t.Fatalf("Error running ote list tests command: %v", err)
119+
}
120+
var specs et.ExtensionTestSpecs
121+
if err = json.Unmarshal(output, &specs); err != nil {
122+
t.Fatalf("Error parsing ote list tests output: %v", err)
123+
}
124+
125+
nameToLabels := make(map[string][]string, len(specs))
126+
for _, spec := range specs {
127+
nameToLabels[spec.Name] = spec.Labels.UnsortedList()
128+
}
129+
114130
ginkgo.GetSuite().SetAnnotateFn(func(name string, node types.TestSpec) {
115-
if newLabels, ok := generated.Annotations[name]; ok {
116-
node.AppendText(newLabels)
131+
if newLabels, ok := nameToLabels[name]; ok {
132+
for _, label := range newLabels {
133+
// Only add the label to the name if it isn't already present to avoid test names that are too long
134+
if !strings.Contains(name, label) {
135+
node.AppendText(fmt.Sprintf(" %s", label))
136+
}
137+
}
117138
} else {
118-
panic(fmt.Sprintf("unable to find test %s", name))
139+
// If the name isn't found in the mapping, it is because the test has been disabled via OTE
140+
node.AppendText(" [Disabled:missing]")
119141
}
120142
if strings.Contains(name, "Kubectl client Kubectl prune with applyset should apply and prune objects") {
121143
fmt.Printf("Trying to annotate %q\n", name)
122144
}
145+
123146
})
124147

125148
e2e.RunE2ETests(t)

openshift-hack/images/tests/Dockerfile.rhel

+3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ WORKDIR /go/src/k8s.io/kubernetes
33
COPY . .
44
RUN make WHAT=openshift-hack/e2e/k8s-e2e.test; \
55
make WHAT=vendor/github.com/onsi/ginkgo/v2/ginkgo; \
6+
make WHAT=openshift-hack/cmd/k8s-tests-ext; \
67
mkdir -p /tmp/build; \
78
cp /go/src/k8s.io/kubernetes/_output/local/bin/linux/$(go env GOARCH)/k8s-e2e.test /tmp/build/; \
89
cp /go/src/k8s.io/kubernetes/_output/local/bin/linux/$(go env GOARCH)/ginkgo /tmp/build/; \
10+
cp /go/src/k8s.io/kubernetes/_output/local/bin/linux/$(go env GOARCH)/k8s-tests-ext /tmp/build/; \
911
cp /go/src/k8s.io/kubernetes/openshift-hack/test-kubernetes-e2e.sh /tmp/build/; \
1012
cp /go/src/k8s.io/kubernetes/openshift-hack/images/kube-proxy/test-kube-proxy.sh /tmp/build/
1113

1214
FROM registry.ci.openshift.org/ocp/4.19:tools
1315
COPY --from=builder /tmp/build/k8s-e2e.test /usr/bin/
1416
COPY --from=builder /tmp/build/ginkgo /usr/bin/
17+
COPY --from=builder /tmp/build/k8s-tests-ext /usr/bin/
1518
COPY --from=builder /tmp/build/test-kubernetes-e2e.sh /usr/bin/
1619
COPY --from=builder /tmp/build/test-kube-proxy.sh /usr/bin/
1720
RUN yum install --setopt=tsflags=nodocs -y git gzip util-linux && yum clean all && rm -rf /var/cache/yum/* && \

openshift-hack/test-kubernetes-e2e.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ esac
5454
# -skip and -focus.
5555
KUBE_E2E_TEST_ARGS="${KUBE_E2E_TEST_ARGS:-${DEFAULT_TEST_ARGS}}"
5656

57-
# k8s-e2e.test and ginkgo are expected to be in the path in
57+
# k8s-e2e.test, ginkgo, and k8s-tests-ext are expected to be in the path in
5858
# CI. Outside of CI, ensure k8s-e2e.test and ginkgo are built and
5959
# available in PATH.
6060
if ! which k8s-e2e.test &> /dev/null; then
6161
make WHAT=vendor/github.com/onsi/ginkgo/v2/ginkgo
6262
make WHAT=openshift-hack/e2e/k8s-e2e.test
63+
make WHAT=openshift-hack/cmd/k8s-tests-ext
6364
ROOT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd -P)"
6465
PATH="${ROOT_PATH}/_output/local/bin/$(go env GOHOSTOS)/$(go env GOARCH):${PATH}"
6566
export PATH

0 commit comments

Comments
 (0)