@@ -2,10 +2,10 @@ package network
22
33import (
44 "fmt"
5- "strings"
65 "testing"
76
87 configv1 "github.com/openshift/api/config/v1"
8+ apifeatures "github.com/openshift/api/features"
99 v1 "github.com/openshift/api/network/v1"
1010 operv1 "github.com/openshift/api/operator/v1"
1111 corev1 "k8s.io/api/core/v1"
@@ -17,6 +17,7 @@ import (
1717 "github.com/openshift/cluster-network-operator/pkg/client/fake"
1818 "github.com/openshift/cluster-network-operator/pkg/hypershift"
1919 "github.com/openshift/cluster-network-operator/pkg/names"
20+ "github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
2021
2122 . "github.com/onsi/gomega"
2223)
@@ -37,6 +38,20 @@ var ClusterConfig = configv1.NetworkSpec{
3738 NetworkType : "None" ,
3839}
3940
41+ func getFeatureGatesWithDualStack () featuregates.FeatureGate {
42+ return featuregates .NewFeatureGate (
43+ []configv1.FeatureGateName {apifeatures .FeatureGateAdminNetworkPolicy ,
44+ apifeatures .FeatureGateDNSNameResolver ,
45+ apifeatures .FeatureGateNetworkSegmentation ,
46+ apifeatures .FeatureGateOVNObservability ,
47+ apifeatures .FeatureGateAWSDualStackInstall ,
48+ apifeatures .FeatureGateAzureDualStackInstall },
49+ []configv1.FeatureGateName {
50+ apifeatures .FeatureGatePreconfiguredUDNAddresses ,
51+ },
52+ )
53+ }
54+
4055func TestValidateClusterConfig (t * testing.T ) {
4156 g := NewGomegaWithT (t )
4257
@@ -57,12 +72,13 @@ func TestValidateClusterConfig(t *testing.T) {
5772 g .Expect (err ).NotTo (HaveOccurred ())
5873
5974 cc := * ClusterConfig .DeepCopy ()
60- err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client )
75+ featureGates := getFeatureGatesWithDualStack ()
76+ err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client , featureGates )
6177 g .Expect (err ).NotTo (HaveOccurred ())
6278
6379 haveError := func (cfg configv1.NetworkSpec , substr string ) {
6480 t .Helper ()
65- err = ValidateClusterConfig (& configv1.Network {Spec : cfg }, client )
81+ err = ValidateClusterConfig (& configv1.Network {Spec : cfg }, client , featureGates )
6682 g .Expect (err ).To (MatchError (ContainSubstring (substr )))
6783 }
6884
@@ -88,7 +104,7 @@ func TestValidateClusterConfig(t *testing.T) {
88104
89105 cc = * ClusterConfig .DeepCopy ()
90106 cc .ClusterNetwork [1 ].HostPrefix = 0
91- res := ValidateClusterConfig (& configv1.Network {Spec : cc }, client )
107+ res := ValidateClusterConfig (& configv1.Network {Spec : cc }, client , featureGates )
92108 // Since the NetworkType is None, and the hostprefix is unset we don't validate it
93109 g .Expect (res ).Should (BeNil ())
94110
@@ -289,7 +305,8 @@ func TestValidClusterConfigLiveMigration(t *testing.T) {
289305 for _ , tt := range tests {
290306 t .Run (tt .name , func (t * testing.T ) {
291307 client := fake .NewFakeClient (tt .objects ... )
292- err := validateClusterConfig (tt .config , tt .infraRes , client )
308+ fg := getFeatureGatesWithDualStack ()
309+ err := validateClusterConfig (tt .config , tt .infraRes , client , fg )
293310 if tt .expectErr {
294311 g .Expect (err ).To (HaveOccurred ())
295312 if tt .expectedErrorMsg != "" {
@@ -323,12 +340,13 @@ func TestValidateClusterConfigDualStack(t *testing.T) {
323340 g .Expect (err ).NotTo (HaveOccurred ())
324341
325342 cc := * ClusterConfig .DeepCopy ()
326- err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client )
343+ featureGates := getFeatureGatesWithDualStack ()
344+ err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client , featureGates )
327345 g .Expect (err ).NotTo (HaveOccurred ())
328346
329347 haveError := func (cfg configv1.NetworkSpec , substr string ) {
330348 t .Helper ()
331- err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client )
349+ err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client , featureGates )
332350 g .Expect (err ).To (MatchError (ContainSubstring (substr )))
333351 }
334352
@@ -368,11 +386,14 @@ func TestValidateClusterConfigDualStack(t *testing.T) {
368386 CIDR : "fd01::/48" ,
369387 HostPrefix : 64 ,
370388 })
371- err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client )
389+ err = ValidateClusterConfig (& configv1.Network {Spec : cc }, client , featureGates )
372390 g .Expect (err ).NotTo (HaveOccurred ())
373391
374- // You can't use dual-stack if this is anything else but BareMetal or NonePlatformType
375- infrastructure .Status .PlatformStatus .Type = configv1 .AzurePlatformType
392+ // You can't use dual-stack if enabled on an unsupported platform
393+ infrastructure .Status .PlatformStatus .Type = configv1 .GCPPlatformType
394+ infrastructure .Status .PlatformStatus .GCP = & configv1.GCPPlatformStatus {
395+ Region : "us-west1" ,
396+ }
376397 client = fake .NewFakeClient (infrastructure )
377398 err = createProxy (client )
378399 g .Expect (err ).NotTo (HaveOccurred ())
@@ -382,8 +403,8 @@ func TestValidateClusterConfigDualStack(t *testing.T) {
382403 CIDR : "fd01::/48" ,
383404 HostPrefix : 64 ,
384405 })
385- haveError (cc , fmt .Sprintf ("%s is not one of the supported platforms for dual stack (%s) " ,
386- infrastructure .Status .PlatformStatus .Type , strings . Join ( dualStackPlatforms . List (), ", " ) ))
406+ haveError (cc , fmt .Sprintf ("%s is not one of the supported platforms for dual stack" ,
407+ infrastructure .Status .PlatformStatus .Type ))
387408}
388409
389410func TestMergeClusterConfig (t * testing.T ) {
0 commit comments