Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use net module instead of exe os command #23

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package services
import (
"errors"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -115,15 +115,17 @@ func FindWebUIDistPath(ctx context.Context) (*string, error) {
func GetHostIp(ctx context.Context) string {
logger := klog.FromContext(ctx)

cmd := exec.Command("hostname", "-I")
stdout, err := cmd.Output()
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
logger.Error(err, ", [WEBUI] unable to retrive cfm-service's ip address")
return ""
}
output := string(stdout[:])
addresses := strings.Split(output, " ")
return strings.TrimSpace(string(addresses[0]))
defer conn.Close()

localAddr := conn.LocalAddr().(*net.UDPAddr)
logger.V(2).Info("[WEBUI] found webui service", "ip addr", localAddr.IP)

return fmt.Sprintf("%s", localAddr.IP[:]) // deep copy
}

// UpdateBasePath: Replace the base address in the webui distro file
Expand Down
Loading