Skip to content

Commit be1e34a

Browse files
Merge pull request #30684 from duanwei33/revert-STOR-2550
OCPBUGS-73778: revert LSO networkpolicy cases
2 parents 2108639 + 3c9c6ab commit be1e34a

16 files changed

Lines changed: 2 additions & 4245 deletions

File tree

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ require (
6666
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
6767
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
6868
github.com/openshift/library-go v0.0.0-20251015151611-6fc7a74b67c5
69-
github.com/operator-framework/api v0.36.0
7069
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20250118001652-a8b9c3c31417
7170
github.com/pborman/uuid v1.2.0
7271
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,6 @@ github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20251001123353-fd5b1fb35db1 h1:PMTg
892892
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20251001123353-fd5b1fb35db1/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
893893
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
894894
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
895-
github.com/operator-framework/api v0.36.0 h1:6+duRhamCvB540JbvNp/1+Pot7luff7HqdAOm9bAntg=
896-
github.com/operator-framework/api v0.36.0/go.mod h1:QSmHMx8XpGsNWvjU5CUelVZC916VLp/TZhfYvGKpghM=
897895
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
898896
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20250118001652-a8b9c3c31417 h1:7k+dokKFfpICbkpX5TvvpFbKTFsl/6YQd46EpY2JNhc=
899897
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20250118001652-a8b9c3c31417/go.mod h1:9LxDV3rAHlGHAYtVrT62y/fqfIxc5RrDiYi9RVeD0gg=

test/extended/storage/storage_networkpolicy.go

Lines changed: 2 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/blang/semver/v4"
98
g "github.com/onsi/ginkgo/v2"
109
o "github.com/onsi/gomega"
1110
exutil "github.com/openshift/origin/test/extended/util"
12-
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1311
"k8s.io/apimachinery/pkg/api/errors"
1412
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1513
e2e "k8s.io/kubernetes/test/e2e/framework"
16-
"sigs.k8s.io/controller-runtime/pkg/client"
1714
)
1815

1916
// storage_networkpolicy.go contains tests for verifying network policy configurations
@@ -28,14 +25,8 @@ import (
2825
// 2. CSI driver resources - verifies network policy labels on platform-specific CSI
2926
// drivers (AWS EBS/EFS, Azure Disk/File, GCP PD/Filestore, vSphere, IBM Cloud,
3027
// OpenStack Cinder/Manila, SMB)
31-
// 3. LSO (Local Storage Operator) resources - verifies network policy labels on
32-
// related deployment and diskmaker daemonsets
33-
// 4. NetworkPolicy resources - ensures required NetworkPolicies exist with correct
34-
// PodSelector labels for CSO, CSI, and LSO namespaces
35-
//
36-
// LSO-specific Design Considerations:
37-
// - LSONamespace is defined as a variable (not constant) because LSO can be installed
38-
// in a user-specified namespace, allowing for customization based on actual deployment
28+
// 3. NetworkPolicy resources - ensures required NetworkPolicies exist with correct
29+
// PodSelector labels for CSO, CSI
3930

4031
// ResourceType defines the type of Openshift workload resource
4132
type ResourceType string
@@ -45,13 +36,6 @@ const (
4536
ResourceTypeDaemonSet ResourceType = "DaemonSet"
4637
)
4738

48-
// lsoInfo contains information about the Local Storage Operator installation
49-
type lsoInfo struct {
50-
Installed bool
51-
Namespace string
52-
Version string
53-
}
54-
5539
// resourceCheck defines a check for a workload resource (Deployment, DaemonSet, etc.)
5640
type resourceCheck struct {
5741
ResourceType ResourceType
@@ -68,11 +52,6 @@ var (
6852
npLabelOperatorMetricsRange = map[string]string{"openshift.storage.network-policy.operator-metrics-range": "allow"}
6953
npLabelMetricsRange = map[string]string{"openshift.storage.network-policy.metrics-range": "allow"}
7054
npLabelAllEgress = map[string]string{"openshift.storage.network-policy.all-egress": "allow"}
71-
// LSO specific network policy labels
72-
npLabelLSOAPIServer = map[string]string{"openshift.storage.network-policy.lso.api-server": "allow"}
73-
npLabelLSODNS = map[string]string{"openshift.storage.network-policy.lso.dns": "allow"}
74-
npLabelLSOOperatorMetrics = map[string]string{"openshift.storage.network-policy.lso.operator-metrics": "allow"}
75-
npLabelLSODiskmakerMetrics = map[string]string{"openshift.storage.network-policy.lso.diskmaker-metrics": "allow"}
7655
)
7756

7857
func mergeLabels(maps ...map[string]string) map[string]string {
@@ -94,9 +73,6 @@ var (
9473
csiOperatorWithAllEgressRequiredLabels = mergeLabels(npLabelAPI, npLabelDNS, npLabelOperatorMetricsRange, npLabelAllEgress)
9574
csiControllerRequiredLabels = mergeLabels(npLabelAPI, npLabelDNS, npLabelMetricsRange)
9675
csiControllerWithAllEgressRequiredLabels = mergeLabels(npLabelAPI, npLabelDNS, npLabelMetricsRange, npLabelAllEgress)
97-
// LSO specific required labels
98-
lsoOperatorRequiredLabels = mergeLabels(npLabelLSOAPIServer, npLabelLSODNS, npLabelLSOOperatorMetrics)
99-
lsoDiskmakerRequiredLabels = mergeLabels(npLabelLSOAPIServer, npLabelLSODNS, npLabelLSODiskmakerMetrics)
10076
)
10177

10278
type npCheck struct {
@@ -140,26 +116,11 @@ var networkPolicyChecks = []npCheck{
140116
// },
141117
}
142118

143-
// getLSONetworkPolicyCheck returns the LSO network policy check configuration
144-
// based on the detected LSO installation information
145-
func getLSONetworkPolicyCheck(lso *lsoInfo) npCheck {
146-
return npCheck{
147-
Namespace: lso.Namespace,
148-
RequiredPodSelectors: []map[string]string{
149-
npLabelLSOAPIServer,
150-
npLabelLSODNS,
151-
npLabelLSOOperatorMetrics,
152-
npLabelLSODiskmakerMetrics,
153-
},
154-
}
155-
}
156-
157119
var _ = g.Describe("[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Network Policy", func() {
158120
defer g.GinkgoRecover()
159121
var (
160122
oc = exutil.NewCLI("storage-network-policy")
161123
currentPlatform = e2e.TestContext.Provider
162-
lsoInstallInfo *lsoInfo // LSO installation information detected once per suite
163124
)
164125

165126
g.BeforeEach(func() {
@@ -168,20 +129,6 @@ var _ = g.Describe("[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Netwo
168129
if isMicroShift {
169130
g.Skip("Storage Network Policy tests are not supported on MicroShift")
170131
}
171-
172-
// Detect LSO installation only once (cache the result)
173-
if lsoInstallInfo == nil {
174-
lsoInstallInfo, err = getLSOInfo(oc)
175-
o.Expect(err).NotTo(o.HaveOccurred(), "Failed to detect LSO installation")
176-
177-
if lsoInstallInfo.Installed {
178-
supported := isLSOVersionSupported(lsoInstallInfo.Version)
179-
g.By(fmt.Sprintf("Detected LSO installed in namespace: %s, version: %s (network policy support: %v)",
180-
lsoInstallInfo.Namespace, lsoInstallInfo.Version, supported))
181-
} else {
182-
g.By("LSO is not installed on this cluster")
183-
}
184-
}
185132
})
186133

187134
g.It("should verify required labels for CSO related Operators", func() {
@@ -364,59 +311,6 @@ var _ = g.Describe("[sig-storage][OCPFeature:StorageNetworkPolicy] Storage Netwo
364311
runResourceChecks(oc, CSIResourcesToCheck, currentPlatform)
365312
})
366313

367-
g.It("should verify required labels for LSO related resources", func() {
368-
// Skip if LSO is not installed or version is lower than 4.21.0
369-
if !lsoInstallInfo.Installed {
370-
g.Skip("LSO is not installed on this cluster")
371-
}
372-
373-
if !isLSOVersionSupported(lsoInstallInfo.Version) {
374-
g.Skip(fmt.Sprintf("LSO network policy support requires version >= 4.21.0, current version: %s", lsoInstallInfo.Version))
375-
}
376-
377-
LSOResourcesToCheck := []resourceCheck{
378-
{
379-
ResourceType: ResourceTypeDeployment,
380-
Namespace: lsoInstallInfo.Namespace,
381-
Name: "local-storage-operator",
382-
Platform: "all",
383-
RequiredLabels: lsoOperatorRequiredLabels,
384-
},
385-
{
386-
ResourceType: ResourceTypeDaemonSet,
387-
Namespace: lsoInstallInfo.Namespace,
388-
Name: "diskmaker-manager",
389-
Platform: "all",
390-
RequiredLabels: lsoDiskmakerRequiredLabels,
391-
},
392-
{
393-
ResourceType: ResourceTypeDaemonSet,
394-
Namespace: lsoInstallInfo.Namespace,
395-
Name: "diskmaker-discovery",
396-
Platform: "all",
397-
RequiredLabels: lsoDiskmakerRequiredLabels,
398-
},
399-
}
400-
401-
runResourceChecks(oc, LSOResourcesToCheck, currentPlatform)
402-
})
403-
404-
g.It("should ensure required NetworkPolicies exist with correct labels for LSO", func() {
405-
// Skip if LSO is not installed or version is lower than 4.21.0
406-
if !lsoInstallInfo.Installed {
407-
g.Skip("LSO is not installed on this cluster")
408-
}
409-
410-
if !isLSOVersionSupported(lsoInstallInfo.Version) {
411-
g.Skip(fmt.Sprintf("LSO network policy support requires version >= 4.21.0, current version: %s", lsoInstallInfo.Version))
412-
}
413-
414-
// Get LSO network policy check configuration
415-
lsoCheck := getLSONetworkPolicyCheck(lsoInstallInfo)
416-
417-
verifyNetworkPolicyPodSelectors(oc, lsoCheck.Namespace, lsoCheck.RequiredPodSelectors)
418-
})
419-
420314
g.It("should ensure required NetworkPolicies exist with correct labels", func() {
421315
for _, c := range networkPolicyChecks {
422316
_, err := oc.AdminKubeClient().CoreV1().Namespaces().Get(context.TODO(), c.Namespace, metav1.GetOptions{})
@@ -496,70 +390,6 @@ func runResourceChecks(oc *exutil.CLI, resources []resourceCheck, currentPlatfor
496390
}
497391
}
498392

499-
// isLSOVersionSupported checks if the LSO version is 4.21.0 or higher
500-
// Supported version formats: "4.21.0", "4.21.0-202511252120"
501-
func isLSOVersionSupported(versionStr string) bool {
502-
// Minimum required version for LSO network policy support
503-
minVersion := semver.MustParse("4.21.0")
504-
505-
// Parse the LSO version
506-
// The version string may contain build metadata (e.g., "4.21.0-202511252120")
507-
// semver.Parse handles this correctly
508-
version, err := semver.Parse(versionStr)
509-
if err != nil {
510-
e2e.Logf("Failed to parse LSO version %q: %v", versionStr, err)
511-
return false
512-
}
513-
514-
// Compare versions: returns true if version >= minVersion
515-
return version.GTE(minVersion)
516-
}
517-
518-
// getLSOInfo detects if LSO is installed by searching for local-storage-operator CSV
519-
// across all namespaces and returns its namespace and version information
520-
func getLSOInfo(oc *exutil.CLI) (*lsoInfo, error) {
521-
info := &lsoInfo{
522-
Installed: false,
523-
}
524-
525-
// Create controller-runtime client
526-
clusterConfig := oc.AdminConfig()
527-
clusterClient, err := client.New(clusterConfig, client.Options{})
528-
if err != nil {
529-
return info, fmt.Errorf("failed to create controller-runtime client: %v", err)
530-
}
531-
532-
// Add operatorsv1alpha1 to scheme
533-
err = operatorsv1alpha1.AddToScheme(clusterClient.Scheme())
534-
if err != nil {
535-
return info, fmt.Errorf("failed to add operators.coreos.com/v1alpha1 to scheme: %v", err)
536-
}
537-
538-
// List all ClusterServiceVersions across all namespaces
539-
csvList := &operatorsv1alpha1.ClusterServiceVersionList{}
540-
err = clusterClient.List(context.TODO(), csvList)
541-
if err != nil {
542-
return info, fmt.Errorf("failed to list ClusterServiceVersions: %v", err)
543-
}
544-
545-
// Search for local-storage-operator CSV
546-
for _, csv := range csvList.Items {
547-
// Match CSV name pattern: local-storage-operator.*
548-
if strings.HasPrefix(csv.Name, "local-storage-operator") {
549-
// Only consider CSVs in Succeeded phase
550-
if csv.Status.Phase == operatorsv1alpha1.CSVPhaseSucceeded {
551-
info.Installed = true
552-
info.Namespace = csv.Namespace
553-
info.Version = csv.Spec.Version.String()
554-
return info, nil
555-
}
556-
}
557-
}
558-
559-
// LSO not found or not in Succeeded phase
560-
return info, nil
561-
}
562-
563393
// podSelectorContainsLabels checks if actualLabels contains all key-value pairs from requiredLabels
564394
func podSelectorContainsLabels(actualLabels map[string]string, requiredLabels map[string]string) bool {
565395
for key, value := range requiredLabels {

0 commit comments

Comments
 (0)