Skip to content

Commit

Permalink
feat: add feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
luckymrwang committed Apr 18, 2023
1 parent 34be312 commit b847091
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/agent/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,6 +53,7 @@ func NewRavenAgentCommand(ctx context.Context) *cobra.Command {
}

agentOptions.AddFlags(cmd.Flags())
features.DefaultMutableFeatureGate.AddFlag(cmd.Flags())
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
@@ -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},
}
2 changes: 1 addition & 1 deletion raven.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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"

0 comments on commit b847091

Please sign in to comment.