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

update logic for GetHostIP and allowedNetworks #213

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ func (s *service) BeforeServe(

var networksList []string
if allNetworks, ok := csictx.LookupEnv(ctx, EnvAllowedNetworks); ok {
networksList = strings.Split(allNetworks, " ")
allNetworks = strings.TrimSpace(allNetworks)
if allNetworks == "" {
networksList = []string{}
} else {
networksList = strings.Split(allNetworks, ",")
}
}
opts.allowedNetworks = networksList

Expand Down
11 changes: 11 additions & 0 deletions service/utils/emcutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ func GetHostIP() ([]string, error) {
}
}
if len(lookupIps) == 0 {
// Compute host ip from 'hostname -i' when lookup address fails
cmd = exec.Command("hostname", "-i")
cmdOutput = &bytes.Buffer{}
cmd.Stdout = cmdOutput
err = cmd.Run()
if err != nil {
return nil, err
}
output := string(cmdOutput.Bytes())
ips := strings.Split(strings.TrimSpace(output), " ")
lookupIps = append(lookupIps, ips[0])
}
return lookupIps, nil
Expand All @@ -197,6 +207,7 @@ func GetAddresses(allowedNetworks []string, addrs []net.Addr) ([]string, error)
var nodeIPs []string
networks := make(map[string]bool)
for _, cnet := range allowedNetworks {
cnet = strings.TrimSpace(cnet)
_, cnet, err := net.ParseCIDR(cnet)
if err != nil {
return nil, err
Expand Down