Skip to content

Commit

Permalink
fix: via gateway for vm (#613)
Browse files Browse the repository at this point in the history
* fix via gateway for vm

Signed-off-by: Cybwan <[email protected]>
Signed-off-by: Lin Yang <[email protected]>

* fix virtual machine monitor

Signed-off-by: Cybwan <[email protected]>
Signed-off-by: Lin Yang <[email protected]>

---------

Signed-off-by: Cybwan <[email protected]>
Signed-off-by: Lin Yang <[email protected]>
  • Loading branch information
cybwan authored Jan 3, 2025
1 parent e2575c0 commit 2cf92eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newClient(informerCollection *fsminformers.InformerCollection, policyClient

// If specific informers are not selected to be initialized, initialize all informers
if len(selectInformers) == 0 {
selectInformers = []InformerKey{Namespaces, Services, ServiceAccounts, Pods, Endpoints}
selectInformers = []InformerKey{Namespaces, Services, ServiceAccounts, Pods, Endpoints, VirtualMachine}
}

for _, informer := range selectInformers {
Expand Down
23 changes: 17 additions & 6 deletions pkg/sidecar/v1/providers/pipy/repo/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ func generatePipyOutboundTrafficBalancePolicy(meshCatalog catalog.MeshCataloger,
dependClusters map[service.ClusterName]*WeightedCluster) bool {
ready := true
viaGateway := cfg.GetMeshConfig().Spec.Connector.ViaGateway
clusterSet := fmt.Sprintf("%s.%s.%s.%s",
cfg.GetMeshConfig().Spec.ClusterSet.Name,
cfg.GetMeshConfig().Spec.ClusterSet.Group,
cfg.GetMeshConfig().Spec.ClusterSet.Zone,
cfg.GetMeshConfig().Spec.ClusterSet.Region)
otp := pipyConf.newOutboundTrafficPolicy()
clustersConfigsMap := make(map[string][]*trafficpolicy.MeshClusterConfig)
if len(outboundPolicy.ClustersConfigs) > 0 {
Expand Down Expand Up @@ -464,8 +469,14 @@ func generatePipyOutboundTrafficBalancePolicy(meshCatalog catalog.MeshCataloger,
}
if len(upstreamEndpoint.ViaGatewayMode) > 0 {
if upstreamEndpoint.WithGateway {
if upstreamEndpoint.WithMultiGateways {
viaGw = generatePipyViaGateway(upstreamEndpoint.AppProtocol, upstreamEndpoint.ClusterID, proxy, &viaGateway)
if proxy.VM {
if strings.EqualFold(proxy.ClusterID, clusterSet) {
viaGw = generatePipyViaGateway(upstreamEndpoint.AppProtocol, upstreamEndpoint.ClusterID, "", &viaGateway)
} else {
viaGw = generatePipyViaGateway(upstreamEndpoint.AppProtocol, upstreamEndpoint.ClusterID, proxy.ClusterID, &viaGateway)
}
} else if upstreamEndpoint.WithMultiGateways {
viaGw = generatePipyViaGateway(upstreamEndpoint.AppProtocol, upstreamEndpoint.ClusterID, proxy.ClusterID, &viaGateway)
}
} else {
port = Port(upstreamEndpoint.Port)
Expand All @@ -486,10 +497,10 @@ func generatePipyOutboundTrafficBalancePolicy(meshCatalog catalog.MeshCataloger,
return ready
}

func generatePipyViaGateway(appProtocol, clusterID string, proxy *pipy.Proxy, viaGateway *configv1alpha3.ConnectorGatewaySpec) string {
func generatePipyViaGateway(appProtocol, endpointClusterID, proxyClusterID string, viaGateway *configv1alpha3.ConnectorGatewaySpec) string {
viaGw := ""
if len(appProtocol) > 0 && !strings.EqualFold(proxy.ClusterID, clusterID) {
if len(proxy.ClusterID) == 0 { // k8s -> fgw(EgressIP:EgressPort) -> others
if len(appProtocol) > 0 && !strings.EqualFold(proxyClusterID, endpointClusterID) {
if len(proxyClusterID) == 0 { // k8s -> fgw(EgressIP:EgressPort) -> others
if len(viaGateway.ClusterIP) > 0 && viaGateway.EgressHTTPPort > 0 &&
strings.EqualFold(constants.ProtocolHTTP, appProtocol) {
viaGw = fmt.Sprintf("%s:%d", viaGateway.ClusterIP, viaGateway.EgressHTTPPort)
Expand All @@ -499,7 +510,7 @@ func generatePipyViaGateway(appProtocol, clusterID string, proxy *pipy.Proxy, vi
viaGw = fmt.Sprintf("%s:%d", viaGateway.ClusterIP, viaGateway.EgressGRPCPort)
}
} else {
if len(clusterID) == 0 { // others -> fgw(IngressIP:IngressPort) -> k8s
if len(endpointClusterID) == 0 { // others -> fgw(IngressIP:IngressPort) -> k8s
if len(viaGateway.IngressAddr) > 0 && viaGateway.IngressHTTPPort > 0 &&
strings.EqualFold(constants.ProtocolHTTP, appProtocol) {
viaGw = fmt.Sprintf("%s:%d", viaGateway.IngressAddr, viaGateway.IngressHTTPPort)
Expand Down

0 comments on commit 2cf92eb

Please sign in to comment.