Skip to content

Commit 29c14d2

Browse files
committed
UPSTREAM: <carry>: add openshift-tests-extension compatible binary
1 parent 8540bd4 commit 29c14d2

File tree

40 files changed

+133277
-37
lines changed

40 files changed

+133277
-37
lines changed

.openshift-tests-extension/openshift_payload_hyperkube.json

Lines changed: 132871 additions & 0 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
github.com/moby/ipvs v1.1.0
4545
github.com/mrunalp/fileutils v0.5.1
4646
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
47-
github.com/onsi/ginkgo/v2 v2.17.2
47+
github.com/onsi/ginkgo/v2 v2.6.1-0.20241002180654-3ded579fec72
4848
github.com/onsi/gomega v1.33.1
4949
github.com/opencontainers/runc v1.1.13
5050
github.com/opencontainers/selinux v1.11.0
@@ -191,6 +191,7 @@ require (
191191
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
192192
github.com/opencontainers/go-digest v1.0.0 // indirect
193193
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 // indirect
194+
github.com/openshift-eng/openshift-tests-extension v0.0.0-20241008125406-e4e57f0bc1e8
194195
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
195196
github.com/pquerna/cachecontrol v0.1.0 // indirect
196197
github.com/prometheus/procfs v0.15.1 // indirect
@@ -234,7 +235,7 @@ require (
234235

235236
replace (
236237
github.com/google/cadvisor => github.com/openshift/google-cadvisor v0.49.0-openshift-4.17-2
237-
github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20240806135314-3946b2b7b2a8
238+
github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241002180654-3ded579fec72
238239
k8s.io/api => ./staging/src/k8s.io/api
239240
k8s.io/apiextensions-apiserver => ./staging/src/k8s.io/apiextensions-apiserver
240241
k8s.io/apimachinery => ./staging/src/k8s.io/apimachinery

hack/lib/golang.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ kube::golang::server_targets() {
8080
cluster/gce/gci/mounter
8181
cmd/watch-termination
8282
openshift-hack/cmd/k8s-tests
83+
openshift-hack/cmd/k8s-tests-ext
8384
)
8485
echo "${targets[@]}"
8586
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/spf13/pflag"
8+
9+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
10+
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
11+
"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
12+
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
13+
v "github.com/openshift-eng/openshift-tests-extension/pkg/version"
14+
15+
"k8s.io/client-go/pkg/version"
16+
utilflag "k8s.io/component-base/cli/flag"
17+
"k8s.io/component-base/logs"
18+
"k8s.io/kubernetes/openshift-hack/e2e/annotate/generated"
19+
20+
// initialize framework extensions
21+
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
22+
_ "k8s.io/kubernetes/test/e2e/framework/metrics/init"
23+
)
24+
25+
func main() {
26+
logs.InitLogs()
27+
defer logs.FlushLogs()
28+
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
29+
30+
// Get version info from kube
31+
kubeVersion := version.Get()
32+
v.GitTreeState = kubeVersion.GitTreeState
33+
v.BuildDate = kubeVersion.BuildDate
34+
v.CommitFromGit = kubeVersion.GitCommit
35+
36+
// Create our registry of openshift-tests extensions
37+
extensionRegistry := e.NewRegistry()
38+
kubeTestsExtension := e.NewExtension("openshift", "payload", "hyperkube")
39+
extensionRegistry.Register(kubeTestsExtension)
40+
41+
// Carve up the kube tests into our openshift suites...
42+
kubeTestsExtension.AddSuite(e.Suite{
43+
Name: "kubernetes/conformance/parallel",
44+
Parents: []string{
45+
"openshift/conformance/parallel",
46+
"openshift/conformance/parallel/minimal",
47+
},
48+
Qualifiers: []string{`!labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance"`},
49+
})
50+
51+
kubeTestsExtension.AddSuite(e.Suite{
52+
Name: "kubernetes/conformance/serial",
53+
Parents: []string{
54+
"openshift/conformance/serial",
55+
"openshift/conformance/serial/minimal",
56+
},
57+
Qualifiers: []string{`labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance"`},
58+
})
59+
60+
//FIXME(stbenjam): what other suites does k8s-test contribute to?
61+
62+
// Build our specs from ginkgo
63+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
64+
if err != nil {
65+
panic(err)
66+
}
67+
68+
// Initialization for kube ginkgo test framework needs to run before all tests execute
69+
specs.AddBeforeAll(func() {
70+
if err := initializeTestFramework(os.Getenv("TEST_PROVIDER")); err != nil {
71+
panic(err)
72+
}
73+
})
74+
75+
// Annotations get appended to test names, these are additions to upstream
76+
// tests for controlling skips, suite membership, etc.
77+
//
78+
// TODO:
79+
// - Remove this annotation code, and migrate to Labels/Tags and
80+
// the environmental skip code from the enhancement once its implemented.
81+
// - Make sure to account for test renames that occur because of removal of these
82+
// annotations
83+
specs.Walk(func(spec *extensiontests.ExtensionTestSpec) {
84+
if annotations, ok := generated.Annotations[spec.Name]; ok {
85+
spec.Name += annotations
86+
}
87+
})
88+
89+
kubeTestsExtension.AddSpecs(specs)
90+
91+
// Cobra stuff
92+
root := &cobra.Command{
93+
Long: "Kubernetes tests extension for OpenShift",
94+
}
95+
96+
root.AddCommand(
97+
cmd.DefaultExtensionCommands(extensionRegistry)...,
98+
)
99+
100+
if err := func() error {
101+
return root.Execute()
102+
}(); err != nil {
103+
os.Exit(1)
104+
}
105+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
11+
"github.com/onsi/ginkgo/v2"
12+
"github.com/onsi/gomega"
13+
14+
corev1 "k8s.io/api/core/v1"
15+
kclientset "k8s.io/client-go/kubernetes"
16+
"k8s.io/client-go/tools/clientcmd"
17+
"k8s.io/kubernetes/openshift-hack/e2e"
18+
conformancetestdata "k8s.io/kubernetes/test/conformance/testdata"
19+
"k8s.io/kubernetes/test/e2e/framework"
20+
"k8s.io/kubernetes/test/e2e/framework/testfiles"
21+
"k8s.io/kubernetes/test/e2e/storage/external"
22+
e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests"
23+
testfixtures "k8s.io/kubernetes/test/fixtures"
24+
25+
// this appears to inexplicably auto-register global flags.
26+
_ "k8s.io/kubernetes/test/e2e/storage/drivers"
27+
28+
// these are loading important global flags that we need to get and set
29+
_ "k8s.io/kubernetes/test/e2e"
30+
_ "k8s.io/kubernetes/test/e2e/lifecycle"
31+
)
32+
33+
// copied directly from github.com/openshift/origin/cmd/openshift-tests/provider.go
34+
// and github.com/openshift/origin/test/extended/util/test.go
35+
func initializeTestFramework(provider string) error {
36+
providerInfo := &ClusterConfiguration{}
37+
if err := json.Unmarshal([]byte(provider), &providerInfo); err != nil {
38+
return fmt.Errorf("provider must be a JSON object with the 'type' key at a minimum: %v", err)
39+
}
40+
if len(providerInfo.ProviderName) == 0 {
41+
return fmt.Errorf("provider must be a JSON object with the 'type' key")
42+
}
43+
config := &ClusterConfiguration{}
44+
if err := json.Unmarshal([]byte(provider), config); err != nil {
45+
return fmt.Errorf("provider must decode into the ClusterConfig object: %v", err)
46+
}
47+
48+
// update testContext with loaded config
49+
testContext := &framework.TestContext
50+
testContext.Provider = config.ProviderName
51+
testContext.CloudConfig = framework.CloudConfig{
52+
ProjectID: config.ProjectID,
53+
Region: config.Region,
54+
Zone: config.Zone,
55+
Zones: config.Zones,
56+
NumNodes: config.NumNodes,
57+
MultiMaster: config.MultiMaster,
58+
MultiZone: config.MultiZone,
59+
ConfigFile: config.ConfigFile,
60+
}
61+
testContext.AllowedNotReadyNodes = -1
62+
testContext.MinStartupPods = -1
63+
testContext.MaxNodesToGather = 0
64+
testContext.KubeConfig = os.Getenv("KUBECONFIG")
65+
66+
// allow the CSI tests to access test data, but only briefly
67+
// TODO: ideally CSI would not use any of these test methods
68+
// var err error
69+
// exutil.WithCleanup(func() { err = initCSITests(dryRun) })
70+
// TODO: for now I'm only initializing CSI directly, but we probably need that
71+
// WithCleanup here as well
72+
if err := initCSITests(); err != nil {
73+
return err
74+
}
75+
76+
if ad := os.Getenv("ARTIFACT_DIR"); len(strings.TrimSpace(ad)) == 0 {
77+
os.Setenv("ARTIFACT_DIR", filepath.Join(os.TempDir(), "artifacts"))
78+
}
79+
80+
testContext.DeleteNamespace = os.Getenv("DELETE_NAMESPACE") != "false"
81+
testContext.VerifyServiceAccount = true
82+
testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS())
83+
testfiles.AddFileSource(testfixtures.GetTestFixturesFS())
84+
testfiles.AddFileSource(conformancetestdata.GetConformanceTestdataFS())
85+
testContext.KubectlPath = "kubectl"
86+
// context.KubeConfig = KubeConfigPath()
87+
testContext.KubeConfig = os.Getenv("KUBECONFIG")
88+
89+
// "debian" is used when not set. At least GlusterFS tests need "custom".
90+
// (There is no option for "rhel" or "centos".)
91+
testContext.NodeOSDistro = "custom"
92+
testContext.MasterOSDistro = "custom"
93+
94+
// load and set the host variable for kubectl
95+
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: testContext.KubeConfig}, &clientcmd.ConfigOverrides{})
96+
cfg, err := clientConfig.ClientConfig()
97+
if err != nil {
98+
return err
99+
}
100+
testContext.Host = cfg.Host
101+
102+
// Ensure that Kube tests run privileged (like they do upstream)
103+
testContext.CreateTestingNS = func(ctx context.Context, baseName string, c kclientset.Interface, labels map[string]string) (*corev1.Namespace, error) {
104+
return e2e.CreateTestingNS(ctx, baseName, c, labels, true)
105+
}
106+
107+
gomega.RegisterFailHandler(ginkgo.Fail)
108+
109+
framework.AfterReadingAllFlags(testContext)
110+
testContext.DumpLogsOnFailure = true
111+
112+
// these constants are taken from kube e2e and used by tests
113+
testContext.IPFamily = "ipv4"
114+
if config.HasIPv6 && !config.HasIPv4 {
115+
testContext.IPFamily = "ipv6"
116+
}
117+
118+
testContext.ReportDir = os.Getenv("TEST_JUNIT_DIR")
119+
120+
return nil
121+
}
122+
123+
const (
124+
manifestEnvVar = "TEST_CSI_DRIVER_FILES"
125+
)
126+
127+
// copied directly from github.com/openshift/origin/cmd/openshift-tests/csi.go
128+
// Initialize openshift/csi suite, i.e. define CSI tests from TEST_CSI_DRIVER_FILES.
129+
func initCSITests() error {
130+
manifestList := os.Getenv(manifestEnvVar)
131+
if manifestList != "" {
132+
manifests := strings.Split(manifestList, ",")
133+
for _, manifest := range manifests {
134+
if err := external.AddDriverDefinition(manifest); err != nil {
135+
return fmt.Errorf("failed to load manifest from %q: %s", manifest, err)
136+
}
137+
// Register the base dir of the manifest file as a file source.
138+
// With this we can reference the CSI driver's storageClass
139+
// in the manifest file (FromFile field).
140+
testfiles.AddFileSource(testfiles.RootFileSource{
141+
Root: filepath.Dir(manifest),
142+
})
143+
}
144+
}
145+
146+
return nil
147+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
// copied directly from github.com/openshift/origin/test/extended/util/cluster/cluster.go
4+
type ClusterConfiguration struct {
5+
ProviderName string `json:"type"`
6+
7+
// These fields (and the "type" tag for ProviderName) chosen to match
8+
// upstream's e2e.CloudConfig.
9+
ProjectID string
10+
Region string
11+
Zone string
12+
NumNodes int
13+
MultiMaster bool
14+
MultiZone bool
15+
Zones []string
16+
ConfigFile string
17+
18+
// Disconnected is set for test jobs without external internet connectivity
19+
Disconnected bool
20+
21+
// SingleReplicaTopology is set for disabling disruptive tests or tests
22+
// that require high availability
23+
SingleReplicaTopology bool
24+
25+
// NetworkPlugin is the "official" plugin name
26+
NetworkPlugin string
27+
// NetworkPluginMode is an optional sub-identifier for the NetworkPlugin.
28+
// (Currently it is only used for OpenShiftSDN.)
29+
NetworkPluginMode string `json:",omitempty"`
30+
31+
// HasIPv4 and HasIPv6 determine whether IPv4-specific, IPv6-specific,
32+
// and dual-stack-specific tests are run
33+
HasIPv4 bool
34+
HasIPv6 bool
35+
36+
// HasSCTP determines whether SCTP connectivity tests can be run in the cluster
37+
HasSCTP bool
38+
39+
// IsProxied determines whether we are accessing the cluster through an HTTP proxy
40+
IsProxied bool
41+
42+
// IsIBMROKS determines whether the cluster is Managed IBM Cloud (ROKS)
43+
IsIBMROKS bool
44+
45+
// IsNoOptionalCapabilities indicates the cluster has no optional capabilities enabled
46+
HasNoOptionalCapabilities bool
47+
}

openshift-hack/e2e/annotate/rules_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func (n *testNode) AppendText(text string) {
2222
n.text += text
2323
}
2424

25+
func (n *testNode) Labels() []string {
26+
return nil
27+
}
28+
2529
func TestStockRules(t *testing.T) {
2630
tests := []struct {
2731
name string

openshift-hack/images/hyperkube/Dockerfile.rhel

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.18 AS builder
22
WORKDIR /go/src/k8s.io/kubernetes
33
COPY . .
4-
RUN make WHAT='cmd/kube-apiserver cmd/kube-controller-manager cmd/kube-scheduler cmd/kubelet cmd/watch-termination openshift-hack/cmd/k8s-tests' && \
4+
RUN make WHAT='cmd/kube-apiserver cmd/kube-controller-manager cmd/kube-scheduler cmd/kubelet cmd/watch-termination openshift-hack/cmd/k8s-tests openshift-hack/cmd/k8s-tests-ext' && \
55
mkdir -p /tmp/build && \
66
cp openshift-hack/images/hyperkube/hyperkube openshift-hack/images/hyperkube/kubensenter /tmp/build && \
7-
cp /go/src/k8s.io/kubernetes/_output/local/bin/linux/$(go env GOARCH)/{kube-apiserver,kube-controller-manager,kube-scheduler,kubelet,watch-termination,k8s-tests} \
8-
/tmp/build
7+
cp /go/src/k8s.io/kubernetes/_output/local/bin/linux/$(go env GOARCH)/{kube-apiserver,kube-controller-manager,kube-scheduler,kubelet,watch-termination,k8s-tests,k8s-tests-ext} \
8+
/tmp/build && \
9+
gzip /tmp/build/k8s-tests-ext
910

1011
FROM registry.ci.openshift.org/ocp/4.18:base-rhel9
1112
RUN yum install -y --setopt=tsflags=nodocs --setopt=skip_missing_names_on_install=False iproute && yum clean all

staging/src/k8s.io/api/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ require (
2121
github.com/kr/pretty v0.3.1 // indirect
2222
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2323
github.com/modern-go/reflect2 v1.0.2 // indirect
24+
github.com/onsi/ginkgo/v2 v2.6.1-0.20241002180654-3ded579fec72
25+
github.com/openshift-eng/openshift-tests-extension v0.0.0-20241008125406-e4e57f0bc1e8
2426
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
2527
github.com/rogpeppe/go-internal v1.12.0 // indirect
2628
github.com/spf13/pflag v1.0.5 // indirect
@@ -41,7 +43,7 @@ require (
4143

4244
replace (
4345
github.com/google/cadvisor => github.com/openshift/google-cadvisor v0.49.0-openshift-4.17-2
44-
github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20240806135314-3946b2b7b2a8
46+
github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241002180654-3ded579fec72
4547
k8s.io/api => ../api
4648
k8s.io/apiextensions-apiserver => ../apiextensions-apiserver
4749
k8s.io/apimachinery => ../apimachinery

staging/src/k8s.io/apiextensions-apiserver/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ require (
7878
github.com/modern-go/reflect2 v1.0.2 // indirect
7979
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8080
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
81+
github.com/onsi/ginkgo/v2 v2.6.1-0.20241002180654-3ded579fec72
82+
github.com/openshift-eng/openshift-tests-extension v0.0.0-20241008125406-e4e57f0bc1e8
8183
github.com/openshift/library-go v0.0.0-20241001171606-756adf2188fc // indirect
8284
github.com/pkg/errors v0.9.1 // indirect
8385
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -131,7 +133,7 @@ require (
131133

132134
replace (
133135
github.com/google/cadvisor => github.com/openshift/google-cadvisor v0.49.0-openshift-4.17-2
134-
github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20240806135314-3946b2b7b2a8
136+
github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241002180654-3ded579fec72
135137
k8s.io/api => ../api
136138
k8s.io/apiextensions-apiserver => ../apiextensions-apiserver
137139
k8s.io/apimachinery => ../apimachinery

0 commit comments

Comments
 (0)