GCE Cloud provider changes for ESIPP
Add feature gate (ExternalTrafficLocalOnly) for alpha feature
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
.PHONY: all netexec image push clean
|
||||
|
||||
TAG = 1.5
|
||||
TAG = 1.6
|
||||
PREFIX = gcr.io/google_containers
|
||||
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ func main() {
|
||||
|
||||
func startHTTPServer(httpPort int) {
|
||||
http.HandleFunc("/", rootHandler)
|
||||
http.HandleFunc("/clientip", clientIpHandler)
|
||||
http.HandleFunc("/echo", echoHandler)
|
||||
http.HandleFunc("/exit", exitHandler)
|
||||
http.HandleFunc("/hostname", hostnameHandler)
|
||||
@@ -102,6 +103,11 @@ func echoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%s", r.FormValue("msg"))
|
||||
}
|
||||
|
||||
func clientIpHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("GET /clientip")
|
||||
fmt.Fprintf(w, r.RemoteAddr)
|
||||
}
|
||||
|
||||
func exitHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("GET /exit?code=%s", r.FormValue("code"))
|
||||
code, err := strconv.Atoi(r.FormValue("code"))
|
||||
@@ -345,7 +351,7 @@ func hostNameHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, getHostName())
|
||||
}
|
||||
|
||||
// udp server only supports the hostName command.
|
||||
// udp server supports the hostName, echo and clientIP commands.
|
||||
func startUDPServer(udpPort int) {
|
||||
serverAddress, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", udpPort))
|
||||
assertNoError(err)
|
||||
@@ -363,8 +369,8 @@ func startUDPServer(udpPort int) {
|
||||
for {
|
||||
n, clientAddress, err := serverConn.ReadFromUDP(buf)
|
||||
assertNoError(err)
|
||||
receivedText := strings.TrimSpace(string(buf[0:n]))
|
||||
if receivedText == "hostName" || receivedText == "hostname" {
|
||||
receivedText := strings.ToLower(strings.TrimSpace(string(buf[0:n])))
|
||||
if receivedText == "hostname" {
|
||||
log.Println("Sending udp hostName response")
|
||||
_, err = serverConn.WriteToUDP([]byte(getHostName()), clientAddress)
|
||||
assertNoError(err)
|
||||
@@ -377,6 +383,10 @@ func startUDPServer(udpPort int) {
|
||||
log.Printf("Echoing %v\n", resp)
|
||||
_, err = serverConn.WriteToUDP([]byte(resp), clientAddress)
|
||||
assertNoError(err)
|
||||
} else if receivedText == "clientip" {
|
||||
log.Printf("Sending back clientip to %s", clientAddress.String())
|
||||
_, err = serverConn.WriteToUDP([]byte(clientAddress.String()), clientAddress)
|
||||
assertNoError(err)
|
||||
} else if len(receivedText) > 0 {
|
||||
log.Printf("Unknown udp command received: %v\n", receivedText)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user