Skip to content

Commit

Permalink
Set default feature gates of unsupported features to false on Windows (
Browse files Browse the repository at this point in the history
…#3527)

A feature might be enabled by default on Linux, but is not supported on
Windows, so set the default feature gates of such features to false on
Windows.

Signed-off-by: Jianjun Shen <shenj@vmware.com>
  • Loading branch information
jianjuns authored Mar 31, 2022
1 parent ac50657 commit ce0de59
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
5 changes: 1 addition & 4 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
43 changes: 20 additions & 23 deletions pkg/apiserver/handlers/featuregates/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"},
},
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"},
Expand All @@ -214,3 +202,12 @@ func Test_getControllerGatesResponse(t *testing.T) {
})
}
}

func init() {
egressStatus = "Enabled"
nplStatus = "Enabled"
if runtime.IsWindowsPlatform() {
egressStatus = "Disabled"
nplStatus = "Disabled"
}
}
17 changes: 15 additions & 2 deletions pkg/features/antrea_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ce0de59

Please sign in to comment.