From b8470917f1fc1bab4a79c8c914819dda6264bf98 Mon Sep 17 00:00:00 2001 From: Cookie Wang Date: Sun, 16 Apr 2023 22:15:18 +0800 Subject: [PATCH] feat: add feature gate --- cmd/agent/app/start.go | 2 ++ go.mod | 2 +- pkg/features/features.go | 51 ++++++++++++++++++++++++++++++++++++++++ raven.sh | 2 +- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 pkg/features/features.go diff --git a/cmd/agent/app/start.go b/cmd/agent/app/start.go index 6d7636b..59343c5 100644 --- a/cmd/agent/app/start.go +++ b/cmd/agent/app/start.go @@ -25,6 +25,7 @@ import ( "github.com/openyurtio/raven/cmd/agent/app/config" "github.com/openyurtio/raven/cmd/agent/app/options" + "github.com/openyurtio/raven/pkg/features" "github.com/openyurtio/raven/pkg/k8s" "github.com/openyurtio/raven/pkg/networkengine/routedriver" "github.com/openyurtio/raven/pkg/networkengine/vpndriver" @@ -52,6 +53,7 @@ func NewRavenAgentCommand(ctx context.Context) *cobra.Command { } agentOptions.AddFlags(cmd.Flags()) + features.DefaultMutableFeatureGate.AddFlag(cmd.Flags()) return cmd } diff --git a/go.mod b/go.mod index b57fd9b..2c0db66 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( k8s.io/apimachinery v0.23.2 k8s.io/apiserver v0.23.2 k8s.io/client-go v0.23.2 + k8s.io/component-base v0.23.2 k8s.io/klog/v2 v2.30.0 sigs.k8s.io/controller-runtime v0.11.0 ) @@ -102,7 +103,6 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.23.2 // indirect k8s.io/apiextensions-apiserver v0.23.0 // indirect - k8s.io/component-base v0.23.2 // indirect k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.27 // indirect diff --git a/pkg/features/features.go b/pkg/features/features.go new file mode 100644 index 0000000..49ab311 --- /dev/null +++ b/pkg/features/features.go @@ -0,0 +1,51 @@ +/* + * Copyright 2022 The OpenYurt Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package features + +import ( + "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/component-base/featuregate" +) + +var ( + // DefaultMutableFeatureGate is a mutable version of DefaultFeatureGate. + DefaultMutableFeatureGate featuregate.MutableFeatureGate = featuregate.NewFeatureGate() + + // DefaultFeatureGate is a shared global FeatureGate. + // Top-level commands/options setup that needs to modify this feature gate should use DefaultMutableFeatureGate. + DefaultFeatureGate featuregate.FeatureGate = DefaultMutableFeatureGate +) + +func init() { + runtime.Must(DefaultMutableFeatureGate.Add(defaultRavenFeatureGates)) +} + +const ( + // RavenL7Proxy setups and serves a L7 proxy. + // + // owner: @luckymrwang + // alpha: v0.3.1 + // Setting on openyurt and raven-agent side. + RavenL7Proxy featuregate.Feature = "RavenL7Proxy" +) + +// defaultRavenFeatureGates consists of all known Kubernetes-specific and raven feature keys. +// To add a new feature, define a key for it above and add it here. The features will be +// available throughout raven binaries. +var defaultRavenFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ + RavenL7Proxy: {Default: false, PreRelease: featuregate.Alpha, LockToDefault: false}, +} diff --git a/raven.sh b/raven.sh index 4704b1f..bd97a3d 100755 --- a/raven.sh +++ b/raven.sh @@ -21,4 +21,4 @@ set -e -x [ "$(cat /proc/sys/net/ipv4/conf/all/send_redirects)" = 0 ] || echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects # run raven agent -exec agent --node-name="$NODE_NAME" --vpn-driver="$VPN_DRIVER" --forward-node-ip="$FORWARD_NODE_IP" --metric-bind-addr="$METRIC_BIND_ADDR" \ No newline at end of file +exec agent --node-name="$NODE_NAME" --vpn-driver="$VPN_DRIVER" --forward-node-ip="$FORWARD_NODE_IP" --metric-bind-addr="$METRIC_BIND_ADDR" --feature-gates="$FEATURE_GATES" \ No newline at end of file