diff --git a/dubbod/discovery/pkg/bootstrap/inherent_xds_controller.go b/dubbod/discovery/pkg/bootstrap/inherent_xds_controller.go index 96d87d984..37e3d2892 100644 --- a/dubbod/discovery/pkg/bootstrap/inherent_xds_controller.go +++ b/dubbod/discovery/pkg/bootstrap/inherent_xds_controller.go @@ -607,6 +607,9 @@ func isInherentTriplePod(pod *corev1.Pod) bool { if pod == nil { return false } + if strings.EqualFold(pod.Annotations["cni.dubbo.apache.org/redirection"], "enabled") { + return true + } for _, templateName := range strings.Split(pod.Annotations[inject.InherentInjectTemplatesAnnoName], ",") { if strings.TrimSpace(templateName) == inject.InherentTripleTemplateName { return true diff --git a/manifests/charts/dubbod/files/triple-engine.yaml b/manifests/charts/dubbod/files/triple-engine.yaml index 304811f58..190490a11 100644 --- a/manifests/charts/dubbod/files/triple-engine.yaml +++ b/manifests/charts/dubbod/files/triple-engine.yaml @@ -17,6 +17,7 @@ metadata: annotations: dubbo.apache.org/rev: default inject.dubbo.apache.org/templates: triple-engine + cni.dubbo.apache.org/redirection: enabled spec: volumes: - name: dubbo-xds diff --git a/pkg/kube/inject/inherent_test.go b/pkg/kube/inject/inherent_test.go index 863b9e478..3767c6d05 100644 --- a/pkg/kube/inject/inherent_test.go +++ b/pkg/kube/inject/inherent_test.go @@ -208,13 +208,16 @@ func assertDirectXDSConnection(t *testing.T, pod *corev1.Pod, containerName, sec t.Fatalf("prometheus scrape annotation = %q, want true", got) } + if got := pod.Annotations["cni.dubbo.apache.org/redirection"]; got != "enabled" { + t.Fatalf("cni redirection annotation = %q, want enabled", got) + } + for _, want := range []struct { name string value string }{ {name: "XDS_ADDRESS", value: "dubbod.dubbo-system.svc:26012"}, {name: "CA_ADDRESS", value: "dubbod.dubbo-system.svc:26012"}, - {name: "TRIPLE_ADDRESS", value: ""}, {name: "TRIPLE_XDS_EXPERIMENTAL_SECURITY_SUPPORT", value: "true"}, {name: "DUBBO_META_GENERATOR", value: "triple"}, {name: "DUBBO_META_CLUSTER_ID", value: "Kubernetes"}, diff --git a/pkg/kube/inject/webhook.go b/pkg/kube/inject/webhook.go index 2b036b1e8..8ecf525d7 100644 --- a/pkg/kube/inject/webhook.go +++ b/pkg/kube/inject/webhook.go @@ -504,15 +504,24 @@ func addApplicationContainerConfig(pod *corev1.Pod, req InjectionParameters) err }) ensureApplicationMetricsAnnotations(pod) } + xdsAddr := discoveryAddress + if xdsAddr == "" { + xdsAddr = "dubbod.dubbo-system.svc:26012" + } + if pod.Annotations == nil { + pod.Annotations = map[string]string{} + } + if _, exists := pod.Annotations["cni.dubbo.apache.org/redirection"]; !exists { + pod.Annotations["cni.dubbo.apache.org/redirection"] = "enabled" + } staticEnvs := []corev1.EnvVar{ {Name: InherentTripleBootstrapEnvName, Value: InherentTripleBootstrapPath}, - {Name: "XDS_ADDRESS", Value: "dubbod.dubbo-system.svc:26012"}, - {Name: "CA_ADDRESS", Value: "dubbod.dubbo-system.svc:26012"}, - {Name: "TRIPLE_ADDRESS", Value: ""}, + {Name: "XDS_ADDRESS", Value: xdsAddr}, + {Name: "CA_ADDRESS", Value: xdsAddr}, {Name: "TRIPLE_XDS_EXPERIMENTAL_SECURITY_SUPPORT", Value: "true"}, {Name: "DUBBO_META_GENERATOR", Value: "triple"}, {Name: "DUBBO_META_CLUSTER_ID", Value: "Kubernetes"}, - {Name: "DUBBO_META_MESH_ID", Value: "cluster.local"}, + {Name: "DUBBO_META_MESH_ID", Value: trustDomain}, {Name: "TRUST_DOMAIN", Value: trustDomain}, { Name: "POD_NAMESPACE",