Skip to content

Commit

Permalink
Add log output for hostname request
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Jul 9, 2024
1 parent 069b7f8 commit 8828812
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/admission/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import (
"fmt"
"net/http"
"os"

"github.com/sirupsen/logrus"
)

func pingHandler(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("pong\n"))
}

func hostnameHandler(w http.ResponseWriter, _ *http.Request) {
func hostnameHandler(w http.ResponseWriter, req *http.Request) {
n, err := os.Hostname()
if err != nil {
err := fmt.Errorf("failed to get hostname: %w", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
logrus.Infof("handle hostname request from [%v]", req.Host)
w.Write([]byte(n + "\n"))
}

0 comments on commit 8828812

Please sign in to comment.