From d67a1fad6bbe970b11c39e2e26475e1efc5bbb10 Mon Sep 17 00:00:00 2001 From: shrutipathak2 Date: Fri, 6 May 2022 16:26:11 +0530 Subject: [PATCH] Atlas-12675: Replacing google dns with internal csp --- .../templates/dapr_sidecar_injector_deployment.yaml | 2 ++ charts/dapr/charts/dapr_sidecar_injector/values.yaml | 3 +++ utils/host.go | 8 +++++++- utils/host_test.go | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/charts/dapr/charts/dapr_sidecar_injector/templates/dapr_sidecar_injector_deployment.yaml b/charts/dapr/charts/dapr_sidecar_injector/templates/dapr_sidecar_injector_deployment.yaml index 4acf8c4ce22..bd24b70a2cb 100644 --- a/charts/dapr/charts/dapr_sidecar_injector/templates/dapr_sidecar_injector_deployment.yaml +++ b/charts/dapr/charts/dapr_sidecar_injector/templates/dapr_sidecar_injector_deployment.yaml @@ -77,6 +77,8 @@ spec: {{- end }} - "--metrics-port" - "{{ .Values.global.prometheus.port }}" + - "--public-server" + - "{{ .Values.host.cpNoa.domain | required "set host.cpNoa.domain" | quote }}" env: - name: TLS_CERT_FILE value: /dapr/cert/tls.crt diff --git a/charts/dapr/charts/dapr_sidecar_injector/values.yaml b/charts/dapr/charts/dapr_sidecar_injector/values.yaml index ce0e60ecb2a..b1ae215ae45 100644 --- a/charts/dapr/charts/dapr_sidecar_injector/values.yaml +++ b/charts/dapr/charts/dapr_sidecar_injector/values.yaml @@ -12,3 +12,6 @@ webhookFailurePolicy: Ignore sidecarImagePullPolicy: Always runAsNonRoot: true resources: {} +host: + cpNoa: + domain: "" diff --git a/utils/host.go b/utils/host.go index ab41ce3782b..b65caa51314 100644 --- a/utils/host.go +++ b/utils/host.go @@ -1,6 +1,7 @@ package utils import ( + "fmt" "net" "os" @@ -18,9 +19,14 @@ func GetHostAddress() (string, error) { return val, nil } + publicLookupAddr, ok := os.LookupEnv("public-server") + if !ok { + publicLookupAddr = "cp.noa.infoblox.com" + } + // Use udp so no handshake is made. // Any IP can be used, since connection is not established, but we used a known DNS IP. - conn, err := net.Dial("udp", "8.8.8.8:80") + conn, err := net.Dial("udp", fmt.Sprintf("%s:80", publicLookupAddr)) if err != nil { // Could not find one via a UDP connection, so we fallback to the "old" way: try first non-loopback IPv4: addrs, err := net.InterfaceAddrs() diff --git a/utils/host_test.go b/utils/host_test.go index 98d72aa178b..9924894ae55 100644 --- a/utils/host_test.go +++ b/utils/host_test.go @@ -23,4 +23,12 @@ func TestGetHostAdress(t *testing.T) { assert.Nil(t, err) assert.NotEmpty(t, address) }) + + t.Run("public-server present,", func(t *testing.T) { + os.Setenv("public-server", "cp.noa.infoblox.com") + defer os.Clearenv() + address, err := GetHostAddress() + assert.Nil(t, err) + assert.Equal(t, hostIP, address) + }) }