Skip to content

Commit d1a6fda

Browse files
committed
title: Add ipsec tunnel mode to support cross clusters and elastic ip
Signed-off-by: GreatLazyMan <[email protected]>
1 parent 42f2476 commit d1a6fda

File tree

6 files changed

+45
-33
lines changed

6 files changed

+45
-33
lines changed

pkg/apis/kosmos/v1alpha1/nodeconfig_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ func (a *Arp) Compare(v Arp) bool {
104104
a.Dev == v.Dev
105105
}
106106

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

131+
/*
132+
Just like linux command:
133+
134+
ip xfrm state add src $LeftIP dst $RightIP proto esp spi $SPI reqid $ReqID mode tunnel aead 'rfc4106(gcm(aes))' $PSK 128
135+
*/
125136
type XfrmState struct {
126137
LeftIP string `json:"leftip"`
127138
RightIP string `json:"rightip"`

pkg/clusterlink/controllers/calicoippool/calicoippool_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (c *Controller) Reconcile(key utils.QueueKey) error {
339339
}
340340

341341
klog.Infof("start reconcile cluster %s", cluster.Name)
342-
if cluster.Name == c.clusterName && cluster.Spec.ClusterLinkOptions.CNI != utils.CNITypeCalico {
342+
if cluster.Spec.ClusterLinkOptions.CNI != utils.CNITypeCalico {
343343
klog.Infof("cluster %s cni type is %s skip reconcile", cluster.Name, cluster.Spec.ClusterLinkOptions.CNI)
344344
return nil
345345
}

pkg/clusterlink/controllers/cluster/cluster_controller.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,6 @@ const (
5050
KubeFlannelNetworkConf = "net-conf.json"
5151
KubeFlannelIPPool = "Network"
5252
KubeSystemNamespace = "kube-system"
53-
InvalidService = `
54-
apiVersion: v1
55-
kind: Service
56-
metadata:
57-
labels:
58-
kosmos.io/app: coredns
59-
name: invalidsvc
60-
namespace: {{ .Namespace }}
61-
spec:
62-
clusterIP: 8.8.8.8
63-
clusterIPs:
64-
- 8.8.8.8
65-
ipFamilies:
66-
- IPv4
67-
ports:
68-
- name: dns
69-
port: 53
70-
protocol: UDP
71-
targetPort: 53
72-
selector:
73-
invalid/app: null
74-
sessionAffinity: None
75-
type: ClusterIP
76-
`
7753
)
7854

7955
type SetClusterPodCIDRFun func(cluster *clusterlinkv1alpha1.Cluster) error
@@ -135,7 +111,9 @@ func (c *Controller) Start(ctx context.Context) error {
135111
var podFilterFunc func(pod *corev1.Pod) bool
136112
if cluster.Spec.ClusterLinkOptions.UseExternalApiserver {
137113
podFilterFunc = func(pod *corev1.Pod) bool {
114+
// TODO: find a better way
138115
// some k8s, apiserver not a pod in cluster, maybe not a good way
116+
// so we choose some kube-system pod and clusterlink-controller-manager itself as filter
139117
return pod.Labels["k8s-app"] == "kube-proxy" || pod.Labels["app"] == "clusterlink-controller-manager"
140118
}
141119
} else {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cluster
2+
3+
const (
4+
InvalidService = `
5+
apiVersion: v1
6+
kind: Service
7+
metadata:
8+
labels:
9+
kosmos.io/app: coredns
10+
name: invalidsvc
11+
namespace: {{ .Namespace }}
12+
spec:
13+
clusterIP: 8.8.8.8
14+
clusterIPs:
15+
- 8.8.8.8
16+
ipFamilies:
17+
- IPv4
18+
ports:
19+
- name: dns
20+
port: 53
21+
protocol: UDP
22+
targetPort: 53
23+
selector:
24+
invalid/app: null
25+
sessionAffinity: None
26+
type: ClusterIP
27+
`
28+
)

pkg/clusterlink/elector/elector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (e *Elector) EnsureGateWayRole() error {
8181

8282
if needReelect {
8383
if !isCurrentNodeWithEIP && len(readyNodes) > 0 {
84+
// TODO: now choose first one, find a better way
8485
sort.Strings(readyNodes)
8586
e.nodeName = readyNodes[0]
8687
} else {

pkg/clusterlink/network/iptables/iptables.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,9 @@ func init() {
7474
return
7575
}
7676
if len(ret_nft) > len(ret_legacy) {
77-
klog.Info("use iptables-nft as default iptables")
78-
_, err := execInterface.Command("ln", []string{"-sf", "/sbin/xtables-nft-multi", "/sbin/iptables"}...).CombinedOutput()
77+
err := os.Setenv("IPTABLES_PATH", "/sbin/xtables-nft-multi")
7978
if err != nil {
80-
klog.Errorf("%s: %v", errInfo, err)
81-
return
82-
}
83-
_, err = execInterface.Command("ln", []string{"-sf", "/sbin/xtables-nft-multi", "/sbin/ip6tables"}...).CombinedOutput()
84-
if err != nil {
85-
klog.Errorf("%s: %v", errInfo, err)
79+
klog.Errorf("%s, set env error: %v", errInfo, err)
8680
return
8781
}
8882
}

0 commit comments

Comments
 (0)