Skip to content

Commit 83f12bb

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

File tree

6 files changed

+293
-3
lines changed

6 files changed

+293
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ openshift*.tar.gz
131131
# Ensure that openapi definitions are not ignored to ensure that
132132
# openshift/origin can vendor them.
133133
!pkg/generated/openapi/zz_generated.openapi.go
134+
135+
# Ignore openshift-tests-extension
136+
/.openshift-tests-extension
137+
/k8s-tests*

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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
7+
"github.com/spf13/cobra"
8+
"github.com/spf13/pflag"
9+
10+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
11+
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
12+
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
13+
14+
utilflag "k8s.io/component-base/cli/flag"
15+
"k8s.io/component-base/logs"
16+
"k8s.io/kubernetes/openshift-hack/e2e/annotate/generated"
17+
18+
// initialize framework extensions
19+
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
20+
_ "k8s.io/kubernetes/test/e2e/framework/metrics/init"
21+
)
22+
23+
func main() {
24+
logs.InitLogs()
25+
defer logs.FlushLogs()
26+
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
27+
28+
registry := e.NewRegistry()
29+
ext := e.NewExtension("openshift", "payload", "hyperkube")
30+
31+
// Carve up the kube tests into our openshift suites...
32+
ext.AddSuite(e.Suite{
33+
Name: "kubernetes/conformance/parallel",
34+
Parents: []string{
35+
"openshift/conformance/parallel",
36+
"openshift/conformance/parallel/minimal",
37+
},
38+
Qualifiers: []string{`!labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance"`},
39+
})
40+
41+
ext.AddSuite(e.Suite{
42+
Name: "kubernetes/conformance/serial",
43+
Parents: []string{
44+
"openshift/conformance/serial",
45+
"openshift/conformance/serial/minimal",
46+
},
47+
Qualifiers: []string{`labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance"`},
48+
})
49+
50+
//FIXME(stbenjam): what other suites does k8s-test contribute to?
51+
52+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
53+
if err != nil {
54+
panic(err)
55+
}
56+
57+
// Initialization for kube ginkgo test framework needs to run before all tests execute
58+
specs.AddBeforeAll(func() {
59+
if err := initializeTestFramework(os.Getenv("TEST_PROVIDER")); err != nil {
60+
panic(err)
61+
}
62+
})
63+
64+
// Annotations get appended to test names, these are additions to upstream
65+
// tests for controlling skips, suite membership, etc.
66+
// TODO: get rid of annotations
67+
specs.Walk(func(spec *extensiontests.ExtensionTestSpec) {
68+
if annotations, ok := generated.Annotations[spec.Name]; ok {
69+
spec.Name += annotations
70+
}
71+
})
72+
73+
ext.AddSpecs(specs)
74+
registry.Register(ext)
75+
76+
// Cobra stuff
77+
root := &cobra.Command{
78+
Long: "OpenShift Tests compatible wrapper",
79+
}
80+
81+
root.AddCommand(
82+
cmd.DefaultExtensionCommands(registry)...,
83+
)
84+
85+
if err := func() error {
86+
return root.Execute()
87+
}(); err != nil {
88+
os.Exit(1)
89+
}
90+
}
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/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

0 commit comments

Comments
 (0)