Skip to content

Commit ecf52ae

Browse files
authored
Supports MCP service configuration protocol and SNI, along with various other fixes. (alibaba#1369)
1 parent 3ed28f2 commit ecf52ae

File tree

23 files changed

+282
-94
lines changed

23 files changed

+282
-94
lines changed

Diff for: api/kubernetes/customresourcedefinitions.gen.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ spec:
284284
type: string
285285
port:
286286
type: integer
287+
protocol:
288+
type: string
289+
sni:
290+
type: string
287291
type:
288292
type: string
289293
zkServicesPath:

Diff for: api/networking/v1/mcp_bridge.pb.go

+24-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: api/networking/v1/mcp_bridge.proto

+2
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ message RegistryConfig {
6464
string consulServiceTag = 15;
6565
int64 consulRefreshInterval = 16;
6666
string authSecretName = 17;
67+
string protocol = 18;
68+
string sni = 19;
6769
}

Diff for: envoy/envoy

Submodule envoy updated 28 files

Diff for: helm/core/crds/customresourcedefinitions.gen.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ spec:
284284
type: string
285285
port:
286286
type: integer
287+
protocol:
288+
type: string
289+
sni:
290+
type: string
287291
type:
288292
type: string
289293
zkServicesPath:
@@ -302,3 +306,4 @@ spec:
302306
subresources:
303307
status: {}
304308

309+
---

Diff for: helm/core/templates/_pod.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ template:
180180
{{- end }}
181181
- name: config
182182
mountPath: /etc/istio/config
183-
- name: istio-ca-root-cert
183+
- name: higress-ca-root-cert
184184
mountPath: /var/run/secrets/istio
185185
- name: istio-data
186186
mountPath: /var/lib/istio/data
@@ -266,7 +266,7 @@ template:
266266
expirationSeconds: 43200
267267
path: istio-token
268268
{{- end }}
269-
- name: istio-ca-root-cert
269+
- name: higress-ca-root-cert
270270
configMap:
271271
{{- if .Values.global.enableHigressIstio }}
272272
name: istio-ca-root-cert

Diff for: pkg/common/protocol.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ type Protocol string
2121
const (
2222
TCP Protocol = "TCP"
2323
HTTP Protocol = "HTTP"
24+
HTTP2 Protocol = "HTTP2"
25+
HTTPS Protocol = "HTTPS"
2426
GRPC Protocol = "GRPC"
27+
GRPCS Protocol = "GRPCS"
2528
Dubbo Protocol = "Dubbo"
2629
Unsupported Protocol = "UnsupportedProtocol"
2730
)
@@ -32,8 +35,14 @@ func ParseProtocol(s string) Protocol {
3235
return TCP
3336
case "http":
3437
return HTTP
38+
case "https":
39+
return HTTPS
40+
case "http2":
41+
return HTTP2
3542
case "grpc", "triple", "tri":
3643
return GRPC
44+
case "grpcs":
45+
return GRPCS
3746
case "dubbo":
3847
return Dubbo
3948
}
@@ -51,7 +60,7 @@ func (p Protocol) IsTCP() bool {
5160

5261
func (p Protocol) IsHTTP() bool {
5362
switch p {
54-
case HTTP, GRPC:
63+
case HTTP, GRPC, GRPCS, HTTP2, HTTPS:
5564
return true
5665
default:
5766
return false
@@ -60,7 +69,16 @@ func (p Protocol) IsHTTP() bool {
6069

6170
func (p Protocol) IsGRPC() bool {
6271
switch p {
63-
case GRPC:
72+
case GRPC, GRPCS:
73+
return true
74+
default:
75+
return false
76+
}
77+
}
78+
79+
func (i Protocol) IsHTTPS() bool {
80+
switch i {
81+
case HTTPS, GRPCS:
6482
return true
6583
default:
6684
return false

Diff for: pkg/config/constants/constants.go

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ const KnativeIngressCRDName = "ingresses.networking.internal.knative.dev"
2323
const KnativeServicesCRDName = "services.serving.knative.dev"
2424

2525
const ManagedGatewayController = "higress.io/gateway-controller"
26+
27+
const RegistryTypeLabelKey = "higress-registry-type"
28+
29+
const RegistryNameLabelKey = "higress-registry-name"

Diff for: pkg/ingress/config/ingress_config.go

+49-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
extlisterv1 "github.com/alibaba/higress/client/pkg/listers/extensions/v1alpha1"
5454
netlisterv1 "github.com/alibaba/higress/client/pkg/listers/networking/v1"
5555
"github.com/alibaba/higress/pkg/cert"
56+
higressconst "github.com/alibaba/higress/pkg/config/constants"
5657
"github.com/alibaba/higress/pkg/ingress/kube/annotations"
5758
"github.com/alibaba/higress/pkg/ingress/kube/common"
5859
"github.com/alibaba/higress/pkg/ingress/kube/configmap"
@@ -628,8 +629,8 @@ func (m *IngressConfig) convertServiceEntry([]common.WrapperConfig) []config.Con
628629
if m.RegistryReconciler == nil {
629630
return nil
630631
}
631-
serviceEntries := m.RegistryReconciler.GetAllServiceEntryWrapper()
632-
IngressLog.Infof("Found http2rpc serviceEntries %s", serviceEntries)
632+
serviceEntries := m.RegistryReconciler.GetAllServiceWrapper()
633+
IngressLog.Infof("Found mcp serviceEntries %v", serviceEntries)
633634
out := make([]config.Config, 0, len(serviceEntries))
634635
for _, se := range serviceEntries {
635636
out = append(out, config.Config{
@@ -638,6 +639,10 @@ func (m *IngressConfig) convertServiceEntry([]common.WrapperConfig) []config.Con
638639
Name: se.ServiceEntry.Hosts[0],
639640
Namespace: "mcp",
640641
CreationTimestamp: se.GetCreateTime(),
642+
Labels: map[string]string{
643+
higressconst.RegistryTypeLabelKey: se.RegistryType,
644+
higressconst.RegistryNameLabelKey: se.RegistryName,
645+
},
641646
},
642647
Spec: se.ServiceEntry,
643648
})
@@ -703,6 +708,32 @@ func (m *IngressConfig) convertDestinationRule(configs []common.WrapperConfig) [
703708
destinationRules[serviceName] = dr
704709
}
705710

711+
if m.RegistryReconciler != nil {
712+
drws := m.RegistryReconciler.GetAllDestinationRuleWrapper()
713+
IngressLog.Infof("Found mcp destinationRules: %v", drws)
714+
for _, destinationRuleWrapper := range drws {
715+
serviceName := destinationRuleWrapper.ServiceKey.ServiceFQDN
716+
dr, exist := destinationRules[serviceName]
717+
if !exist {
718+
destinationRules[serviceName] = destinationRuleWrapper
719+
} else if dr.DestinationRule.TrafficPolicy != nil {
720+
portTrafficPolicy := destinationRuleWrapper.DestinationRule.TrafficPolicy.PortLevelSettings[0]
721+
portUpdated := false
722+
for _, portTrafficPolicy := range dr.DestinationRule.TrafficPolicy.PortLevelSettings {
723+
if portTrafficPolicy.Port.Number == portTrafficPolicy.Port.Number {
724+
portTrafficPolicy.Tls = portTrafficPolicy.Tls
725+
portUpdated = true
726+
break
727+
}
728+
}
729+
if portUpdated {
730+
continue
731+
}
732+
dr.DestinationRule.TrafficPolicy.PortLevelSettings = append(dr.DestinationRule.TrafficPolicy.PortLevelSettings, portTrafficPolicy)
733+
}
734+
}
735+
}
736+
706737
out := make([]config.Config, 0, len(destinationRules))
707738
for _, dr := range destinationRules {
708739
sort.SliceStable(dr.DestinationRule.TrafficPolicy.PortLevelSettings, func(i, j int) bool {
@@ -727,6 +758,7 @@ func (m *IngressConfig) convertDestinationRule(configs []common.WrapperConfig) [
727758
Spec: dr.DestinationRule,
728759
})
729760
}
761+
730762
return out
731763
}
732764

@@ -1034,16 +1066,27 @@ func (m *IngressConfig) AddOrUpdateMcpBridge(clusterNamespacedName util.ClusterN
10341066
}
10351067
if m.RegistryReconciler == nil {
10361068
m.RegistryReconciler = reconcile.NewReconciler(func() {
1037-
metadata := config.Meta{
1069+
seMetadata := config.Meta{
10381070
Name: "mcpbridge-serviceentry",
10391071
Namespace: m.namespace,
10401072
GroupVersionKind: gvk.ServiceEntry,
10411073
// Set this label so that we do not compare configs and just push.
10421074
Labels: map[string]string{constants.AlwaysPushLabel: "true"},
10431075
}
1076+
drMetadata := config.Meta{
1077+
Name: "mcpbridge-destinationrule",
1078+
Namespace: m.namespace,
1079+
GroupVersionKind: gvk.DestinationRule,
1080+
// Set this label so that we do not compare configs and just push.
1081+
Labels: map[string]string{constants.AlwaysPushLabel: "true"},
1082+
}
10441083
for _, f := range m.serviceEntryHandlers {
10451084
IngressLog.Debug("McpBridge triggerd serviceEntry update")
1046-
f(config.Config{Meta: metadata}, config.Config{Meta: metadata}, istiomodel.EventUpdate)
1085+
f(config.Config{Meta: seMetadata}, config.Config{Meta: seMetadata}, istiomodel.EventUpdate)
1086+
}
1087+
for _, f := range m.destinationRuleHandlers {
1088+
IngressLog.Debug("McpBridge triggerd destinationRule update")
1089+
f(config.Config{Meta: drMetadata}, config.Config{Meta: drMetadata}, istiomodel.EventUpdate)
10471090
}
10481091
}, m.localKubeClient, m.namespace)
10491092
}
@@ -1489,7 +1532,7 @@ func constructBasicAuthEnvoyFilter(rules *common.BasicAuthRules, namespace strin
14891532
}, nil
14901533
}
14911534

1492-
func QueryByName(serviceEntries []*memory.ServiceEntryWrapper, serviceName string) (*memory.ServiceEntryWrapper, error) {
1535+
func QueryByName(serviceEntries []*memory.ServiceWrapper, serviceName string) (*memory.ServiceWrapper, error) {
14931536
IngressLog.Infof("Found http2rpc serviceEntries %s", serviceEntries)
14941537
for _, se := range serviceEntries {
14951538
if se.ServiceName == serviceName {
@@ -1499,7 +1542,7 @@ func QueryByName(serviceEntries []*memory.ServiceEntryWrapper, serviceName strin
14991542
return nil, fmt.Errorf("can't find ServiceEntry by serviceName:%v", serviceName)
15001543
}
15011544

1502-
func QueryRpcServiceVersion(serviceEntry *memory.ServiceEntryWrapper, serviceName string) (string, error) {
1545+
func QueryRpcServiceVersion(serviceEntry *memory.ServiceWrapper, serviceName string) (string, error) {
15031546
IngressLog.Infof("Found http2rpc serviceEntry %s", serviceEntry)
15041547
IngressLog.Infof("Found http2rpc ServiceEntry %s", serviceEntry.ServiceEntry)
15051548
IngressLog.Infof("Found http2rpc WorkloadSelector %s", serviceEntry.ServiceEntry.WorkloadSelector)

Diff for: pkg/ingress/kube/common/controller.go

+9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ type WrapperGateway struct {
5252
Host string
5353
}
5454

55+
func CreateMcpServiceKey(host string, portNumber int32) ServiceKey {
56+
return ServiceKey{
57+
Namespace: "mcp",
58+
Name: host,
59+
ServiceFQDN: host,
60+
Port: portNumber,
61+
}
62+
}
63+
5564
func (w *WrapperGateway) IsHTTPS() bool {
5665
if w.Gateway == nil || len(w.Gateway.Servers) == 0 {
5766
return false

Diff for: pkg/ingress/kube/ingress/controller.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -920,12 +920,7 @@ func (c *controller) storeBackendTrafficPolicy(wrapper *common.WrapperConfig, ba
920920
if common.ValidateBackendResource(backend.Resource) && wrapper.AnnotationsConfig.Destination != nil {
921921
for _, dest := range wrapper.AnnotationsConfig.Destination.McpDestination {
922922
portNumber := dest.Destination.GetPort().GetNumber()
923-
serviceKey := common.ServiceKey{
924-
Namespace: "mcp",
925-
Name: dest.Destination.Host,
926-
Port: int32(portNumber),
927-
ServiceFQDN: dest.Destination.Host,
928-
}
923+
serviceKey := common.CreateMcpServiceKey(dest.Destination.Host, int32(portNumber))
929924
if _, exist := store[serviceKey]; !exist {
930925
if serviceKey.Port != 0 {
931926
store[serviceKey] = &common.WrapperTrafficPolicy{

Diff for: pkg/ingress/kube/ingressv1/controller.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -900,12 +900,7 @@ func (c *controller) storeBackendTrafficPolicy(wrapper *common.WrapperConfig, ba
900900
if common.ValidateBackendResource(backend.Resource) && wrapper.AnnotationsConfig.Destination != nil {
901901
for _, dest := range wrapper.AnnotationsConfig.Destination.McpDestination {
902902
portNumber := dest.Destination.GetPort().GetNumber()
903-
serviceKey := common.ServiceKey{
904-
Namespace: "mcp",
905-
Name: dest.Destination.Host,
906-
Port: int32(portNumber),
907-
ServiceFQDN: dest.Destination.Host,
908-
}
903+
serviceKey := common.CreateMcpServiceKey(dest.Destination.Host, int32(portNumber))
909904
if _, exist := store[serviceKey]; !exist {
910905
if serviceKey.Port != 0 {
911906
store[serviceKey] = &common.WrapperTrafficPolicy{

Diff for: pkg/ingress/mcp/generator.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (c ServiceEntryGenerator) Generate(proxy *model.Proxy, w *model.WatchedReso
6464
return serviceEntries[i].CreationTimestamp.Before(serviceEntries[j].CreationTimestamp)
6565
})
6666
}
67-
return generate(proxy, serviceEntries, w, updates, false, false)
67+
return generate(proxy, serviceEntries, w, updates, c.GeneratorOptions.KeepConfigLabels, c.GeneratorOptions.KeepConfigAnnotations)
6868
}
6969

7070
func (c ServiceEntryGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
@@ -82,7 +82,7 @@ type VirtualServiceGenerator struct {
8282
func (c VirtualServiceGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
8383
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
8484
virtualServices := c.Environment.List(gvk.VirtualService, model.NamespaceAll)
85-
return generate(proxy, virtualServices, w, updates, false, false)
85+
return generate(proxy, virtualServices, w, updates, c.GeneratorOptions.KeepConfigLabels, c.GeneratorOptions.KeepConfigAnnotations)
8686
}
8787

8888
func (c VirtualServiceGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
@@ -100,7 +100,7 @@ type DestinationRuleGenerator struct {
100100
func (c DestinationRuleGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
101101
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
102102
rules := c.Environment.List(gvk.DestinationRule, model.NamespaceAll)
103-
return generate(proxy, rules, w, updates, false, false)
103+
return generate(proxy, rules, w, updates, c.GeneratorOptions.KeepConfigLabels, c.GeneratorOptions.KeepConfigAnnotations)
104104
}
105105

106106
func (c DestinationRuleGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
@@ -118,7 +118,7 @@ type EnvoyFilterGenerator struct {
118118
func (c EnvoyFilterGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
119119
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
120120
filters := c.Environment.List(gvk.EnvoyFilter, model.NamespaceAll)
121-
return generate(proxy, filters, w, updates, false, false)
121+
return generate(proxy, filters, w, updates, c.GeneratorOptions.KeepConfigLabels, c.GeneratorOptions.KeepConfigAnnotations)
122122
}
123123

124124
func (c EnvoyFilterGenerator) GenerateDeltas(proxy *model.Proxy, updates *model.PushRequest,
@@ -154,7 +154,7 @@ type WasmPluginGenerator struct {
154154
func (c WasmPluginGenerator) Generate(proxy *model.Proxy, w *model.WatchedResource,
155155
updates *model.PushRequest) (model.Resources, model.XdsLogDetails, error) {
156156
wasmPlugins := c.Environment.List(gvk.WasmPlugin, model.NamespaceAll)
157-
return generate(proxy, wasmPlugins, w, updates, false, false)
157+
return generate(proxy, wasmPlugins, w, updates, c.GeneratorOptions.KeepConfigLabels, c.GeneratorOptions.KeepConfigAnnotations)
158158
}
159159

160160
func (c WasmPluginGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,

0 commit comments

Comments
 (0)