Skip to content

Commit 2d3315e

Browse files
committed
upgrade anp to 0.34.0
1 parent 2b153e5 commit 2d3315e

File tree

11 files changed

+530
-1260
lines changed

11 files changed

+530
-1260
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.18 as builder
2+
FROM golang:1.25 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

cmd/agent/app/options/options.go

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3733
const (
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
8277
func (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
136137
func (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)

cmd/agent/app/start.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,47 @@ package app
1818

1919
import (
2020
"context"
21+
"flag"
2122
"fmt"
23+
"os"
2224
"sync"
2325
"time"
2426

2527
"github.com/lorenzosaino/go-sysctl"
2628
"github.com/spf13/cobra"
2729
"k8s.io/klog/v2"
30+
ctrl "sigs.k8s.io/controller-runtime"
31+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2832

2933
"github.com/openyurtio/raven/cmd/agent/app/config"
3034
"github.com/openyurtio/raven/cmd/agent/app/options"
3135
ravenengine "github.com/openyurtio/raven/pkg/engine"
3236
"github.com/openyurtio/raven/pkg/features"
37+
"github.com/openyurtio/raven/pkg/networkengine/routedriver/vxlan"
38+
"github.com/openyurtio/raven/pkg/networkengine/vpndriver"
39+
"github.com/openyurtio/raven/pkg/networkengine/vpndriver/libreswan"
40+
"github.com/openyurtio/raven/pkg/utils"
3341
)
3442

3543
// NewRavenAgentCommand creates a new raven agent command
44+
3645
func NewRavenAgentCommand(ctx context.Context) *cobra.Command {
37-
agentOptions := &options.AgentOptions{}
46+
agentOptions := &options.AgentOptions{
47+
TunnelOptions: options.TunnelOptions{
48+
VPNDriver: libreswan.DriverName,
49+
RouteDriver: vxlan.DriverName,
50+
VPNPort: vpndriver.DefaultVPNPort,
51+
MACPrefix: "aa:0f",
52+
},
53+
ProxyOptions: options.ProxyOptions{
54+
ProxyClientCertDir: utils.RavenProxyClientCertDir,
55+
ProxyServerCertDir: utils.RavenProxyServerCertDir,
56+
InterceptorServerUDSFile: utils.RavenProxyServerUDSFile,
57+
},
58+
NodeName: os.Getenv("NODE_NAME"),
59+
NodeIP: os.Getenv("NODE_IP"),
60+
}
61+
3862
cmd := &cobra.Command{
3963
Short: fmt.Sprintf("Launch %s", "raven-agent"),
4064
RunE: func(c *cobra.Command, args []string) error {
@@ -55,6 +79,13 @@ func NewRavenAgentCommand(ctx context.Context) *cobra.Command {
5579

5680
agentOptions.AddFlags(cmd.Flags())
5781
features.DefaultMutableFeatureGate.AddFlag(cmd.Flags())
82+
83+
opts := zap.Options{
84+
Development: true,
85+
}
86+
opts.BindFlags(flag.CommandLine)
87+
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
88+
5889
return cmd
5990
}
6091

0 commit comments

Comments
 (0)