You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2026/04/21 19:30:15 UTC

(dubbo-kubernetes) branch chore_v34 created (now 5426bb8f)

This is an automated email from the ASF dual-hosted git repository.

mfordjody pushed a change to branch chore_v34
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


      at 5426bb8f feat: Control plane and connection to any service completed

This branch includes the following new commits:

     new 5426bb8f feat: Control plane and connection to any service completed

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(dubbo-kubernetes) 01/01: feat: Control plane and connection to any service completed

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mfordjody pushed a commit to branch chore_v34
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git

commit 5426bb8f3599210ee5dad72fee7cd38c534c2724
Author: mfordjody <11...@qq.com>
AuthorDate: Wed Apr 22 03:29:59 2026 +0800

    feat: Control plane and connection to any service completed
---
 .../{dockerfile.daemon => dockerfile.dubbod}       |   2 +-
 .../pkg/bootstrap/proxyless_grpc_controller.go     |  26 ++-
 .../charts/dubbod/files/grpc-engine.yaml           |  26 ++-
 .../charts/dubbod/files/kube-gateway.yaml          | 160 ----------------
 .../dubbod/templates/configmap-injector.yaml       |   6 +-
 .../charts/dubbod/templates/deployment.yaml        |   6 +-
 .../charts/dubbod/templates/service.yaml           |  20 +-
 pkg/kube/inject/proxyless.go                       |  24 +--
 pkg/kube/inject/proxyless_test.go                  |  94 ++++++++-
 pkg/kube/inject/template.go                        |  15 +-
 pkg/kube/inject/webhook.go                         |  40 +++-
 samples/app/README.md                              |  22 +++
 samples/app/deployment.yaml                        |  92 +++++++++
 samples/grpc-app/README.md                         |   3 -
 samples/grpc-app/grpc-app.yaml                     | 210 ---------------------
 15 files changed, 302 insertions(+), 444 deletions(-)

diff --git a/dubbod/discovery/docker/dockerfile.daemon b/dubbod/discovery/docker/dockerfile.dubbod
similarity index 95%
rename from dubbod/discovery/docker/dockerfile.daemon
rename to dubbod/discovery/docker/dockerfile.dubbod
index 51245f1e..af1ed5d6 100644
--- a/dubbod/discovery/docker/dockerfile.daemon
+++ b/dubbod/discovery/docker/dockerfile.dubbod
@@ -31,7 +31,7 @@ COPY . .
 
 RUN go build -v -trimpath -ldflags="-s -w" \
     -o /out/dubbod \
-    ./dubbod/discovery/cmd/dubbo-discover/main.go
+    ./dubbod/discovery/cmd/main.go
 
 FROM scratch
 
diff --git a/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go b/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go
index 92766aab..e18a48b3 100644
--- a/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go
+++ b/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go
@@ -146,14 +146,14 @@ func (c *proxylessGRPCWorkloadController) enqueueAllPods() {
 
 func (c *proxylessGRPCWorkloadController) reconcile(key types.NamespacedName) error {
 	pod := c.pods.Get(key.Name, key.Namespace)
-	if pod == nil || !shouldManageProxylessGRPCPod(pod) || pod.DeletionTimestamp != nil {
+	if pod == nil {
 		c.clearRotation(key)
 		return c.deleteSecret(key)
 	}
-	if pod.Status.PodIP == "" {
-		return nil
+	if !shouldManageProxylessGRPCPod(pod) || pod.DeletionTimestamp != nil {
+		c.clearRotation(key)
+		return c.deleteSecretForPod(pod)
 	}
-
 	desired, expireAt, err := c.buildSecret(pod)
 	if err != nil {
 		return err
@@ -194,7 +194,7 @@ func (c *proxylessGRPCWorkloadController) buildSecret(pod *corev1.Pod) (*corev1.
 
 	secret := &corev1.Secret{
 		ObjectMeta: metav1.ObjectMeta{
-			Name:      inject.ProxylessGRPCSecretName(pod.Name),
+			Name:      inject.ProxylessGRPCSecretNameForMeta(pod.ObjectMeta),
 			Namespace: pod.Namespace,
 			OwnerReferences: []metav1.OwnerReference{{
 				APIVersion: "v1",
@@ -234,17 +234,21 @@ func (c *proxylessGRPCWorkloadController) buildBootstrapJSON(pod *corev1.Pod) ([
 	if domainSuffix == "" {
 		domainSuffix = constants.DefaultClusterLocalDomain
 	}
+	podIP := pod.Status.PodIP
+	if podIP == "" {
+		podIP = "0.0.0.0"
+	}
 
 	serviceNode := strings.Join([]string{
 		string(pkgmodel.Proxyless),
-		pod.Status.PodIP,
+		podIP,
 		pod.Name + "." + pod.Namespace,
 		fmt.Sprintf("%s.svc.%s", pod.Namespace, domainSuffix),
 	}, serviceNodeSeparator)
 
 	node, err := pkgbootstrap.GetNodeMetaData(pkgbootstrap.MetadataOptions{
 		ID:          serviceNode,
-		InstanceIPs: []string{pod.Status.PodIP},
+		InstanceIPs: []string{podIP},
 		ProxyConfig: proxyConfig,
 		Envs: []string{
 			"DUBBO_META_GENERATOR=grpc",
@@ -254,7 +258,7 @@ func (c *proxylessGRPCWorkloadController) buildBootstrapJSON(pod *corev1.Pod) ([
 			"TRUST_DOMAIN=" + trustDomain,
 			"POD_NAME=" + pod.Name,
 			"POD_NAMESPACE=" + pod.Namespace,
-			"INSTANCE_IP=" + pod.Status.PodIP,
+			"INSTANCE_IP=" + podIP,
 			"SERVICE_ACCOUNT=" + serviceAccount,
 		},
 	})
@@ -368,6 +372,12 @@ func (c *proxylessGRPCWorkloadController) deleteSecret(key types.NamespacedName)
 	return controllers.IgnoreNotFound(err)
 }
 
+func (c *proxylessGRPCWorkloadController) deleteSecretForPod(pod *corev1.Pod) error {
+	err := c.server.kubeClient.Kube().CoreV1().Secrets(pod.Namespace).Delete(context.Background(),
+		inject.ProxylessGRPCSecretNameForMeta(pod.ObjectMeta), metav1.DeleteOptions{})
+	return controllers.IgnoreNotFound(err)
+}
+
 func (c *proxylessGRPCWorkloadController) scheduleRotation(key types.NamespacedName, expireAt time.Time) {
 	c.clearRotation(key)
 	delay := workloadRotationDelay(time.Now(), expireAt)
diff --git a/dubboinstaller/charts/dubbod/files/grpc-engine.yaml b/dubboinstaller/charts/dubbod/files/grpc-engine.yaml
index fc72f700..7f9f18c8 100644
--- a/dubboinstaller/charts/dubbod/files/grpc-engine.yaml
+++ b/dubboinstaller/charts/dubbod/files/grpc-engine.yaml
@@ -15,15 +15,13 @@
 
 metadata:
   annotations:
-    dubbo.apache.org/rev: {{ .Revision | default "default" }}
+    dubbo.apache.org/rev: default
 spec:
   containers:
-{{- range .Spec.Containers }}
-{{- if and (ne .Name "dubbo-proxy") (ne .Name "dubbo-validation") }}
-  - name: {{ .Name | quote }}
+  - name: app
     env:
     - name: GRPC_XDS_BOOTSTRAP
-      value: {{ proxylessGRPCBootstrapPath | quote }}
+      value: /etc/dubbo/proxy/grpc-bootstrap.json
     - name: GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT
       value: "true"
     - name: DUBBO_GRPC_XDS_CREDENTIALS
@@ -33,17 +31,17 @@ spec:
     - name: DUBBO_META_GENERATOR
       value: "grpc"
     - name: DUBBO_META_CLUSTER_ID
-      value: "Kubernetes"
+      value: Kubernetes
     - name: DUBBO_META_NAMESPACE
       valueFrom:
         fieldRef:
           fieldPath: metadata.namespace
     - name: CA_ADDR
-      value: {{ proxylessGRPCDiscoveryAddress $.MeshGlobalConfig $.ProxyConfig | quote }}
+      value: dubbod.dubbo-system.svc:15012
     - name: DUBBO_META_MESH_ID
-      value: {{ proxylessGRPCTrustDomain $.MeshGlobalConfig | quote }}
+      value: cluster.local
     - name: TRUST_DOMAIN
-      value: {{ proxylessGRPCTrustDomain $.MeshGlobalConfig | quote }}
+      value: cluster.local
     - name: POD_NAME
       valueFrom:
         fieldRef:
@@ -65,13 +63,11 @@ spec:
         fieldRef:
           fieldPath: status.hostIP
     volumeMounts:
-    - name: {{ proxylessXDSVolumeName | quote }}
-      mountPath: {{ proxylessXDSMountPath | quote }}
+    - name: dubbo-xds
+      mountPath: /etc/dubbo/proxy
       readOnly: true
-{{- end }}
-{{- end }}
   volumes:
-  - name: {{ proxylessXDSVolumeName | quote }}
+  - name: dubbo-xds
     secret:
-      secretName: {{ proxylessGRPCSecretName .ObjectMeta.Name | quote }}
+      secretName: dubbo-xds
       defaultMode: 420
diff --git a/dubboinstaller/charts/dubbod/files/kube-gateway.yaml b/dubboinstaller/charts/dubbod/files/kube-gateway.yaml
deleted file mode 100644
index 2b529d8f..00000000
--- a/dubboinstaller/charts/dubbod/files/kube-gateway.yaml
+++ /dev/null
@@ -1,160 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: ServiceAccount
-metadata:
-  name: {{ .ServiceAccount }}
-  namespace: {{ .Namespace }}
-  labels:
-    gateway.dubbo.apache.org/managed: {{ .ControllerLabel }}
-    gateway.networking.k8s.io/gateway-name: {{ .Name }}
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: {{ .DeploymentName }}
-  namespace: {{ .Namespace }}
-  labels:
-    gateway.dubbo.apache.org/managed: {{ .ControllerLabel }}
-    gateway.networking.k8s.io/gateway-name: {{ .Name }}
-spec:
-  selector:
-    matchLabels:
-      gateway.networking.k8s.io/gateway-name: {{ .Name }}
-  template:
-    metadata:
-      annotations:
-        dubbo.apache.org/rev: {{ .Revision }}
-      labels:
-        gateway.dubbo.apache.org/managed: {{ .ControllerLabel }}
-        gateway.networking.k8s.io/gateway-name: {{ .Name }}
-        proxyless.dubbo.apache.org/inject: "false"
-    spec:
-      serviceAccountName: {{ .ServiceAccount }}
-      containers:
-      - name: dubbo-proxy
-        image: dubboregistry/dubbo-proxy:0.3.6
-        imagePullPolicy: Always
-        ports:
-        - containerPort: 15020
-          name: mesh-metrics
-          protocol: TCP
-        - containerPort: 80
-          name: http
-          protocol: TCP
-        args:
-        - proxy
-        - router
-        - --domain
-        - $(POD_NAMESPACE).svc.cluster.local
-        env:
-        - name: DUBBO_CERT_PROVIDER
-          value: dubbod
-        - name: CA_ADDR
-          value: dubbod.dubbo-system.svc:15012
-        - name: DUBBO_META_CLUSTER_ID
-          value: Kubernetes
-        - name: DUBBO_META_MESH_ID
-          value: cluster.local
-        - name: TRUST_DOMAIN
-          value: cluster.local
-        - name: POD_NAME
-          valueFrom:
-            fieldRef:
-              fieldPath: metadata.name
-        - name: POD_NAMESPACE
-          valueFrom:
-            fieldRef:
-              fieldPath: metadata.namespace
-        - name: INSTANCE_IP
-          valueFrom:
-            fieldRef:
-              fieldPath: status.podIP
-        - name: SERVICE_ACCOUNT
-          valueFrom:
-            fieldRef:
-              fieldPath: spec.serviceAccountName
-        - name: HOST_IP
-          valueFrom:
-            fieldRef:
-              fieldPath: status.hostIP
-        volumeMounts:
-          - mountPath: /var/lib/dubbo/data
-            name: dubbo-data
-          - mountPath: /etc/dubbo/proxy
-            name: dubbo-xds
-          - mountPath: /var/run/secrets/workload-spiffe-uds
-            name: workload-socket
-          - mountPath: /var/run/secrets/workload-spiffe-credentials
-            name: workload-certs
-          - mountPath: /etc/dubbo/pod
-            name: dubbo-podinfo
-          - mountPath: /var/run/secrets/dubbo
-            name: dubbod-ca-cert
-      volumes:
-      - emptyDir:
-          medium: Memory
-        name: dubbo-xds
-      - emptyDir: {}
-        name: dubbo-data
-      - emptyDir: {}
-        name: workload-socket
-      - emptyDir: {}
-        name: workload-certs
-      - downwardAPI:
-          defaultMode: 420
-          items:
-            - fieldRef:
-                apiVersion: v1
-                fieldPath: metadata.labels
-              path: labels
-            - fieldRef:
-                apiVersion: v1
-                fieldPath: metadata.annotations
-              path: annotations
-        name: dubbo-podinfo
-      - configMap:
-          defaultMode: 420
-          name: dubbo-ca-root-cert
-        name: dubbod-ca-cert
----
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ .DeploymentName }}
-  namespace: {{ .Namespace }}
-  ownerReferences:
-    - apiVersion: gateway.networking.k8s.io/v1
-      kind: Gateway
-      name: {{.Name}}
-      uid: {{.UID}}
-  labels:
-    gateway.dubbo.apache.org/managed: {{ .ControllerLabel }}
-    gateway.networking.k8s.io/gateway-name: {{ .Name }}
-spec:
-  type: {{ .ServiceType }}
-  ipFamilyPolicy: PreferDualStack
-  ports:
-{{- range .Ports }}
-  - name: {{ .Name }}
-    port: {{ .Port }}
-    targetPort: {{ .Port }}
-    {{- if .AppProtocol }}
-    appProtocol: {{ .AppProtocol }}
-    {{- end }}
-{{- end }}
-  selector:
-    gateway.networking.k8s.io/gateway-name: {{ .Name }}
diff --git a/dubboinstaller/charts/dubbod/templates/configmap-injector.yaml b/dubboinstaller/charts/dubbod/templates/configmap-injector.yaml
index df7ff015..a856b0a0 100644
--- a/dubboinstaller/charts/dubbod/templates/configmap-injector.yaml
+++ b/dubboinstaller/charts/dubbod/templates/configmap-injector.yaml
@@ -23,12 +23,12 @@ metadata:
     dubbo.apache.org/rev: default
 data:
   config: |-
-    defaultTemplates: [kube-gateway]
+    defaultTemplates: [grpc-engine]
     policy: enabled
     templates:
       grpc-engine: |
 {{ .Files.Get "files/grpc-engine.yaml" | trim | indent 8 }}
-      gateway: |
-{{ .Files.Get "files/kube-gateway.yaml" | trim | indent 8 }}
+{{/*      kube-gateway: |*/}}
+{{/*{{ .Files.Get "files/kube-gateway.yaml" | trim | indent 8 }}*/}}
   values: |-
 
diff --git a/dubboinstaller/charts/dubbod/templates/deployment.yaml b/dubboinstaller/charts/dubbod/templates/deployment.yaml
index 607b22cc..a0302d55 100644
--- a/dubboinstaller/charts/dubbod/templates/deployment.yaml
+++ b/dubboinstaller/charts/dubbod/templates/deployment.yaml
@@ -33,7 +33,7 @@ spec:
       serviceAccountName: dubbod
       containers:
         - name: discovery
-          image: "kdubbo/dubbod:0.3.7"
+          image: "kdubbo/dubbod:debug"
           imagePullPolicy: Always
           args:
             - "discovery"
@@ -43,6 +43,9 @@ spec:
             - containerPort: 8080
               protocol: TCP
               name: http-debug
+            - containerPort: 15080
+              protocol: TCP
+              name: gui
             - containerPort: 15010
               protocol: TCP
               name: grpc-xds
@@ -88,4 +91,3 @@ spec:
           name: dubbo-ca-root-cert
           optional: true
         name: dubbo-csr-ca-configmap
-
diff --git a/dubboinstaller/charts/dubbod/templates/service.yaml b/dubboinstaller/charts/dubbod/templates/service.yaml
index 4f50200a..b4117328 100644
--- a/dubboinstaller/charts/dubbod/templates/service.yaml
+++ b/dubboinstaller/charts/dubbod/templates/service.yaml
@@ -33,4 +33,22 @@ spec:
       targetPort: 15017
       protocol: TCP
   selector:
-    app: dubbod
\ No newline at end of file
+    app: dubbod
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: dubbod-gui
+  namespace: dubbo-system
+  labels:
+    app: dubbod
+spec:
+  type: NodePort
+  ports:
+    - port: 15080
+      name: gui
+      targetPort: 15080
+      nodePort: 30080
+      protocol: TCP
+  selector:
+    app: dubbod
diff --git a/pkg/kube/inject/proxyless.go b/pkg/kube/inject/proxyless.go
index 87e067dd..d1d0373c 100644
--- a/pkg/kube/inject/proxyless.go
+++ b/pkg/kube/inject/proxyless.go
@@ -21,9 +21,8 @@ import (
 	"fmt"
 	"strings"
 
-	"github.com/apache/dubbo-kubernetes/pkg/config/constants"
 	"github.com/kdubbo/api/annotation"
-	meshv1alpha1 "github.com/kdubbo/api/mesh/v1alpha1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
 
 const (
@@ -58,21 +57,10 @@ func ProxylessGRPCSecretName(podName string) string {
 	return fmt.Sprintf("%s%s-%s", prefix, base, suffix)
 }
 
-func ProxylessGRPCDiscoveryAddress(meshGlobalConfig *meshv1alpha1.MeshGlobalConfig, proxyConfig *meshv1alpha1.ProxyConfig) string {
-	if meshGlobalConfig != nil {
-		if cfg := meshGlobalConfig.GetDefaultConfig(); cfg != nil && cfg.GetDiscoveryAddress() != "" {
-			return cfg.GetDiscoveryAddress()
-		}
+func ProxylessGRPCSecretNameForMeta(meta metav1.ObjectMeta) string {
+	name := meta.Name
+	if meta.GenerateName != "" {
+		name = meta.GenerateName
 	}
-	if proxyConfig != nil {
-		return proxyConfig.GetDiscoveryAddress()
-	}
-	return ""
-}
-
-func ProxylessGRPCTrustDomain(meshGlobalConfig *meshv1alpha1.MeshGlobalConfig) string {
-	if meshGlobalConfig != nil && meshGlobalConfig.GetTrustDomain() != "" {
-		return meshGlobalConfig.GetTrustDomain()
-	}
-	return constants.DefaultClusterLocalDomain
+	return ProxylessGRPCSecretName(name)
 }
diff --git a/pkg/kube/inject/proxyless_test.go b/pkg/kube/inject/proxyless_test.go
index c97460b8..04117402 100644
--- a/pkg/kube/inject/proxyless_test.go
+++ b/pkg/kube/inject/proxyless_test.go
@@ -19,6 +19,7 @@ import (
 	"os"
 	"path/filepath"
 	"runtime"
+	"strings"
 	"testing"
 
 	meshv1alpha1 "github.com/kdubbo/api/mesh/v1alpha1"
@@ -36,6 +37,9 @@ func TestInstallerGRPCEngineTemplateInjectsDirectXDSConnection(t *testing.T) {
 	if err != nil {
 		t.Fatalf("failed to read grpc-engine.yaml: %v", err)
 	}
+	if strings.Contains(string(templateBytes), "{{") || strings.Contains(string(templateBytes), "}}") {
+		t.Fatalf("grpc-engine.yaml contains template delimiters")
+	}
 	templates, err := ParseTemplates(RawTemplates{
 		ProxylessGRPCTemplateName: string(templateBytes),
 	})
@@ -83,22 +87,89 @@ func TestInstallerGRPCEngineTemplateInjectsDirectXDSConnection(t *testing.T) {
 	}
 
 	if len(injectedPod.Spec.Containers) != 1 {
-		t.Fatalf("template containers = %d, want 1 application container overlay", len(injectedPod.Spec.Containers))
+		t.Fatalf("template containers = %d, want 1 hard-coded application container overlay", len(injectedPod.Spec.Containers))
+	}
+	if err := postProcessPod(mergedPod, *injectedPod, req); err != nil {
+		t.Fatalf("postProcessPod() failed: %v", err)
 	}
-	assertDirectXDSConnection(t, injectedPod, pod.Name)
 
 	if len(mergedPod.Spec.Containers) != 1 {
 		t.Fatalf("containers = %d, want 1 application container", len(mergedPod.Spec.Containers))
 	}
-	assertDirectXDSConnection(t, mergedPod, pod.Name)
+	assertDirectXDSConnection(t, mergedPod, "app", ProxylessGRPCSecretNameForMeta(pod.ObjectMeta))
 }
 
-func assertDirectXDSConnection(t *testing.T, pod *corev1.Pod, podName string) {
+func TestInstallerGRPCEngineTemplateUsesGenerateNameForDeploymentPods(t *testing.T) {
+	_, currentFile, _, ok := runtime.Caller(0)
+	if !ok {
+		t.Fatalf("runtime.Caller() failed")
+	}
+	templatePath := filepath.Join(filepath.Dir(currentFile), "../../..", "dubboinstaller/charts/dubbod/files/grpc-engine.yaml")
+	templateBytes, err := os.ReadFile(templatePath)
+	if err != nil {
+		t.Fatalf("failed to read grpc-engine.yaml: %v", err)
+	}
+	templates, err := ParseTemplates(RawTemplates{
+		ProxylessGRPCTemplateName: string(templateBytes),
+	})
+	if err != nil {
+		t.Fatalf("ParseTemplates() failed: %v", err)
+	}
+	valuesConfig, err := NewValuesConfig("{}")
+	if err != nil {
+		t.Fatalf("NewValuesConfig() failed: %v", err)
+	}
+
+	pod := &corev1.Pod{
+		ObjectMeta: metav1.ObjectMeta{
+			GenerateName: "nginx-95575cc5d-",
+			Namespace:    "app",
+			Annotations: map[string]string{
+				ProxylessInjectTemplatesAnnoName: ProxylessGRPCTemplateName,
+			},
+		},
+		Spec: corev1.PodSpec{
+			ServiceAccountName: "nginx",
+			Containers: []corev1.Container{{
+				Name:  "nginx",
+				Image: "nginx:1.27-alpine",
+			}},
+		},
+	}
+	req := InjectionParameters{
+		pod:          pod,
+		templates:    templates,
+		valuesConfig: valuesConfig,
+		meshGlobalConfig: &meshv1alpha1.MeshGlobalConfig{
+			TrustDomain: "cluster.local",
+			DefaultConfig: &meshv1alpha1.ProxyConfig{
+				DiscoveryAddress: "dubbod.dubbo-system.svc:15012",
+			},
+		},
+	}
+
+	mergedPod, injectedPod, err := RunTemplate(req)
+	if err != nil {
+		t.Fatalf("RunTemplate() failed: %v", err)
+	}
+	if err := postProcessPod(mergedPod, *injectedPod, req); err != nil {
+		t.Fatalf("postProcessPod() failed: %v", err)
+	}
+	if len(mergedPod.Spec.Containers) != 1 {
+		t.Fatalf("containers = %d, want original nginx container only", len(mergedPod.Spec.Containers))
+	}
+	assertDirectXDSConnection(t, mergedPod, "nginx", ProxylessGRPCSecretNameForMeta(pod.ObjectMeta))
+	if got := mergedPod.Spec.Volumes[0].Secret.SecretName; got == ProxylessGRPCSecretName("") {
+		t.Fatalf("secret name = %q, want generateName-based secret", got)
+	}
+}
+
+func assertDirectXDSConnection(t *testing.T, pod *corev1.Pod, containerName, secretName string) {
 	t.Helper()
 
 	container := pod.Spec.Containers[0]
-	if container.Name != "app" {
-		t.Fatalf("container name = %q, want app", container.Name)
+	if container.Name != containerName {
+		t.Fatalf("container name = %q, want %q", container.Name, containerName)
 	}
 	if !hasEnv(container.Env, "GRPC_XDS_BOOTSTRAP", ProxylessGRPCBootstrapPath) {
 		t.Fatalf("GRPC_XDS_BOOTSTRAP env missing")
@@ -133,7 +204,7 @@ func assertDirectXDSConnection(t *testing.T, pod *corev1.Pod, podName string) {
 	if pod.Spec.Volumes[0].Secret == nil {
 		t.Fatalf("volume secret = nil, want SecretVolumeSource")
 	}
-	if got, want := pod.Spec.Volumes[0].Secret.SecretName, ProxylessGRPCSecretName(podName); got != want {
+	if got, want := pod.Spec.Volumes[0].Secret.SecretName, secretName; got != want {
 		t.Fatalf("secret name = %q, want %q", got, want)
 	}
 	if pod.Spec.Volumes[0].Secret.DefaultMode == nil {
@@ -184,7 +255,7 @@ func TestAddApplicationContainerConfigInjectsProxylessGRPCContract(t *testing.T)
 	if vol.Secret == nil {
 		t.Fatalf("volume secret = nil, want SecretVolumeSource")
 	}
-	if got, want := vol.Secret.SecretName, ProxylessGRPCSecretName(pod.Name); got != want {
+	if got, want := vol.Secret.SecretName, ProxylessGRPCSecretNameForMeta(pod.ObjectMeta); got != want {
 		t.Fatalf("secret name = %q, want %q", got, want)
 	}
 
@@ -213,6 +284,13 @@ func TestProxylessGRPCSecretNameFitsKubernetesLengthLimit(t *testing.T) {
 	}
 }
 
+func TestProxylessGRPCSecretNameForMetaPrefersGenerateName(t *testing.T) {
+	meta := metav1.ObjectMeta{Name: "nginx-95575cc5d-kh98x", GenerateName: "nginx-95575cc5d-"}
+	if got, want := ProxylessGRPCSecretNameForMeta(meta), ProxylessGRPCSecretName(meta.GenerateName); got != want {
+		t.Fatalf("secret name = %q, want %q", got, want)
+	}
+}
+
 func hasEnv(envs []corev1.EnvVar, name, value string) bool {
 	for _, env := range envs {
 		if env.Name == name && env.Value == value {
diff --git a/pkg/kube/inject/template.go b/pkg/kube/inject/template.go
index 705b8beb..c3552b15 100644
--- a/pkg/kube/inject/template.go
+++ b/pkg/kube/inject/template.go
@@ -23,18 +23,5 @@ import (
 var InjectionFuncmap = createInjectionFuncmap()
 
 func createInjectionFuncmap() template.FuncMap {
-	return template.FuncMap{
-		"proxylessGRPCSecretName":       ProxylessGRPCSecretName,
-		"proxylessGRPCDiscoveryAddress": ProxylessGRPCDiscoveryAddress,
-		"proxylessGRPCTrustDomain":      ProxylessGRPCTrustDomain,
-		"proxylessGRPCBootstrapPath": func() string {
-			return ProxylessGRPCBootstrapPath
-		},
-		"proxylessXDSVolumeName": func() string {
-			return ProxylessXDSVolumeName
-		},
-		"proxylessXDSMountPath": func() string {
-			return ProxylessXDSMountPath
-		},
-	}
+	return template.FuncMap{}
 }
diff --git a/pkg/kube/inject/webhook.go b/pkg/kube/inject/webhook.go
index fb5b032d..7440ccb0 100644
--- a/pkg/kube/inject/webhook.go
+++ b/pkg/kube/inject/webhook.go
@@ -371,6 +371,7 @@ func postProcessPod(pod *corev1.Pod, injectedPod corev1.Pod, req InjectionParame
 		pod.Labels = map[string]string{}
 	}
 
+	removeTemplateOnlyContainers(pod, injectedPod, req.pod)
 	overwriteClusterInfo(pod, req)
 
 	if shouldInjectProxylessGRPC(req) {
@@ -385,6 +386,39 @@ func postProcessPod(pod *corev1.Pod, injectedPod corev1.Pod, req InjectionParame
 	return nil
 }
 
+func removeTemplateOnlyContainers(pod *corev1.Pod, injectedPod corev1.Pod, originalPod *corev1.Pod) {
+	if originalPod == nil {
+		return
+	}
+
+	originalContainers := map[string]struct{}{}
+	for _, container := range originalPod.Spec.Containers {
+		originalContainers[container.Name] = struct{}{}
+	}
+
+	templateOnlyContainers := map[string]struct{}{}
+	for _, container := range injectedPod.Spec.Containers {
+		if container.Image != "" {
+			continue
+		}
+		if _, found := originalContainers[container.Name]; !found {
+			templateOnlyContainers[container.Name] = struct{}{}
+		}
+	}
+	if len(templateOnlyContainers) == 0 {
+		return
+	}
+
+	containers := pod.Spec.Containers[:0]
+	for _, container := range pod.Spec.Containers {
+		if _, remove := templateOnlyContainers[container.Name]; remove {
+			continue
+		}
+		containers = append(containers, container)
+	}
+	pod.Spec.Containers = containers
+}
+
 func addApplicationContainerConfig(pod *corev1.Pod, req InjectionParameters) {
 	discoveryAddress := ""
 	trustDomain := constants.DefaultClusterLocalDomain
@@ -400,7 +434,11 @@ func addApplicationContainerConfig(pod *corev1.Pod, req InjectionParameters) {
 		discoveryAddress = req.proxyConfig.GetDiscoveryAddress()
 	}
 
-	secretName := ProxylessGRPCSecretName(pod.Name)
+	meta := pod.ObjectMeta
+	if req.pod != nil {
+		meta = req.pod.ObjectMeta
+	}
+	secretName := ProxylessGRPCSecretNameForMeta(meta)
 	desiredVolume := corev1.Volume{
 		Name: ProxylessXDSVolumeName,
 		VolumeSource: corev1.VolumeSource{
diff --git a/samples/app/README.md b/samples/app/README.md
new file mode 100644
index 00000000..d3cefcf2
--- /dev/null
+++ b/samples/app/README.md
@@ -0,0 +1,22 @@
+# App Sample
+
+## Install
+
+```bash
+kubectl create ns app
+kubectl label namespace app dubbo-injection=enabled
+kubectl apply -f samples/app/deployment.yaml
+```
+
+```bash
+kubectl -n app patch deployment nginx --type='merge' -p '{"spec":{"template":{"metadata":{"labels":{"version":"v1","proxyless.dubbo.apache.org/inject":"true"},"annotations":{"proxyless.dubbo.apache.org/inject":"true","inject.dubbo.apache.org/templates":"grpc-engine"}}}}}'
+kubectl -n app rollout restart deploy/nginx
+kubectl -n app rollout status deploy/nginx --timeout=180s
+```
+
+## Uninstall
+
+```bash
+kubectl delete -f samples/app/deployment.yaml --ignore-not-found=true
+kubectl delete ns app
+```
diff --git a/samples/app/deployment.yaml b/samples/app/deployment.yaml
new file mode 100644
index 00000000..20d46bef
--- /dev/null
+++ b/samples/app/deployment.yaml
@@ -0,0 +1,92 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: nginx
+  namespace: app
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: nginx
+  namespace: app
+  labels:
+    app: nginx
+spec:
+  type: ClusterIP
+  selector:
+    app: nginx
+  ports:
+  - name: http
+    port: 80
+    targetPort: 80
+    protocol: TCP
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: nginx
+  namespace: app
+  labels:
+    app: nginx
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: nginx
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      serviceAccountName: nginx
+      containers:
+      - name: app
+        image: nginx:1.27-alpine
+        imagePullPolicy: IfNotPresent
+        ports:
+        - name: http
+          containerPort: 80
+          protocol: TCP
+        env:
+        - name: SERVICE_VERSION
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.labels['version']
+        - name: SERVICE_NAMESPACE
+          valueFrom:
+            fieldRef:
+              fieldPath: metadata.namespace
+        - name: SERVICE_PORT
+          value: "80"
+        readinessProbe:
+          httpGet:
+            path: /
+            port: 80
+          initialDelaySeconds: 5
+          periodSeconds: 5
+          timeoutSeconds: 2
+          failureThreshold: 3
+        livenessProbe:
+          httpGet:
+            path: /
+            port: 80
+          initialDelaySeconds: 10
+          periodSeconds: 10
+          timeoutSeconds: 2
+          failureThreshold: 3
diff --git a/samples/grpc-app/README.md b/samples/grpc-app/README.md
deleted file mode 100644
index f5127ee7..00000000
--- a/samples/grpc-app/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# gRPC Proxyless Example
-
-This is an example demonstrating a gRPC application.
\ No newline at end of file
diff --git a/samples/grpc-app/grpc-app.yaml b/samples/grpc-app/grpc-app.yaml
deleted file mode 100644
index ce422f99..00000000
--- a/samples/grpc-app/grpc-app.yaml
+++ /dev/null
@@ -1,210 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: Service
-metadata:
-  labels:
-    app: provider
-  name: provider
-  namespace: grpc-app
-spec:
-  selector:
-    app: provider
-  type: ClusterIP
-  ports:
-    - name: grpc
-      port: 7070
-      targetPort: 17070
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: provider-v1
-  namespace: grpc-app
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      app: provider
-      version: v1
-  template:
-    metadata:
-      annotations:
-        proxyless.dubbo.apache.org/inject: "true"
-        inject.dubbo.apache.org/templates: grpc-engine
-      labels:
-        app: provider
-        version: v1
-    spec:
-      containers:
-        - name: app
-          image: dubboregistry/grpc-provider:master
-          imagePullPolicy: Always
-          ports:
-            - containerPort: 17070
-              protocol: TCP
-              name: grpc
-          env:
-            - name: GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT
-              value: "true"
-            - name: INSTANCE_IP
-              valueFrom:
-                fieldRef:
-                  apiVersion: v1
-                  fieldPath: status.podIP
-            - name: SERVICE_VERSION
-              valueFrom:
-                fieldRef:
-                  fieldPath: metadata.labels['version']
-            - name: SERVICE_NAMESPACE
-              valueFrom:
-                fieldRef:
-                  fieldPath: metadata.namespace
-            - name: SERVICE_PORT
-              value: "17070"
-          volumeMounts:
-            - mountPath: /var/lib/dubbo/data
-              name: dubbo-data
-          readinessProbe:
-            tcpSocket:
-              port: 17070
-            initialDelaySeconds: 5
-            periodSeconds: 5
-            timeoutSeconds: 2
-            successThreshold: 1
-            failureThreshold: 3
-          livenessProbe:
-            tcpSocket:
-              port: 17070
-            initialDelaySeconds: 10
-            periodSeconds: 10
-            timeoutSeconds: 2
-            successThreshold: 1
-            failureThreshold: 3
-      volumes:
-        - name: dubbo-data
-          emptyDir: {}
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: provider-v2
-  namespace: grpc-app
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      app: provider
-      version: v2
-  template:
-    metadata:
-      annotations:
-        proxyless.dubbo.apache.org/inject: "true"
-        inject.dubbo.apache.org/templates: grpc-engine
-      labels:
-        app: provider
-        version: v2
-    spec:
-      containers:
-        - name: app
-          image: dubboregistry/grpc-provider:master
-          imagePullPolicy: Always
-          ports:
-            - containerPort: 17070
-              protocol: TCP
-              name: grpc
-          env:
-            - name: GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT
-              value: "true"
-            - name: INSTANCE_IP
-              valueFrom:
-                fieldRef:
-                  apiVersion: v1
-                  fieldPath: status.podIP
-            - name: SERVICE_VERSION
-              valueFrom:
-                fieldRef:
-                  fieldPath: metadata.labels['version']
-            - name: SERVICE_NAMESPACE
-              valueFrom:
-                fieldRef:
-                  fieldPath: metadata.namespace
-            - name: SERVICE_PORT
-              value: "17070"
-          volumeMounts:
-            - mountPath: /var/lib/dubbo/data
-              name: dubbo-data
-          readinessProbe:
-            tcpSocket:
-              port: 17070
-            initialDelaySeconds: 5
-            periodSeconds: 5
-            timeoutSeconds: 2
-            successThreshold: 1
-            failureThreshold: 3
-          livenessProbe:
-            tcpSocket:
-              port: 17070
-            initialDelaySeconds: 10
-            periodSeconds: 10
-            timeoutSeconds: 2
-            successThreshold: 1
-            failureThreshold: 3
-      volumes:
-        - name: dubbo-data
-          emptyDir: {}
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: consumer
-  namespace: grpc-app
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      app: consumer
-  template:
-    metadata:
-      annotations:
-        proxyless.dubbo.apache.org/inject: "true"
-        inject.dubbo.apache.org/templates: grpc-engine
-      labels:
-        app: consumer
-    spec:
-      containers:
-        - name: app
-          # Replace with your own image containing the consumer binary
-          image: dubboregistry/grpc-consumer:master
-          imagePullPolicy: Always
-          ports:
-            - containerPort: 17171
-              protocol: TCP
-              name: grpc-test
-          env:
-            - name: GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT
-              value: "true"
-            - name: INSTANCE_IP
-              valueFrom:
-                fieldRef:
-                  apiVersion: v1
-                  fieldPath: status.podIP
-          volumeMounts:
-            - mountPath: /var/lib/dubbo/data
-              name: dubbo-data
-      volumes:
-        - name: dubbo-data
-          emptyDir: {}
\ No newline at end of file