Skip to content

Commit c5e16b5

Browse files
OTE framework for Ingress Node Firewall and migrating a LEVEL0 usecase
Adding OTP tak to usecase
1 parent 1223118 commit c5e16b5

182 files changed

Lines changed: 36577 additions & 6 deletions

File tree

Some content is hidden

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

Dockerfile.openshift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ COPY controllers/ controllers/
1414
COPY pkg/ pkg/
1515
COPY vendor/ vendor/
1616
COPY bindata/manifests/ bindata/manifests/
17+
COPY test/ test/
1718

1819
# Build
1920
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -mod=vendor -o manager main.go
2021

22+
# Build extended tests
23+
RUN make -C test build-e2e-tests && \
24+
gzip test/bin/ingress-node-firewall-tests
25+
2126
FROM registry.ci.openshift.org/ocp/4.22:base-rhel9
2227
WORKDIR /
2328
COPY --from=builder /workspace/manager .
2429
COPY --from=builder /workspace/bindata/manifests /bindata/manifests
30+
COPY --from=builder /workspace/test/bin/ingress-node-firewall-tests.gz /usr/bin/
2531

2632
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,12 @@ podman-build-daemon: ## Build the daemon image with podman. To change location,
480480
.PHONY: podman-push-daemon
481481
podman-push-daemon: ## Push the daemon image with docker. To change location, specify DAEMON_IMG=<image>.
482482
podman push ${DAEMON_IMG}
483+
484+
##@ Extended Tests (OTE)
485+
.PHONY: build-e2e-tests
486+
build-e2e-tests: ## Build the extended e2e test binary for OpenShift
487+
$(MAKE) -C test build-e2e-tests
488+
489+
.PHONY: clean-e2e-tests
490+
clean-e2e-tests: ## Clean the extended e2e test artifacts
491+
$(MAKE) -C test clean

go.mod

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ require (
1313
github.com/google/gopacket v1.1.19
1414
github.com/kennygrant/sanitize v1.2.4
1515
github.com/onsi/ginkgo v1.16.5
16+
github.com/onsi/ginkgo/v2 v2.23.3
1617
github.com/onsi/gomega v1.37.0
1718
github.com/pkg/errors v0.9.1
1819
github.com/prometheus/client_golang v1.22.0
1920
github.com/prometheus/common v0.63.0
21+
github.com/spf13/cobra v1.8.1
2022
github.com/vishvananda/netlink v1.3.1-0.20250206174618-62fb240731fa
2123
golang.org/x/sys v0.32.0
2224
gopkg.in/mcuadros/go-syslog.v2 v2.3.0
@@ -47,16 +49,19 @@ require (
4749
github.com/go-openapi/jsonpointer v0.21.0 // indirect
4850
github.com/go-openapi/jsonreference v0.21.0 // indirect
4951
github.com/go-openapi/swag v0.23.0 // indirect
52+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
5053
github.com/gogo/protobuf v1.3.2 // indirect
5154
github.com/golang/protobuf v1.5.4 // indirect
5255
github.com/google/btree v1.1.3 // indirect
5356
github.com/google/gnostic-models v0.6.8 // indirect
5457
github.com/google/go-cmp v0.7.0 // indirect
5558
github.com/google/gofuzz v1.2.0 // indirect
59+
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
5660
github.com/google/uuid v1.6.0 // indirect
5761
github.com/gorilla/websocket v1.5.0 // indirect
5862
github.com/huandu/xstrings v1.3.2 // indirect
5963
github.com/imdario/mergo v0.3.16 // indirect
64+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6065
github.com/josharian/intern v1.0.0 // indirect
6166
github.com/json-iterator/go v1.1.12 // indirect
6267
github.com/kylelemons/godebug v1.1.0 // indirect
@@ -85,6 +90,7 @@ require (
8590
golang.org/x/term v0.30.0 // indirect
8691
golang.org/x/text v0.23.0 // indirect
8792
golang.org/x/time v0.7.0 // indirect
93+
golang.org/x/tools v0.30.0 // indirect
8894
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
8995
google.golang.org/protobuf v1.36.5 // indirect
9096
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
@@ -97,3 +103,33 @@ require (
97103
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
98104
sigs.k8s.io/yaml v1.4.0 // indirect
99105
)
106+
107+
// Replace directives for OTE framework
108+
replace (
109+
k8s.io/api => k8s.io/api v0.32.3
110+
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.32.3
111+
k8s.io/apimachinery => k8s.io/apimachinery v0.32.3
112+
k8s.io/apiserver => k8s.io/apiserver v0.32.3
113+
k8s.io/cli-runtime => k8s.io/cli-runtime v0.32.3
114+
k8s.io/client-go => k8s.io/client-go v0.32.3
115+
k8s.io/cloud-provider => k8s.io/cloud-provider v0.32.3
116+
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.32.3
117+
k8s.io/code-generator => k8s.io/code-generator v0.32.3
118+
k8s.io/component-base => k8s.io/component-base v0.32.3
119+
k8s.io/component-helpers => k8s.io/component-helpers v0.32.3
120+
k8s.io/controller-manager => k8s.io/controller-manager v0.32.3
121+
k8s.io/cri-api => k8s.io/cri-api v0.32.3
122+
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.32.3
123+
k8s.io/dynamic-resource-allocation => k8s.io/dynamic-resource-allocation v0.32.3
124+
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.32.3
125+
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.32.3
126+
k8s.io/kube-proxy => k8s.io/kube-proxy v0.32.3
127+
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.32.3
128+
k8s.io/kubectl => k8s.io/kubectl v0.32.3
129+
k8s.io/kubelet => k8s.io/kubelet v0.32.3
130+
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.32.3
131+
k8s.io/metrics => k8s.io/metrics v0.32.3
132+
k8s.io/mount-utils => k8s.io/mount-utils v0.32.3
133+
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.32.3
134+
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.32.3
135+
)

go.sum

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
1616
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
1717
github.com/cilium/ebpf v0.18.0 h1:OsSwqS4y+gQHxaKgg2U/+Fev834kdnsQbtzRnbVC6Gs=
1818
github.com/cilium/ebpf v0.18.0/go.mod h1:vmsAT73y4lW2b4peE+qcOqw6MxvWQdC+LiU5gd/xyo4=
19+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1920
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2021
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2122
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -45,7 +46,6 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr
4546
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
4647
github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6 h1:teYtXy9B7y5lHTp8V9KPxpYRAVA7dozigQcMiBust1s=
4748
github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6/go.mod h1:p4lGIVX+8Wa6ZPNDvqcxq36XpUDLh42FLetFU7odllI=
48-
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
4949
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
5050
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
5151
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
@@ -88,6 +88,8 @@ github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw
8888
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
8989
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
9090
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
91+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
92+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
9193
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
9294
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
9395
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
@@ -157,6 +159,9 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
157159
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
158160
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
159161
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
162+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
163+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
164+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
160165
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
161166
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
162167
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

test/Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# test/Makefile - Build targets for ingress-node-firewall extended tests
2+
3+
SHELL := /bin/bash
4+
5+
# Binary name
6+
BINARY_NAME := ingress-node-firewall-tests
7+
8+
# Build directory
9+
BUILD_DIR := bin
10+
BINARY_PATH := $(BUILD_DIR)/$(BINARY_NAME)
11+
12+
# Go build flags
13+
GO := go
14+
GOFLAGS ?=
15+
LDFLAGS := -w -s
16+
17+
# Version information
18+
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "unknown")
19+
GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
20+
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
21+
22+
# LDFLAGS with version info
23+
LDFLAGS += -X github.com/openshift/ingress-node-firewall/test/version.Version=$(VERSION)
24+
LDFLAGS += -X github.com/openshift/ingress-node-firewall/test/version.GitCommit=$(GIT_COMMIT)
25+
LDFLAGS += -X github.com/openshift/ingress-node-firewall/test/version.BuildDate=$(BUILD_DATE)
26+
27+
.PHONY: all
28+
all: build-e2e-tests
29+
30+
.PHONY: build-e2e-tests
31+
build-e2e-tests: ## Build the extended e2e test binary
32+
@echo "Building $(BINARY_NAME)..."
33+
@mkdir -p $(BUILD_DIR)
34+
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BINARY_PATH) ./cmd/main.go
35+
@echo "Built $(BINARY_PATH)"
36+
37+
.PHONY: clean
38+
clean: ## Clean build artifacts
39+
@echo "Cleaning test build artifacts..."
40+
@rm -rf $(BUILD_DIR)
41+
42+
.PHONY: help
43+
help: ## Display this help
44+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
34.7 MB
Binary file not shown.

test/cmd/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
8+
_ "github.com/openshift/ingress-node-firewall/test/e2e/operator"
9+
"github.com/openshift/ingress-node-firewall/test/extension"
10+
testcmd "github.com/openshift/ingress-node-firewall/test/extension/cmd"
11+
)
12+
13+
func main() {
14+
// Create the extension registry
15+
registry := extension.NewTestRegistry()
16+
17+
// Register ingress-node-firewall tests
18+
registry.RegisterTests("ingress-node-firewall", "Ingress Node Firewall extended tests")
19+
20+
// Create root command
21+
rootCmd := &cobra.Command{
22+
Use: "ingress-node-firewall-tests",
23+
Short: "OpenShift extended tests for ingress-node-firewall",
24+
Long: "This binary contains extended e2e tests for ingress-node-firewall operator",
25+
}
26+
27+
// Add OTE standard extension commands (info, list, run-test)
28+
rootCmd.AddCommand(testcmd.DefaultExtensionCommands(registry)...)
29+
30+
if err := rootCmd.Execute(); err != nil {
31+
os.Exit(1)
32+
}
33+
}

test/e2e/cli.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package e2e
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"fmt"
7+
"os/exec"
8+
"strings"
9+
)
10+
11+
// OCClient provides helper methods for executing oc commands
12+
type OCClient struct {
13+
kubeconfig string
14+
}
15+
16+
// NewOCClient creates a new OCClient
17+
func NewOCClient(kubeconfig string) *OCClient {
18+
if kubeconfig == "" {
19+
kubeconfig = GetKubeconfig()
20+
}
21+
return &OCClient{
22+
kubeconfig: kubeconfig,
23+
}
24+
}
25+
26+
// Run executes an oc command and returns the output
27+
func (c *OCClient) Run(ctx context.Context, args ...string) (string, error) {
28+
cmdArgs := append([]string{"--kubeconfig", c.kubeconfig}, args...)
29+
cmd := exec.CommandContext(ctx, "oc", cmdArgs...)
30+
31+
var stdout, stderr bytes.Buffer
32+
cmd.Stdout = &stdout
33+
cmd.Stderr = &stderr
34+
35+
err := cmd.Run()
36+
if err != nil {
37+
return "", fmt.Errorf("command failed: %v, stderr: %s", err, stderr.String())
38+
}
39+
40+
return strings.TrimSpace(stdout.String()), nil
41+
}
42+
43+
// Apply applies a resource from a file
44+
func (c *OCClient) Apply(ctx context.Context, file string) error {
45+
_, err := c.Run(ctx, "apply", "-f", file)
46+
return err
47+
}
48+
49+
// Delete deletes a resource
50+
func (c *OCClient) Delete(ctx context.Context, resourceType, name, namespace string) error {
51+
args := []string{"delete", resourceType, name}
52+
if namespace != "" {
53+
args = append(args, "-n", namespace)
54+
}
55+
_, err := c.Run(ctx, args...)
56+
return err
57+
}
58+
59+
// Get gets a resource
60+
func (c *OCClient) Get(ctx context.Context, resourceType, name, namespace string) (string, error) {
61+
args := []string{"get", resourceType}
62+
if name != "" {
63+
args = append(args, name)
64+
}
65+
if namespace != "" {
66+
args = append(args, "-n", namespace)
67+
}
68+
return c.Run(ctx, args...)
69+
}

test/e2e/operator/operator.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package operator
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
"time"
8+
9+
g "github.com/onsi/ginkgo/v2"
10+
o "github.com/onsi/gomega"
11+
12+
e2e "github.com/openshift/ingress-node-firewall/test/e2e"
13+
)
14+
15+
var _ = g.Describe("[sig-network] INFW", func() {
16+
defer g.GinkgoRecover()
17+
18+
var (
19+
oc *e2e.OCClient
20+
ctx context.Context
21+
cancel context.CancelFunc
22+
opNamespace = "openshift-ingress-node-firewall"
23+
)
24+
25+
g.BeforeEach(func() {
26+
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Minute)
27+
oc = e2e.NewOCClient("")
28+
})
29+
30+
g.AfterEach(func() {
31+
if cancel != nil {
32+
cancel()
33+
}
34+
})
35+
36+
// OCP-61481 - Ingress Node Firewall Operator Installation
37+
g.It("Author:anusaxen-High-61481-[LEVEL0][OTP]-StagerunBoth-Ingress Node Firewall Operator Installation [apigroup:ingressnodefirewall.openshift.io]", func() {
38+
g.By("Checking Ingress Node Firewall operator installation")
39+
40+
// Check that the operator namespace exists
41+
output, err := oc.Get(ctx, "namespace", opNamespace, "")
42+
o.Expect(err).NotTo(o.HaveOccurred(), "Operator namespace should exist")
43+
o.Expect(output).To(o.ContainSubstring(opNamespace), "Namespace output should contain the operator namespace")
44+
45+
g.By("Verifying CRDs are installed")
46+
crdOutput, err := oc.Run(ctx, "get", "crd")
47+
o.Expect(err).NotTo(o.HaveOccurred(), "Should be able to list CRDs")
48+
49+
expectedCRDs := []string{
50+
"ingressnodefirewallconfigs.ingressnodefirewall.openshift.io",
51+
"ingressnodefirewallnodestates.ingressnodefirewall.openshift.io",
52+
"ingressnodefirewalls.ingressnodefirewall.openshift.io",
53+
}
54+
55+
for _, crd := range expectedCRDs {
56+
o.Expect(strings.Contains(crdOutput, crd)).To(o.BeTrue(),
57+
"CRD %s should be installed", crd)
58+
}
59+
60+
g.By("Verifying operator deployment is running")
61+
// Check that the operator deployment exists and is ready
62+
deploymentOutput, err := oc.Run(ctx, "get", "deployment", "-n", opNamespace, "-o=jsonpath={.items[*].metadata.name}")
63+
o.Expect(err).NotTo(o.HaveOccurred(), "Should be able to list deployments in operator namespace")
64+
o.Expect(deploymentOutput).NotTo(o.BeEmpty(), "There should be at least one deployment in the operator namespace")
65+
66+
// Wait for the operator deployment to be ready
67+
deploymentName := "ingress-node-firewall-controller-manager"
68+
_, err = oc.Run(ctx, "wait", "deployment/"+deploymentName, "-n", opNamespace, "--for=condition=Available", "--timeout=5m")
69+
o.Expect(err).NotTo(o.HaveOccurred(), "Operator deployment should be available")
70+
71+
g.By("SUCCESS - Ingress Node Firewall operator and CRDs installed")
72+
fmt.Println("Operator install and CRDs check successful!")
73+
})
74+
})

0 commit comments

Comments
 (0)