forked from kosmos-io/kosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: intercommunication between subclusters
Signed-off-by: wangyizhi1 <[email protected]>
- Loading branch information
1 parent
d5548df
commit eba9ea3
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/kosmos.io/kosmos/pkg/apis/clusterlink/v1alpha1" | ||
"github.com/kosmos.io/kosmos/pkg/constants" | ||
"github.com/kosmos.io/kosmos/pkg/network-manager/helpers" | ||
) | ||
|
||
type GlobalMap struct { | ||
Next | ||
} | ||
|
||
func (h *GlobalMap) Do(c *Context) (err error) { | ||
gwNodes := c.Filter.GetGatewayNodes() | ||
epNodes := c.Filter.GetEndpointNodes() | ||
|
||
nodes := append(gwNodes, epNodes...) | ||
|
||
for _, n := range nodes { | ||
cluster := c.Filter.GetClusterByName(n.Spec.ClusterName) | ||
globalMap := cluster.Spec.GlobalCIDRsMap | ||
|
||
if len(globalMap) > 0 { | ||
for src, dst := range cluster.Spec.GlobalCIDRsMap { | ||
ipType := helpers.GetIPType(src) | ||
|
||
var vxBridge string | ||
if ipType == helpers.IPV6 { | ||
vxBridge = constants.VXLAN_BRIDGE_NAME_6 | ||
} else if ipType == helpers.IPV4 { | ||
vxBridge = constants.VXLAN_BRIDGE_NAME | ||
} | ||
|
||
// todo in-cluster globalIP access | ||
c.Results[n.Name].Iptables = append(c.Results[n.Name].Iptables, v1alpha1.Iptables{ | ||
Table: "nat", | ||
Chain: constants.IPTablesPreRoutingChain, | ||
Rule: fmt.Sprintf("-d %s -i %s -j NETMAP --to %s", dst, vxBridge, src), | ||
}) | ||
|
||
_, dstIP, err := net.ParseCIDR(dst) | ||
if err != nil { | ||
klog.Errorf("globalmap: invalid dstIP, err: %v", err) | ||
continue | ||
} | ||
|
||
c.Results[n.Name].Iptables = append(c.Results[n.Name].Iptables, v1alpha1.Iptables{ | ||
Table: "nat", | ||
Chain: constants.IPTablesPostRoutingChain, | ||
Rule: fmt.Sprintf("-s %s -o %s -j SNAT --to-source %s", src, vxBridge, dstIP.IP), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters