Skip to content

Commit f461a80

Browse files
committed
setup OTE freamwork and migration one case from openshift-tests-private repo
Signed-off-by: zhaozhanqi <zzhao@redhat.com>
1 parent 05d6f46 commit f461a80

File tree

5,957 files changed

+1217981
-44719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,957 files changed

+1217981
-44719
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.21 AS builder
22
WORKDIR /go/src/github.com/openshift/cluster-network-operator
33
COPY . .
4-
RUN hack/build-go.sh
4+
RUN hack/build-go.sh && make build-e2e-tests && gzip -9 test/bin/cluster-network-operator-tests
55

66
FROM registry.ci.openshift.org/ocp/4.21:base-rhel9
77
COPY --from=builder /go/src/github.com/openshift/cluster-network-operator/cluster-network-operator /usr/bin/
88
COPY --from=builder /go/src/github.com/openshift/cluster-network-operator/cluster-network-check-endpoints /usr/bin/
99
COPY --from=builder /go/src/github.com/openshift/cluster-network-operator/cluster-network-check-target /usr/bin/
10+
COPY --from=builder /go/src/github.com/openshift/cluster-network-operator/test/bin/cluster-network-operator-tests.gz /usr/bin/cluster-network-operator-tests.gz
1011

1112
COPY manifests /manifests
1213
COPY bindata /bindata

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ clean:
4646
$(RM) cluster-network-operator cluster-network-check-endpoints cluster-network-check-target
4747
.PHONY: clean
4848

49+
# Build the e2e test binary
50+
.PHONY: build-e2e-tests
51+
build-e2e-tests:
52+
@echo "Building cluster-network-operator-tests binary..."
53+
$(MAKE) -C test build
54+
4955
GO_TEST_PACKAGES :=./pkg/... ./cmd/...

go.mod

Lines changed: 161 additions & 49 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 298 additions & 123 deletions
Large diffs are not rendered by default.

test/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Makefile for CNO E2E Test
2+
3+
# Binary name
4+
BINARY_NAME := cluster-network-operator-tests
5+
6+
# Build directory
7+
BUILD_DIR := bin
8+
9+
# Go module and package
10+
GO_MODULE := github.com/openshift/cluster-network-operator
11+
12+
# Version information
13+
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
14+
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
15+
16+
# Go build flags
17+
LDFLAGS := -X '$(GO_MODULE)/pkg/version.commitFromGit=$(GIT_COMMIT)' \
18+
-X '$(GO_MODULE)/pkg/version.buildDate=$(BUILD_DATE)' \
19+
-X '$(GO_MODULE)/pkg/version.versionFromGit=$(GIT_COMMIT)'
20+
21+
# Default target
22+
.PHONY: all
23+
all: build
24+
25+
# Build the binary
26+
.PHONY: build
27+
build:
28+
@echo "Building $(BINARY_NAME)..."
29+
@mkdir -p $(BUILD_DIR)
30+
cd cmd && go build -o ../$(BUILD_DIR)/$(BINARY_NAME) -ldflags="$(LDFLAGS)" .
31+
32+
# Build for Linux (useful for container builds)
33+
.PHONY: build-linux
34+
build-linux:
35+
@echo "Building $(BINARY_NAME) for Linux..."
36+
@mkdir -p $(BUILD_DIR)
37+
cd cmd && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
38+
go build -o ../$(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 -ldflags="$(LDFLAGS)" .
39+
40+
# Clean build artifacts
41+
.PHONY: clean
42+
clean:
43+
@echo "Cleaning build artifacts..."
44+
rm -rf $(BUILD_DIR)
45+

test/cmd/main.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
8+
9+
"github.com/spf13/cobra"
10+
11+
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
12+
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
13+
14+
_ "github.com/openshift/cluster-network-operator/test/e2e"
15+
)
16+
17+
func main() {
18+
registry := e.NewRegistry()
19+
20+
// Tests should only be run as part of or via openshift-tests, running tests via the extension is not supported.
21+
ext := e.NewExtension("openshift", "payload", "cluster-network-operator")
22+
ext.AddSuite(e.Suite{
23+
Name: "openshift/cluster-network-operator/conformance/parallel",
24+
Parents: []string{
25+
"openshift/conformance/parallel",
26+
},
27+
Qualifiers: []string{
28+
"name.contains('[Suite:openshift/cluster-network-operator/conformance/parallel')",
29+
},
30+
})
31+
32+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
33+
if err != nil {
34+
panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error()))
35+
}
36+
37+
ext.AddSpecs(specs)
38+
registry.Register(ext)
39+
40+
root := &cobra.Command{
41+
Long: "OpenShift Tests Extension for Cluster Network Operator",
42+
}
43+
root.AddCommand(cmd.DefaultExtensionCommands(registry)...)
44+
45+
if err := func() error {
46+
return root.Execute()
47+
}(); err != nil {
48+
os.Exit(1)
49+
}
50+
}

test/e2e/cno.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
6+
g "github.com/onsi/ginkgo/v2"
7+
o "github.com/onsi/gomega"
8+
9+
exutil "github.com/openshift/origin/test/extended/util"
10+
11+
admissionapi "k8s.io/pod-security-admission/api"
12+
13+
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
14+
)
15+
16+
var _ = g.Describe("[sig-network] CNO", func() {
17+
defer g.GinkgoRecover()
18+
oc := exutil.NewCLIWithPodSecurityLevel("networking-cno", admissionapi.LevelBaseline)
19+
20+
g.It("Author:anusaxen-High-73205-High-72817-Make sure internalJoinSubnet and internalTransitSwitchSubnet is configurable post install as a Day 2 operation [Disruptive]", func() {
21+
var (
22+
pod1Name = "hello-pod1"
23+
pod2Name = "hello-pod2"
24+
podLabel = "hello-pod"
25+
serviceName = "test-service-73205"
26+
)
27+
ipStackType := checkIPStackType(oc)
28+
o.Expect(ipStackType).NotTo(o.BeEmpty())
29+
30+
nodeList, err := e2enode.GetReadySchedulableNodes(context.TODO(), oc.KubeFramework().ClientSet)
31+
o.Expect(err).NotTo(o.HaveOccurred())
32+
if len(nodeList.Items) < 2 {
33+
g.Skip("This case requires 2 nodes, but the cluster has less than two nodes")
34+
}
35+
36+
// Create hello-pod1 on the first node
37+
createPingPodOnNode(oc, pod1Name, oc.Namespace(), podLabel, nodeList.Items[0].Name)
38+
39+
// Create hello-pod2 on the second node
40+
createPingPodOnNode(oc, pod2Name, oc.Namespace(), podLabel, nodeList.Items[1].Name)
41+
42+
// Determine ipFamilyPolicy based on cluster type
43+
var ipFamilyPolicy string
44+
if ipStackType == "ipv4single" {
45+
ipFamilyPolicy = "SingleStack"
46+
} else {
47+
ipFamilyPolicy = "PreferDualStack"
48+
}
49+
internalTrafficPolicy := "Cluster"
50+
externalTrafficPolicy := ""
51+
// Create service backing both pods
52+
createGenericService(oc, serviceName, oc.Namespace(), "TCP", podLabel, "ClusterIP", ipFamilyPolicy, internalTrafficPolicy, externalTrafficPolicy)
53+
//custom patches to test depending on type of cluster addressing
54+
customPatchIPv4 := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"100.99.0.0/16\",\"internalTransitSwitchSubnet\": \"100.69.0.0/16\"}}}}}"
55+
customPatchIPv6 := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv6\":{\"internalJoinSubnet\": \"ab98::/64\",\"internalTransitSwitchSubnet\": \"ab97::/64\"}}}}}"
56+
customPatchDualstack := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"100.99.0.0/16\",\"internalTransitSwitchSubnet\": \"100.69.0.0/16\"},\"ipv6\": {\"internalJoinSubnet\": \"ab98::/64\",\"internalTransitSwitchSubnet\": \"ab97::/64\"}}}}}"
57+
58+
//gather original cluster values so that we can defer to them later once test done
59+
currentinternalJoinSubnetIPv4Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.items[*].spec.defaultNetwork.ovnKubernetesConfig.ipv4.internalJoinSubnet}").Output()
60+
o.Expect(err).NotTo(o.HaveOccurred())
61+
currentinternalTransitSwSubnetIPv4Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.items[*].spec.defaultNetwork.ovnKubernetesConfig.ipv4.internalTransitSwitchSubnet}").Output()
62+
o.Expect(err).NotTo(o.HaveOccurred())
63+
currentinternalJoinSubnetIPv6Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.items[*].spec.defaultNetwork.ovnKubernetesConfig.ipv6.internalJoinSubnet}").Output()
64+
o.Expect(err).NotTo(o.HaveOccurred())
65+
currentinternalTransitSwSubnetIPv6Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.items[*].spec.defaultNetwork.ovnKubernetesConfig.ipv6.internalTransitSwitchSubnet}").Output()
66+
o.Expect(err).NotTo(o.HaveOccurred())
67+
68+
//if any of value is null on exisiting cluster, it indicates that cluster came up with following default values assigned by OVNK
69+
if (currentinternalJoinSubnetIPv4Value == "") || (currentinternalJoinSubnetIPv6Value == "") {
70+
currentinternalJoinSubnetIPv4Value = "100.64.0.0/16"
71+
currentinternalJoinSubnetIPv6Value = "fd98::/64"
72+
}
73+
if (currentinternalTransitSwSubnetIPv4Value == "") || (currentinternalTransitSwSubnetIPv6Value == "") {
74+
currentinternalTransitSwSubnetIPv4Value = "100.88.0.0/16"
75+
currentinternalTransitSwSubnetIPv6Value = "fd97::/64"
76+
}
77+
78+
//vars to patch cluster back to original state
79+
patchIPv4original := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv4Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv4Value + "\"}}}}}"
80+
patchIPv6original := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv6\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv6Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv6Value + "\"}}}}}"
81+
patchDualstackoriginal := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv4Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv4Value + "\"},\"ipv6\": {\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv6Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv6Value + "\"}}}}}"
82+
83+
switch ipStackType {
84+
case "ipv4single":
85+
defer func() {
86+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchIPv4original)
87+
err := checkOVNKState(oc)
88+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch")
89+
}()
90+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchIPv4)
91+
case "ipv6single":
92+
defer func() {
93+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchIPv6original)
94+
err := checkOVNKState(oc)
95+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch")
96+
}()
97+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchIPv6)
98+
default:
99+
defer func() {
100+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchDualstackoriginal)
101+
err := checkOVNKState(oc)
102+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch")
103+
}()
104+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchDualstack)
105+
}
106+
err = checkOVNKState(oc)
107+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube never trigger or rolled out successfully post oc patch")
108+
//check usual svc and pod connectivities post migration which also ensures disruption doesn't last post successful rollout
109+
CurlPod2PodPass(oc, oc.Namespace(), pod1Name, oc.Namespace(), pod2Name)
110+
CurlPod2SvcPass(oc, oc.Namespace(), oc.Namespace(), pod1Name, serviceName)
111+
})
112+
})

0 commit comments

Comments
 (0)