Skip to content

Commit

Permalink
title: Add ipsec tunnel mode to support cross clusters and elastic ip
Browse files Browse the repository at this point in the history
Signed-off-by: GreatLazyMan <[email protected]>
  • Loading branch information
GreatLazyMan committed Jan 17, 2024
1 parent 42f2476 commit d1a6fda
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 33 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/kosmos/v1alpha1/nodeconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func (a *Arp) Compare(v Arp) bool {
a.Dev == v.Dev
}

/*
Just like linux command:
ip xfrm policy add src $LeftNet dst $RightNet dir $Dir \
tmpl src $LeftIP dst $RightIP proto esp reqid $ReqID mode tunnel
*/
type XfrmPolicy struct {
LeftIP string `json:"leftip"`
LeftNet string `json:"leftnet"`
Expand All @@ -122,6 +128,11 @@ func (a *XfrmPolicy) Compare(v XfrmPolicy) bool {
a.Dir == v.Dir
}

/*
Just like linux command:
ip xfrm state add src $LeftIP dst $RightIP proto esp spi $SPI reqid $ReqID mode tunnel aead 'rfc4106(gcm(aes))' $PSK 128
*/
type XfrmState struct {
LeftIP string `json:"leftip"`
RightIP string `json:"rightip"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (c *Controller) Reconcile(key utils.QueueKey) error {
}

klog.Infof("start reconcile cluster %s", cluster.Name)
if cluster.Name == c.clusterName && cluster.Spec.ClusterLinkOptions.CNI != utils.CNITypeCalico {
if cluster.Spec.ClusterLinkOptions.CNI != utils.CNITypeCalico {
klog.Infof("cluster %s cni type is %s skip reconcile", cluster.Name, cluster.Spec.ClusterLinkOptions.CNI)
return nil
}
Expand Down
26 changes: 2 additions & 24 deletions pkg/clusterlink/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ const (
KubeFlannelNetworkConf = "net-conf.json"
KubeFlannelIPPool = "Network"
KubeSystemNamespace = "kube-system"
InvalidService = `
apiVersion: v1
kind: Service
metadata:
labels:
kosmos.io/app: coredns
name: invalidsvc
namespace: {{ .Namespace }}
spec:
clusterIP: 8.8.8.8
clusterIPs:
- 8.8.8.8
ipFamilies:
- IPv4
ports:
- name: dns
port: 53
protocol: UDP
targetPort: 53
selector:
invalid/app: null
sessionAffinity: None
type: ClusterIP
`
)

type SetClusterPodCIDRFun func(cluster *clusterlinkv1alpha1.Cluster) error
Expand Down Expand Up @@ -135,7 +111,9 @@ func (c *Controller) Start(ctx context.Context) error {
var podFilterFunc func(pod *corev1.Pod) bool
if cluster.Spec.ClusterLinkOptions.UseExternalApiserver {
podFilterFunc = func(pod *corev1.Pod) bool {
// TODO: find a better way
// some k8s, apiserver not a pod in cluster, maybe not a good way
// so we choose some kube-system pod and clusterlink-controller-manager itself as filter
return pod.Labels["k8s-app"] == "kube-proxy" || pod.Labels["app"] == "clusterlink-controller-manager"
}
} else {
Expand Down
28 changes: 28 additions & 0 deletions pkg/clusterlink/controllers/cluster/invalid_manifest_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cluster

const (
InvalidService = `
apiVersion: v1
kind: Service
metadata:
labels:
kosmos.io/app: coredns
name: invalidsvc
namespace: {{ .Namespace }}
spec:
clusterIP: 8.8.8.8
clusterIPs:
- 8.8.8.8
ipFamilies:
- IPv4
ports:
- name: dns
port: 53
protocol: UDP
targetPort: 53
selector:
invalid/app: null
sessionAffinity: None
type: ClusterIP
`
)
1 change: 1 addition & 0 deletions pkg/clusterlink/elector/elector.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (e *Elector) EnsureGateWayRole() error {

if needReelect {
if !isCurrentNodeWithEIP && len(readyNodes) > 0 {
// TODO: now choose first one, find a better way
sort.Strings(readyNodes)
e.nodeName = readyNodes[0]
} else {
Expand Down
10 changes: 2 additions & 8 deletions pkg/clusterlink/network/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@ func init() {
return
}
if len(ret_nft) > len(ret_legacy) {
klog.Info("use iptables-nft as default iptables")
_, err := execInterface.Command("ln", []string{"-sf", "/sbin/xtables-nft-multi", "/sbin/iptables"}...).CombinedOutput()
err := os.Setenv("IPTABLES_PATH", "/sbin/xtables-nft-multi")
if err != nil {
klog.Errorf("%s: %v", errInfo, err)
return
}
_, err = execInterface.Command("ln", []string{"-sf", "/sbin/xtables-nft-multi", "/sbin/ip6tables"}...).CombinedOutput()
if err != nil {
klog.Errorf("%s: %v", errInfo, err)
klog.Errorf("%s, set env error: %v", errInfo, err)
return
}
}
Expand Down

0 comments on commit d1a6fda

Please sign in to comment.