diff --git a/cmd/antrea-agent/agent.go b/cmd/antrea-agent/agent.go index 0f3bd816c05..73e72aab2ce 100644 --- a/cmd/antrea-agent/agent.go +++ b/cmd/antrea-agent/agent.go @@ -64,7 +64,6 @@ import ( "antrea.io/antrea/pkg/util/channel" "antrea.io/antrea/pkg/util/cipher" "antrea.io/antrea/pkg/util/k8s" - "antrea.io/antrea/pkg/util/runtime" "antrea.io/antrea/pkg/version" ) @@ -84,9 +83,6 @@ var excludeNodePortDevices = []string{"antrea-egress0", "antrea-ingress0", "kube func run(o *Options) error { klog.Infof("Starting Antrea agent (version %s)", version.GetFullVersion()) - // Windows platform doesn't support Egress feature yet. - egressEnabled := features.DefaultFeatureGate.Enabled(features.Egress) && !runtime.IsWindowsPlatform() - // Create K8s Clientset, CRD Clientset and SharedInformerFactory for the given config. k8sClient, _, crdClient, _, err := k8s.CreateClients(o.config.ClientConnection, o.config.KubeAPIServerOverride) if err != nil { @@ -119,6 +115,7 @@ func run(o *Options) error { } defer ovsdbConnection.Close() + egressEnabled := features.DefaultFeatureGate.Enabled(features.Egress) enableBridgingMode := features.DefaultFeatureGate.Enabled(features.AntreaIPAM) && o.config.EnableBridgingMode // Bridging mode will connect the uplink interface to the OVS bridge. connectUplinkToBridge := enableBridgingMode diff --git a/pkg/apiserver/handlers/featuregates/handler_test.go b/pkg/apiserver/handlers/featuregates/handler_test.go index ec2d2921026..943797855db 100644 --- a/pkg/apiserver/handlers/featuregates/handler_test.go +++ b/pkg/apiserver/handlers/featuregates/handler_test.go @@ -29,6 +29,12 @@ import ( "k8s.io/client-go/kubernetes/fake" "antrea.io/antrea/pkg/features" + "antrea.io/antrea/pkg/util/runtime" +) + +var ( + egressStatus string + nplStatus string ) func Test_getGatesResponse(t *testing.T) { @@ -47,13 +53,13 @@ func Test_getGatesResponse(t *testing.T) { want: []Response{ {Component: "agent", Name: "AntreaPolicy", Status: "Disabled", Version: "BETA"}, {Component: "agent", Name: "AntreaProxy", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "Egress", Status: "Enabled", Version: "BETA"}, + {Component: "agent", Name: "Egress", Status: egressStatus, Version: "BETA"}, {Component: "agent", Name: "EndpointSlice", Status: "Disabled", Version: "ALPHA"}, {Component: "agent", Name: "AntreaIPAM", Status: "Disabled", Version: "ALPHA"}, {Component: "agent", Name: "Traceflow", Status: "Enabled", Version: "BETA"}, {Component: "agent", Name: "FlowExporter", Status: "Disabled", Version: "ALPHA"}, {Component: "agent", Name: "NetworkPolicyStats", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "NodePortLocal", Status: "Enabled", Version: "BETA"}, + {Component: "agent", Name: "NodePortLocal", Status: nplStatus, Version: "BETA"}, {Component: "agent", Name: "Multicast", Status: "Disabled", Version: "ALPHA"}, {Component: "agent", Name: "ServiceExternalIP", Status: "Disabled", Version: "ALPHA"}, }, @@ -128,30 +134,12 @@ func TestHandleFunc(t *testing.T) { ) tests := []struct { - name string - expectedStatus int - expectedResponse []Response + name string + expectedStatus int }{ { name: "good path", expectedStatus: http.StatusOK, - expectedResponse: []Response{ - {Component: "controller", Name: "AntreaPolicy", Status: "Enabled", Version: "BETA"}, - {Component: "controller", Name: "Egress", Status: "Disabled", Version: "ALPHA"}, - {Component: "controller", Name: "Traceflow", Status: "Enabled", Version: "BETA"}, - {Component: "controller", Name: "NetworkPolicyStats", Status: "Enabled", Version: "BETA"}, - {Component: "controller", Name: "NodeIPAM", Status: "Disabled", Version: "ALPHA"}, - {Component: "controller", Name: "ServiceExternalIP", Status: "Disabled", Version: "ALPHA"}, - {Component: "agent", Name: "AntreaPolicy", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "AntreaProxy", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "Egress", Status: "Disabled", Version: "ALPHA"}, - {Component: "agent", Name: "EndpointSlice", Status: "Disabled", Version: "ALPHA"}, - {Component: "agent", Name: "Traceflow", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "FlowExporter", Status: "Disabled", Version: "ALPHA"}, - {Component: "agent", Name: "NetworkPolicyStats", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "NodePortLocal", Status: "Enabled", Version: "BETA"}, - {Component: "agent", Name: "ServiceExternalIP", Status: "Disabled", Version: "ALPHA"}, - }, }, } os.Setenv("POD_NAME", "antrea-controller-wotqiwth") @@ -191,7 +179,7 @@ func Test_getControllerGatesResponse(t *testing.T) { name: "good path", want: []Response{ {Component: "controller", Name: "AntreaPolicy", Status: "Enabled", Version: "BETA"}, - {Component: "controller", Name: "Egress", Status: "Enabled", Version: "BETA"}, + {Component: "controller", Name: "Egress", Status: egressStatus, Version: "BETA"}, {Component: "controller", Name: "Traceflow", Status: "Enabled", Version: "BETA"}, {Component: "controller", Name: "NetworkPolicyStats", Status: "Enabled", Version: "BETA"}, {Component: "controller", Name: "NodeIPAM", Status: "Disabled", Version: "ALPHA"}, @@ -214,3 +202,12 @@ func Test_getControllerGatesResponse(t *testing.T) { }) } } + +func init() { + egressStatus = "Enabled" + nplStatus = "Enabled" + if runtime.IsWindowsPlatform() { + egressStatus = "Disabled" + nplStatus = "Disabled" + } +} diff --git a/pkg/features/antrea_features.go b/pkg/features/antrea_features.go index 01cd6ecf536..6eb6f0adb64 100644 --- a/pkg/features/antrea_features.go +++ b/pkg/features/antrea_features.go @@ -15,8 +15,10 @@ package features import ( - "k8s.io/apimachinery/pkg/util/runtime" + k8sruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/component-base/featuregate" + + "antrea.io/antrea/pkg/util/runtime" ) // When editing this file, make sure you edit the documentation as well to keep @@ -139,7 +141,18 @@ var ( ) func init() { - runtime.Must(DefaultMutableFeatureGate.Add(DefaultAntreaFeatureGates)) + if runtime.IsWindowsPlatform() { + for f := range unsupportedFeaturesOnWindows { + // A feature which is enabled by default on Linux might not be supported on + // Windows. So, override the default value here. + fg := DefaultAntreaFeatureGates[f] + if fg.Default { + fg.Default = false + DefaultAntreaFeatureGates[f] = fg + } + } + } + k8sruntime.Must(DefaultMutableFeatureGate.Add(DefaultAntreaFeatureGates)) } // SupportedOnWindows checks whether a feature is supported on a Windows Node.