Skip to content

Commit

Permalink
Merge pull request #444 from lostcharlie/merge-modules
Browse files Browse the repository at this point in the history
Combine all components into "fabedge-node"
  • Loading branch information
foriner-phryne authored Mar 20, 2024
2 parents 86d4be2 + a403541 commit 4d44cdf
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OUTPUT_DIR := _output
BINARIES := agent connector operator cloud-agent
BINARIES := agent connector operator cloud-agent node
IMAGES := $(addsuffix -image, ${BINARIES})

VERSION := $(shell git describe --tags)
Expand Down
16 changes: 16 additions & 0 deletions build/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.17.13 as builder
COPY . /fabedge
RUN cd /fabedge && make node QUICK=1 CGO_ENABLED=0 GOPROXY=https://goproxy.cn,direct

FROM fabedge/cni-plugins:v1.4.0 as cni-plugins
FROM fabedge/base-image:0.1.0

COPY --from=builder /fabedge/_output/fabedge-node /usr/local/bin/node
COPY --from=builder /fabedge/build/node/*.sh /
COPY --from=cni-plugins /plugins/ /plugins

RUN apk --update add keepalived curl && \
rm -rf /var/cache/apk/* && \
chmod +x /entrypoint.sh /check-connector-leader.sh

ENTRYPOINT ["/entrypoint.sh"]
13 changes: 13 additions & 0 deletions build/node/check-connector-leader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env sh
is_leader=`curl -s http://127.0.0.1:30306/is-leader`
exit_code=$?

if [ $exit_code != 0 ]; then
exit $exit_code
fi

if [ $is_leader == "true" ]; then
exit 0
else
exit 1
fi
10 changes: 10 additions & 0 deletions build/node/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -e

echo 'select between the two modes of iptables ("legacy" and "nft")'
/iptables-wrapper-installer.sh

cmd="/usr/local/bin/node $@"
echo "entrypoint: run command: $cmd"

exec $cmd
18 changes: 15 additions & 3 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@
package main

import (
"os"

"github.com/fabedge/fabedge/pkg/agent"
logutil "github.com/fabedge/fabedge/pkg/util/log"
flag "github.com/spf13/pflag"
"os"
"time"
)

func main() {
if err := agent.Execute(); err != nil {
fs := flag.CommandLine
cfg := &agent.Config{}

logutil.AddFlags(fs)
cfg.AddFlags(fs)
fs.DurationVar(&cfg.SyncPeriod, "sync-period", 30*time.Second, "The period to synchronize network configuration")
fs.UintVar(&cfg.TunnelInitTimeout, "tunnel-init-timeout", 10, "The timeout of tunnel initiation. Uint: second")

flag.Parse()

if err := agent.Execute(cfg); err != nil {
os.Exit(1)
}
}
13 changes: 12 additions & 1 deletion cmd/cloud-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ package main

import (
"github.com/fabedge/fabedge/pkg/cloud-agent"
"github.com/fabedge/fabedge/pkg/common/about"
logutil "github.com/fabedge/fabedge/pkg/util/log"
flag "github.com/spf13/pflag"
)

func main() {
cloud_agent.Execute()
var initMembers []string

flag.StringSliceVar(&initMembers, "connector-node-addresses", []string{}, "internal ip address of all connector nodes")
logutil.AddFlags(flag.CommandLine)
about.AddFlags(flag.CommandLine)

flag.Parse()

cloud_agent.Execute(initMembers)
}
23 changes: 22 additions & 1 deletion cmd/connector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,30 @@
package main

import (
"github.com/fabedge/fabedge/pkg/common/about"
"github.com/fabedge/fabedge/pkg/connector"
logutil "github.com/fabedge/fabedge/pkg/util/log"
flag "github.com/spf13/pflag"
"time"
)

func main() {
connector.Execute()
fs := flag.CommandLine
cfg := &connector.Config{}

logutil.AddFlags(fs)
about.AddFlags(fs)
cfg.AddFlags(fs)

fs.StringVar(&cfg.CNIType, "cni-type", "flannel", "CNI type used in cloud")
fs.DurationVar(&cfg.LeaderElection.LeaseDuration, "leader-lease-duration", 15*time.Second, "The duration that non-leader candidates will wait to force acquire leadership")
fs.DurationVar(&cfg.LeaderElection.RenewDeadline, "leader-renew-deadline", 10*time.Second, "The duration that the acting controlplane will retry refreshing leadership before giving up")
fs.DurationVar(&cfg.LeaderElection.RetryPeriod, "leader-retry-period", 2*time.Second, "The duration that the LeaderElector clients should wait between tries of actions")
fs.StringSliceVar(&cfg.InitMembers, "connector-node-addresses", []string{}, "internal address of all connector nodes")
fs.DurationVar(&cfg.SyncPeriod, "sync-period", 5*time.Minute, "period to sync routes/rules")
fs.UintVar(&cfg.TunnelInitTimeout, "tunnel-init-timeout", 10, "The timeout of tunnel initiation. Unit: second")

flag.Parse()

connector.Execute(cfg)
}
89 changes: 89 additions & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package main

import (
"fmt"
"github.com/fabedge/fabedge/pkg/agent"
"github.com/fabedge/fabedge/pkg/cloud-agent"
"github.com/fabedge/fabedge/pkg/common/about"
"github.com/fabedge/fabedge/pkg/connector"
"github.com/fabedge/fabedge/pkg/operator"
logutil "github.com/fabedge/fabedge/pkg/util/log"
flag "github.com/spf13/pflag"
"os"
"time"
)

func main() {
var component string

fs := flag.CommandLine
fs.StringVar(&component, "component", "", "the component to initiate")

// common
var cniType string
var leaseDuration time.Duration
var renewDeadline time.Duration
var retryPeriod time.Duration
var syncPeriod time.Duration
var tunnelInitTimeout uint

// cloud-agent
var initMembers []string
fs.StringSliceVar(&initMembers, "connector-node-addresses", []string{}, "internal ip address of all connector nodes")

// common
fs.StringVar(&cniType, "cni-type", "", "The CNI name in your kubernetes cluster")
fs.DurationVar(&leaseDuration, "leader-lease-duration", 15*time.Second, "The duration that non-leader candidates will wait to force acquire leadership")
fs.DurationVar(&renewDeadline, "leader-renew-deadline", 10*time.Second, "The duration that the acting controlplane will retry refreshing leadership before giving up")
fs.DurationVar(&retryPeriod, "leader-retry-period", 2*time.Second, "The duration that the LeaderElector clients should wait between tries of actions")
fs.UintVar(&tunnelInitTimeout, "tunnel-init-timeout", 10, "The timeout of tunnel initiation. Uint: second")
// agent: 30s, connector: 5m
fs.DurationVar(&syncPeriod, "sync-period", 30*time.Second, "The period to synchronize network configuration")

// operator
operatorConfig := &operator.Options{}
operatorConfig.AddFlags(fs)

// connector
connectorConfig := &connector.Config{}
connectorConfig.AddFlags(fs)

// agent
agentConfig := &agent.Config{}
agentConfig.AddFlags(fs)

logutil.AddFlags(fs)
about.AddFlags(fs)

flag.Parse()

fmt.Printf("component: %s\n", component)

switch component {
case "cloud-agent":
cloud_agent.Execute(initMembers)
case "operator":
operatorConfig.CNIType = cniType
operatorConfig.ManagerOpts.LeaseDuration = &leaseDuration
operatorConfig.ManagerOpts.RenewDeadline = &renewDeadline
operatorConfig.ManagerOpts.RetryPeriod = &retryPeriod
if err := operator.Execute(operatorConfig); err != nil {
os.Exit(1)
}
case "connector":
connectorConfig.CNIType = cniType
connectorConfig.SyncPeriod = syncPeriod
connectorConfig.InitMembers = initMembers
connectorConfig.LeaderElection.LeaseDuration = leaseDuration
connectorConfig.LeaderElection.RenewDeadline = renewDeadline
connectorConfig.LeaderElection.RetryPeriod = retryPeriod
connectorConfig.TunnelInitTimeout = tunnelInitTimeout
connector.Execute(connectorConfig)
case "agent":
agentConfig.SyncPeriod = syncPeriod
agentConfig.TunnelInitTimeout = tunnelInitTimeout
if err := agent.Execute(agentConfig); err != nil {
os.Exit(1)
}
}
}
20 changes: 19 additions & 1 deletion cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,31 @@
package main

import (
"github.com/fabedge/fabedge/pkg/common/about"
logutil "github.com/fabedge/fabedge/pkg/util/log"
flag "github.com/spf13/pflag"
"os"
"time"

"github.com/fabedge/fabedge/pkg/operator"
)

func main() {
if err := operator.Execute(); err != nil {
opts := &operator.Options{}

fs := flag.CommandLine
logutil.AddFlags(fs)
about.AddFlags(fs)
opts.AddFlags(fs)

flag.StringVar(&opts.CNIType, "cni-type", "", "The CNI name in your kubernetes cluster")
opts.ManagerOpts.LeaseDuration = flag.Duration("leader-lease-duration", 15*time.Second, "The duration that non-leader candidates will wait to force acquire leadership")
opts.ManagerOpts.RenewDeadline = flag.Duration("leader-renew-deadline", 10*time.Second, "The duration that the acting controlplane will retry refreshing leadership before giving up")
opts.ManagerOpts.RetryPeriod = flag.Duration("leader-retry-period", 2*time.Second, "The duration that the LeaderElector clients should wait between tries of actions")

flag.Parse()

if err := operator.Execute(opts); err != nil {
os.Exit(1)
}
}
1 change: 1 addition & 0 deletions deploy/cloud-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ spec:
containers:
- args:
- --connector-node-addresses=10.20.8.12
- --component=cloud-agent
- -v=5
image: fabedge/cloud-agent
imagePullPolicy: IfNotPresent
Expand Down
1 change: 1 addition & 0 deletions deploy/connector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ spec:
- --cni-type=calico
- --sync-period=1m
- --connector-node-addresses=10.20.8.28
- --component=connector
- -v=5
volumeMounts:
- name: var-run
Expand Down
5 changes: 4 additions & 1 deletion deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ spec:
- --connector-subnets=10.233.0.0/18
# 边缘节点生成的证书的ID的格式,{node}会被替换为节点名称
- --endpoint-id-format=C=CN, O=fabedge.io, CN={node}
- --component=operator
- -v=5
# 用环境变量配置agent的参数,每个参数都是'AGENT_ARG_'开头
# 需要注意的是,日志级别必须用'AGENT_ARG_LOG_LEVEL'来配置
Expand All @@ -67,7 +68,9 @@ spec:
- name: AGENT_ARG_USE_XFRM
value: "false"
- name: AGENT_ARG_AUTO_NETWORKING
value: "false"
value: "false"
- name: AGENT_ARG_COMPONENT
value: "agent"
- name: AGENT_ARG_MULTICAST_TOKEN
value: "e6a7ca28-ae6a-45bf-8162-e2374a4a48c1"
# ports, volumeMounts, readinessProbe配置仅限于cluster-role是host时使用
Expand Down
11 changes: 1 addition & 10 deletions pkg/agent/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,11 @@ import (
"k8s.io/klog/v2/klogr"

"github.com/fabedge/fabedge/pkg/common/about"
logutil "github.com/fabedge/fabedge/pkg/util/log"
)

func Execute() error {
func Execute(cfg *Config) error {
defer klog.Flush()

fs := flag.CommandLine
cfg := &Config{}

logutil.AddFlags(fs)
cfg.AddFlags(fs)

flag.Parse()

// the version flag is added by importing kube-proxy packages,
// but I don't know how that happened
if flag.Lookup("version").Value.String() == "true" {
Expand Down
2 changes: 0 additions & 2 deletions pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (cfg *Config) AddFlags(fs *pflag.FlagSet) {

fs.StringSliceVar(&cfg.LocalCerts, "local-cert", []string{"edgecert.pem"}, "The path to cert files, comma separated. If it's a relative path, the cert file should be put under /etc/ipsec.d/certs")
fs.DurationVar(&cfg.DebounceDuration, "debounce", time.Second, "The debounce delay to avoid too much network reconfiguring")
fs.DurationVar(&cfg.SyncPeriod, "sync-period", 30*time.Second, "The period to synchronize network configuration")

fs.BoolVar(&cfg.EnableHairpinMode, "enable-hairpinmode", true, "enable the Hairpin feature")
fs.IntVar(&cfg.NetworkPluginMTU, "network-plugin-mtu", 1400, "Set network plugin MTU for edge nodes")
Expand Down Expand Up @@ -112,7 +111,6 @@ func (cfg *Config) AddFlags(fs *pflag.FlagSet) {
fs.DurationVar(&cfg.BackupInterval, "backup-interval", 10*time.Second, "The interval between local endpoints backing up")
fs.DurationVar(&cfg.EndpointTTL, "endpoint-ttl", 20*time.Second, "The time to live for endpoint received from multicasting")

fs.UintVar(&cfg.TunnelInitTimeout, "tunnel-init-timeout", 10, "The timeout of tunnel initiation. Uint: second")
}

func (cfg *Config) Validate() error {
Expand Down
12 changes: 1 addition & 11 deletions pkg/cloud-agent/cloud_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"github.com/bep/debounce"
flag "github.com/spf13/pflag"
"github.com/vishvananda/netlink"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
Expand All @@ -33,7 +32,6 @@ import (
"github.com/fabedge/fabedge/pkg/common/about"
"github.com/fabedge/fabedge/pkg/common/constants"
"github.com/fabedge/fabedge/pkg/connector/routing"
logutil "github.com/fabedge/fabedge/pkg/util/log"
"github.com/fabedge/fabedge/pkg/util/memberlist"
routeutil "github.com/fabedge/fabedge/pkg/util/route"
)
Expand All @@ -52,17 +50,9 @@ type CloudAgent struct {
routesByHost map[string][]netlink.Route
}

func Execute() {
func Execute(initMembers []string) {
defer klog.Flush()

var initMembers []string

flag.StringSliceVar(&initMembers, "connector-node-addresses", []string{}, "internal ip address of all connector nodes")
logutil.AddFlags(flag.CommandLine)
about.AddFlags(flag.CommandLine)

flag.Parse()

about.DisplayAndExitIfRequested()

if len(initMembers) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/about/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
)

func AddFlags(fs *pflag.FlagSet) {
showVersion = fs.Bool("version", false, "Display version info")
showVersion = fs.Bool("show-version", false, "Display version info")
}

func DisplayAndExitIfRequested() {
Expand Down
13 changes: 1 addition & 12 deletions pkg/connector/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,14 @@
package connector

import (
flag "github.com/spf13/pflag"
"k8s.io/klog/v2"

"github.com/fabedge/fabedge/pkg/common/about"
logutil "github.com/fabedge/fabedge/pkg/util/log"
)

func Execute() {
func Execute(cfg *Config) {
defer klog.Flush()

fs := flag.CommandLine
cfg := &Config{}

logutil.AddFlags(fs)
about.AddFlags(fs)
cfg.AddFlags(fs)

flag.Parse()

about.DisplayAndExitIfRequested()

manger, err := cfg.Manager()
Expand Down
Loading

0 comments on commit 4d44cdf

Please sign in to comment.