diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject.patch index 423efe76472f..bac75d4c48ea 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject.patch @@ -14,10 +14,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_http_probe_rewrite_template.yaml b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_http_probe_rewrite_template.yaml new file mode 100644 index 000000000000..e8ef66c4261a --- /dev/null +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_http_probe_rewrite_template.yaml @@ -0,0 +1,23 @@ +rewriteAppHTTPProbe: true +initContainers: +- name: istio-init + image: example.com/init:latest +containers: +- name: istio-proxy + image: example.com/proxy:latest + args: + - --statusPort + - 15020 +imagePullSecrets: +- name: istio-image-pull-secrets +volumes: +- emptyDir: + medium: Memory + name: istio-envoy +- name: istio-certs + secret: + [[ if eq .Spec.ServiceAccountName "" -]] + secretName: istio.default + [[ else -]] + secretName: [[ printf "istio.%s" .Spec.ServiceAccountName ]] + [[ end -]] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers.patch index e7bbfd8c7c6a..528c67255997 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers.patch @@ -15,10 +15,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_imagePullSecrets.patch index efd45f7cca03..11ed721cf86e 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_imagePullSecrets.patch @@ -15,10 +15,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes.patch index 4c30b78f05c4..58c1d8e787db 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes.patch @@ -15,10 +15,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes_imagePullSecrets.patch index 4020a280f10f..b4235adb4fbd 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_containers_volumes_imagePullSecrets.patch @@ -15,10 +15,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_imagePullSecrets.patch index 423efe76472f..bac75d4c48ea 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_imagePullSecrets.patch @@ -14,10 +14,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers.patch index 0e316b500fcd..56de687c6252 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers.patch @@ -16,10 +16,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers.patch index e20d929287cc..1864dfec2d38 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers.patch @@ -17,10 +17,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_imagePullSecrets.patch index b9e55f197c13..6bb2b728b86f 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_imagePullSecrets.patch @@ -17,10 +17,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_volumes.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_volumes.patch index d8d112b12770..e3e189d5a134 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_volumes.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_containers_volumes.patch @@ -17,10 +17,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_imagePullSecrets.patch index 565022b50f5f..8e723518777b 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_imagePullSecrets.patch @@ -16,10 +16,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes.patch index 565022b50f5f..8e723518777b 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes.patch @@ -16,10 +16,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes_imagePullSecrets.patch index 1ee1908878e3..454c46a96b56 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initContainers_volumes_imagePullSecrets.patch @@ -16,10 +16,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initcontainers_containers_volumes_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initcontainers_containers_volumes_imagePullSecrets.patch index 9b64f4f6b4ae..d7df08567484 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initcontainers_containers_volumes_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_initcontainers_containers_volumes_imagePullSecrets.patch @@ -17,10 +17,6 @@ { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } ] diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes.patch index 22f1357349b5..7a95bd794fa3 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes.patch @@ -14,10 +14,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes_imagePullSecrets.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes_imagePullSecrets.patch index 445f81896723..e1460a9ef3eb 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes_imagePullSecrets.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_no_volumes_imagePullSecrets.patch @@ -14,10 +14,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace.patch index 480cb8d99ead..b57aa32ce93c 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace.patch @@ -26,10 +26,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace_backwards_compat.patch b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace_backwards_compat.patch index c8c3254a513f..e394411fa4c6 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace_backwards_compat.patch +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_replace_backwards_compat.patch @@ -30,10 +30,6 @@ "value": { "name": "istio-proxy", "image": "example.com/proxy:latest", - "args": [ - "--statusPort", - "15020" - ], "resources": {} } }, diff --git a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_template.yaml b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_template.yaml index 4fc1dbeda581..74dc3cf3dbf5 100644 --- a/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_template.yaml +++ b/pilot/pkg/kube/inject/testdata/webhook/TestWebhookInject_template.yaml @@ -4,9 +4,6 @@ initContainers: containers: - name: istio-proxy image: example.com/proxy:latest - args: - - --statusPort - - 15020 imagePullSecrets: - name: istio-image-pull-secrets volumes: diff --git a/pilot/pkg/kube/inject/webhook_test.go b/pilot/pkg/kube/inject/webhook_test.go index 386fb20b818e..91228c59544c 100644 --- a/pilot/pkg/kube/inject/webhook_test.go +++ b/pilot/pkg/kube/inject/webhook_test.go @@ -515,8 +515,9 @@ func TestInjectRequired(t *testing.T) { func TestInject(t *testing.T) { cases := []struct { - inputFile string - wantFile string + inputFile string + wantFile string + templateFile string }{ { inputFile: "TestWebhookInject.yaml", @@ -595,16 +596,21 @@ func TestInject(t *testing.T) { wantFile: "TestWebhookInject_replace_backwards_compat.patch", }, { - inputFile: "TestWebhookInject_http_probe_rewrite.yaml", - wantFile: "TestWebhookInject_http_probe_rewrite.patch", + inputFile: "TestWebhookInject_http_probe_rewrite.yaml", + wantFile: "TestWebhookInject_http_probe_rewrite.patch", + templateFile: "TestWebhookInject_http_probe_rewrite_template.yaml", }, } for i, c := range cases { input := filepath.Join("testdata/webhook", c.inputFile) want := filepath.Join("testdata/webhook", c.wantFile) + templateFile := "TestWebhookInject_template.yaml" + if c.templateFile != "" { + templateFile = c.templateFile + } t.Run(fmt.Sprintf("[%d] %s", i, c.inputFile), func(t *testing.T) { - wh := createTestWebhookFromFile("testdata/webhook/TestWebhookInject_template.yaml", t) + wh := createTestWebhookFromFile(filepath.Join("testdata/webhook", templateFile), t) podYAML := util.ReadFile(input, t) podJSON, err := yaml.YAMLToJSON(podYAML) if err != nil { @@ -797,6 +803,7 @@ func createTestWebhook(sidecarTemplate string) *Webhook { func createTestWebhookFromFile(templateFile string, t *testing.T) *Webhook { t.Helper() sidecarTemplate := string(util.ReadFile(templateFile, t)) + // fmt.Println("jianfeih debug sidecarTemplate ", sidecarTemplate) return createTestWebhook(sidecarTemplate) }