@@ -12,7 +12,6 @@ import (
1212
1313 "github.com/spf13/pflag"
1414 v1 "k8s.io/api/core/v1"
15- "k8s.io/apimachinery/pkg/api/meta"
1615 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1716 "k8s.io/apimachinery/pkg/runtime"
1817 "k8s.io/apiserver/pkg/endpoints/discovery"
@@ -21,25 +20,21 @@ import (
2120 "k8s.io/client-go/tools/clientcmd"
2221 "k8s.io/klog/v2"
2322 ctrl "sigs.k8s.io/controller-runtime"
24- "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
2523 "sigs.k8s.io/controller-runtime/pkg/healthz"
2624 "sigs.k8s.io/controller-runtime/pkg/manager"
25+ metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2726
2827 "github.com/openyurtio/api/raven/v1beta1"
2928 "github.com/openyurtio/raven/cmd/agent/app/config"
30- "github.com/openyurtio/raven/pkg/networkengine/routedriver/vxlan"
31- "github.com/openyurtio/raven/pkg/networkengine/vpndriver"
3229 "github.com/openyurtio/raven/pkg/networkengine/vpndriver/libreswan"
3330 "github.com/openyurtio/raven/pkg/networkengine/vpndriver/wireguard"
34- "github.com/openyurtio/raven/pkg/utils"
3531)
3632
3733const (
3834 DefaultTunnelMetricsPort = 10265
3935 DefaultProxyMetricsPort = 10266
4036 DefaultHealthyProbeAddr = 10275
4137 DefaultLocalHost = "127.0.0.1"
42- DefaultMACPrefix = "aa:0f"
4338)
4439
4540// AgentOptions has the information that required by the raven agent
@@ -80,26 +75,32 @@ type ProxyOptions struct {
8075
8176// Validate validates the AgentOptions
8277func (o * AgentOptions ) Validate () error {
83- if o .VPNDriver != "" {
84- if o .VPNDriver != libreswan .DriverName && o .VPNDriver != wireguard .DriverName {
85- return errors .New ("currently only supports libreswan and wireguard VPN drivers" )
86- }
78+ if o .NodeName == "" {
79+ return errors .New ("either --node-name or $NODE_NAME has to be set" )
80+ }
81+ if o .NodeIP == "" {
82+ return errors .New ("either --node-ip or $NODE_IP has to be set" )
83+ }
84+
85+ if o .VPNDriver != libreswan .DriverName && o .VPNDriver != wireguard .DriverName {
86+ return errors .New ("currently only supports libreswan and wireguard VPN drivers" )
8787 }
88- if o .MACPrefix != "" {
89- reg := regexp .MustCompile (`^[0-9a-fA-F]+$` )
90- strs := strings .Split (o .MACPrefix , ":" )
91- for i := range strs {
92- if ! reg .MatchString (strings .ToLower (strs [i ])) {
93- return fmt .Errorf ("mac prefix %s is nonstandard" , o .MACPrefix )
94- }
88+
89+ reg := regexp .MustCompile (`^[0-9a-fA-F]+$` )
90+ strs := strings .Split (o .MACPrefix , ":" )
91+ for i := range strs {
92+ if ! reg .MatchString (strings .ToLower (strs [i ])) {
93+ return fmt .Errorf ("mac prefix %s is nonstandard" , o .MACPrefix )
9594 }
9695 }
96+
9797 if o .SyncPeriod .Duration < time .Minute {
9898 o .SyncPeriod .Duration = time .Minute
9999 }
100100 if o .SyncPeriod .Duration > 24 * time .Hour {
101101 o .SyncPeriod .Duration = 24 * time .Hour
102102 }
103+
103104 return nil
104105}
105106
@@ -134,18 +135,6 @@ func (o *AgentOptions) AddFlags(fs *pflag.FlagSet) {
134135
135136// Config return a raven agent config objective
136137func (o * AgentOptions ) Config () (* config.Config , error ) {
137- if o .NodeName == "" {
138- o .NodeName = os .Getenv ("NODE_NAME" )
139- if o .NodeName == "" {
140- return nil , errors .New ("either --node-name or $NODE_NAME has to be set" )
141- }
142- }
143- if o .NodeIP == "" {
144- o .NodeIP = os .Getenv ("NODE_IP" )
145- if o .NodeIP == "" {
146- return nil , errors .New ("either --node-ip or $NODE_IP has to be set" )
147- }
148- }
149138 cfg , err := clientcmd .BuildConfigFromFlags ("" , o .Kubeconfig )
150139 if err != nil {
151140 return nil , fmt .Errorf ("failed to create kube client: %s" , err )
@@ -191,27 +180,6 @@ func (o *AgentOptions) Config() (*config.Config, error) {
191180 ProxyServerCertDir : o .ProxyServerCertDir ,
192181 InterceptorServerUDSFile : o .InterceptorServerUDSFile ,
193182 }
194- if c .Tunnel .VPNDriver == "" {
195- c .Tunnel .VPNDriver = libreswan .DriverName
196- }
197- if c .Tunnel .RouteDriver == "" {
198- c .Tunnel .RouteDriver = vxlan .DriverName
199- }
200- if c .Tunnel .VPNPort == "" {
201- c .Tunnel .VPNPort = vpndriver .DefaultVPNPort
202- }
203- if c .Tunnel .MACPrefix == "" {
204- c .Tunnel .MACPrefix = DefaultMACPrefix
205- }
206- if c .Proxy .ProxyClientCertDir == "" {
207- c .Proxy .ProxyClientCertDir = utils .RavenProxyClientCertDir
208- }
209- if c .Proxy .ProxyServerCertDir == "" {
210- c .Proxy .ProxyServerCertDir = utils .RavenProxyServerCertDir
211- }
212- if c .Proxy .InterceptorServerUDSFile == "" {
213- c .Proxy .InterceptorServerUDSFile = utils .RavenProxyServerUDSFile
214- }
215183
216184 c .Proxy .InternalInsecureAddress = resolveAddress (c .Proxy .InternalInsecureAddress , c .NodeIP , strconv .Itoa (v1beta1 .DefaultProxyServerInsecurePort ))
217185 c .Proxy .InternalSecureAddress = resolveAddress (c .Proxy .InternalSecureAddress , c .NodeIP , strconv .Itoa (v1beta1 .DefaultProxyServerSecurePort ))
@@ -227,16 +195,11 @@ func newMgr(cfg *restclient.Config, metricsBindAddress, healthyProbeAddress stri
227195 _ = v1beta1 .AddToScheme (scheme )
228196
229197 opt := ctrl.Options {
230- Scheme : scheme ,
231- MetricsBindAddress : metricsBindAddress ,
232- HealthProbeBindAddress : healthyProbeAddress ,
233- MapperProvider : func (c * restclient.Config ) (meta.RESTMapper , error ) {
234- opt := func () (meta.RESTMapper , error ) {
235- return restmapper .NewDiscoveryRESTMapper (
236- []* restmapper.APIGroupResources {getGatewayAPIGroupResource (), getLegacyAPIGroupResource ()}), nil
237- }
238- return apiutil .NewDynamicRESTMapper (c , apiutil .WithCustomMapper (opt ))
198+ Scheme : scheme ,
199+ Metrics : metricsserver.Options {
200+ BindAddress : metricsBindAddress ,
239201 },
202+ HealthProbeBindAddress : healthyProbeAddress ,
240203 }
241204
242205 mgr , err := ctrl .NewManager (cfg , opt )
0 commit comments