Skip to content

Commit

Permalink
Merge pull request #164 from River-sh/bugfix/panic_for_wireguard
Browse files Browse the repository at this point in the history
Bugfix/panic for wireguard
  • Loading branch information
njucjc authored Mar 4, 2024
2 parents 593aa0e + 23c53a1 commit 654d9d3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions charts/raven-agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.4.0
version: 0.4.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.4.0"
appVersion: "0.4.1"
2 changes: 1 addition & 1 deletion charts/raven-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ image:
repository: openyurt/raven-agent
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 0.4.0
tag: 0.4.1

imagePullSecrets: []
nameOverride: ""
Expand Down
27 changes: 16 additions & 11 deletions cmd/agent/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/openyurtio/raven/pkg/networkengine/routedriver/vxlan"
"github.com/openyurtio/raven/pkg/networkengine/vpndriver"
"github.com/openyurtio/raven/pkg/networkengine/vpndriver/libreswan"
"github.com/openyurtio/raven/pkg/networkengine/vpndriver/wireguard"
"github.com/openyurtio/raven/pkg/utils"
)

Expand Down Expand Up @@ -71,16 +72,9 @@ type ProxyOptions struct {

// Validate validates the AgentOptions
func (o *AgentOptions) Validate() error {
if o.NodeName == "" {
o.NodeName = os.Getenv("NODE_NAME")
if o.NodeName == "" {
return errors.New("either --node-name or $NODE_NAME has to be set")
}
}
if o.NodeIP == "" {
o.NodeIP = os.Getenv("NODE_IP")
if o.NodeIP == "" {
return errors.New("either --node-ip or $NODE_IP has to be set")
if o.VPNDriver != "" {
if o.VPNDriver != libreswan.DriverName && o.VPNDriver != wireguard.DriverName {
return errors.New("currently only supports libreswan and wireguard VPN drivers")
}
}
return nil
Expand Down Expand Up @@ -114,7 +108,18 @@ func (o *AgentOptions) AddFlags(fs *pflag.FlagSet) {

// Config return a raven agent config objective
func (o *AgentOptions) Config() (*config.Config, error) {
var err error
if o.NodeName == "" {
o.NodeName = os.Getenv("NODE_NAME")
if o.NodeName == "" {
return nil, errors.New("either --node-name or $NODE_NAME has to be set")
}
}
if o.NodeIP == "" {
o.NodeIP = os.Getenv("NODE_IP")
if o.NodeIP == "" {
return nil, errors.New("either --node-ip or $NODE_IP has to be set")
}
}
cfg, err := clientcmd.BuildConfigFromFlags("", o.Kubeconfig)
if err != nil {
return nil, fmt.Errorf("failed to create kube client: %s", err)
Expand Down
18 changes: 15 additions & 3 deletions pkg/networkengine/vpndriver/libreswan/libreswan.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ func (l *libreswan) createRelayConnections(desiredRelayConns map[string]*vpndriv
continue
}
if l.centralGw.NodeName == l.nodeName {
errList = errList.Append(l.deleteRavenSkipNAT(l.relayConnections[connName]))
if conn, ok := l.relayConnections[connName]; ok && conn != nil {
err := l.deleteRavenSkipNAT(conn)
if err != nil {
errList = errList.Append(err)
}
}
}
delete(l.relayConnections, connName)
}
Expand All @@ -256,7 +261,9 @@ func (l *libreswan) createRelayConnections(desiredRelayConns map[string]*vpndriv
errList = errList.Append(err)
if l.centralGw.NodeName == l.nodeName {
err = l.ensureRavenSkipNAT(connection)
errList = errList.Append(err)
if err != nil {
errList = errList.Append(err)
}
}
}

Expand Down Expand Up @@ -465,7 +472,12 @@ func (l *libreswan) Cleanup() error {
klog.ErrorS(err, "fail to delete connection", "connectionName", name)
}
if l.centralGw != nil && l.centralGw.NodeName == l.nodeName {
errList = errList.Append(l.deleteRavenSkipNAT(l.relayConnections[name]))
if conn, ok := l.relayConnections[name]; ok && conn != nil {
err := l.deleteRavenSkipNAT(conn)
if err != nil {
errList = errList.Append(err)
}
}
}
}
for name := range l.edgeConnections {
Expand Down

0 comments on commit 654d9d3

Please sign in to comment.