Skip to content

Commit 2b06c4f

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 2b06c4f

File tree

10 files changed

+1126
-175
lines changed

10 files changed

+1126
-175
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-ext
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-ext.gz /usr/bin/cluster-network-operator-tests-ext.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-ext 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.

manifests/0000_70_cluster-network-operator_01_pki_crd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
44
kind: CustomResourceDefinition
55
metadata:
66
annotations:
7-
controller-gen.kubebuilder.io/version: v0.18.0
7+
controller-gen.kubebuilder.io/version: v0.19.0
88
include.release.openshift.io/ibm-cloud-managed: "true"
99
include.release.openshift.io/self-managed-high-availability: "true"
1010
name: operatorpkis.network.operator.openshift.io

pkg/network/openshift_sdn_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ clusterNetworks:
445445
hostsubnetlength: 9
446446
kind: ClusterNetwork
447447
metadata:
448-
creationTimestamp: null
449448
name: default
450449
mtu: 1450
451450
network: 10.128.0.0/15

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-ext
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: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
servicePort = 27017
27+
serviceTargetPort = 8080
28+
)
29+
ipStackType := checkIPStackType(oc)
30+
o.Expect(ipStackType).NotTo(o.BeEmpty())
31+
32+
nodeList, err := e2enode.GetReadySchedulableNodes(context.TODO(), oc.KubeFramework().ClientSet)
33+
o.Expect(err).NotTo(o.HaveOccurred())
34+
if len(nodeList.Items) < 2 {
35+
g.Skip("This case requires 2 nodes, but the cluster has less than two nodes")
36+
}
37+
38+
// Create hello-pod1 on the first node
39+
createPingPodOnNode(oc, pod1Name, oc.Namespace(), podLabel, nodeList.Items[0].Name)
40+
41+
// Create hello-pod2 on the second node
42+
createPingPodOnNode(oc, pod2Name, oc.Namespace(), podLabel, nodeList.Items[1].Name)
43+
44+
// Determine ipFamilyPolicy based on cluster type
45+
var ipFamilyPolicy string
46+
if ipStackType == "ipv4single" {
47+
ipFamilyPolicy = "SingleStack"
48+
} else {
49+
ipFamilyPolicy = "PreferDualStack"
50+
}
51+
internalTrafficPolicy := "Cluster"
52+
externalTrafficPolicy := ""
53+
// Create service backing both pods
54+
createGenericService(oc, serviceName, oc.Namespace(), "TCP", podLabel, "ClusterIP", ipFamilyPolicy, internalTrafficPolicy, externalTrafficPolicy, servicePort, serviceTargetPort)
55+
//custom patches to test depending on type of cluster addressing
56+
customPatchIPv4 := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"100.99.0.0/16\",\"internalTransitSwitchSubnet\": \"100.69.0.0/16\"}}}}}"
57+
customPatchIPv6 := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv6\":{\"internalJoinSubnet\": \"ab98::/64\",\"internalTransitSwitchSubnet\": \"ab97::/64\"}}}}}"
58+
customPatchDualstack := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"100.99.0.0/16\",\"internalTransitSwitchSubnet\": \"100.69.0.0/16\"},\"ipv6\": {\"internalJoinSubnet\": \"ab98::/64\",\"internalTransitSwitchSubnet\": \"ab97::/64\"}}}}}"
59+
60+
//gather original cluster values so that we can defer to them later once test done
61+
currentinternalJoinSubnetIPv4Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv4.internalJoinSubnet}").Output()
62+
o.Expect(err).NotTo(o.HaveOccurred())
63+
currentinternalTransitSwSubnetIPv4Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv4.internalTransitSwitchSubnet}").Output()
64+
o.Expect(err).NotTo(o.HaveOccurred())
65+
currentinternalJoinSubnetIPv6Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv6.internalJoinSubnet}").Output()
66+
o.Expect(err).NotTo(o.HaveOccurred())
67+
currentinternalTransitSwSubnetIPv6Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv6.internalTransitSwitchSubnet}").Output()
68+
o.Expect(err).NotTo(o.HaveOccurred())
69+
70+
//if any of value is null on exisiting cluster, it indicates that cluster came up with following default values assigned by OVNK
71+
if currentinternalJoinSubnetIPv4Value == "" {
72+
currentinternalJoinSubnetIPv4Value = "100.64.0.0/16"
73+
}
74+
if currentinternalJoinSubnetIPv6Value == "" {
75+
currentinternalJoinSubnetIPv6Value = "fd98::/64"
76+
}
77+
if currentinternalTransitSwSubnetIPv4Value == "" {
78+
currentinternalTransitSwSubnetIPv4Value = "100.88.0.0/16"
79+
}
80+
if currentinternalTransitSwSubnetIPv6Value == "" {
81+
currentinternalTransitSwSubnetIPv6Value = "fd97::/64"
82+
}
83+
84+
//vars to patch cluster back to original state
85+
patchIPv4original := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv4Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv4Value + "\"}}}}}"
86+
patchIPv6original := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv6\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv6Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv6Value + "\"}}}}}"
87+
patchDualstackoriginal := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv4Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv4Value + "\"},\"ipv6\": {\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv6Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv6Value + "\"}}}}}"
88+
89+
switch ipStackType {
90+
case "ipv4single":
91+
defer func() {
92+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchIPv4original)
93+
err := checkOVNKState(oc)
94+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch")
95+
}()
96+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchIPv4)
97+
case "ipv6single":
98+
defer func() {
99+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchIPv6original)
100+
err := checkOVNKState(oc)
101+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch")
102+
}()
103+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchIPv6)
104+
default:
105+
defer func() {
106+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchDualstackoriginal)
107+
err := checkOVNKState(oc)
108+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch")
109+
}()
110+
patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchDualstack)
111+
}
112+
err = checkOVNKState(oc)
113+
o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube never trigger or rolled out successfully post oc patch")
114+
//check usual svc and pod connectivities post migration which also ensures disruption doesn't last post successful rollout
115+
curlPod2PodPass(oc, oc.Namespace(), pod1Name, oc.Namespace(), pod2Name, serviceTargetPort)
116+
curlPod2SvcPass(oc, oc.Namespace(), oc.Namespace(), pod1Name, serviceName, servicePort)
117+
})
118+
})

0 commit comments

Comments
 (0)