Skip to content

Commit

Permalink
Atlas-12675: Replacing google dns with internal csp
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutipathak2 committed May 6, 2022
1 parent 21379d1 commit d67a1fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions charts/dapr/charts/dapr_sidecar_injector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ webhookFailurePolicy: Ignore
sidecarImagePullPolicy: Always
runAsNonRoot: true
resources: {}
host:
cpNoa:
domain: ""
8 changes: 7 additions & 1 deletion utils/host.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"fmt"
"net"
"os"

Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions utils/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit d67a1fa

Please sign in to comment.