Skip to content

Commit

Permalink
CIDR to select public IP upon node's startup
Browse files Browse the repository at this point in the history
* new env var `AIS_PUBLIC_IP_CIDR`
  if defined, will take precedence over `AIS_CLUSTER_CIDR`
* for comments, see see api/env/ais
* part two, prev. commit: 8defcb3

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Aug 9, 2024
1 parent fa96f71 commit e685b40
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
16 changes: 15 additions & 1 deletion ais/htrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ func (h *htrun) initSnode(config *cmn.Config) {
cos.ExitLogf("failed to get local IP addr list: %v", err)
}

if l := len(addrList); l > 1 {
if config.HostNet.Hostname == "" || cmn.Rom.FastV(4, cos.SmoduleAIS) {
nlog.Infoln(l, "local unicast IPs:")
for _, addr := range addrList {
nlog.Infoln("\t", addr.String())
}
}
}

// 1. pub net

// the "hostname" field can be a single IP address or DNS hostname;
Expand All @@ -329,8 +338,13 @@ func (h *htrun) initSnode(config *cmn.Config) {
for i, addr := range extra {
pubExtra[i].Init(proto, addr, port)
}
// already logged (pub, extra)
} else {
nlog.Infof("%s (user) access: %v (%q)", cmn.NetPublic, pubAddr, config.HostNet.Hostname)
var s string
if config.HostNet.Hostname != "" {
s = " (config: " + config.HostNet.Hostname + ")"
}
nlog.Infof("%s (user) access: %v%s", cmn.NetPublic, pubAddr, s)
}

// 2. intra-cluster
Expand Down
3 changes: 2 additions & 1 deletion ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/NVIDIA/aistore/ais/s3"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/archive"
"github.com/NVIDIA/aistore/cmn/atomic"
Expand Down Expand Up @@ -94,7 +95,7 @@ func (p *proxy) init(config *cmn.Config) {

cos.InitShortID(p.si.Digest())

if network, err := localRedirectCIDR(); err != nil {
if network, err := _parseCIDR(env.AIS.LocalRedirectCIDR, ""); err != nil {
cos.ExitLog(err) // FATAL
} else {
p.si.LocalNet = network
Expand Down
29 changes: 14 additions & 15 deletions ais/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type (
func (na netAccess) isSet(flag netAccess) bool { return na&flag == flag }

func (addr *localIPv4Info) String() string {
return fmt.Sprintf("unicast IP: %s (MTU %d)", addr.ipv4, addr.mtu)
return fmt.Sprintf("IP: %s (MTU %d)", addr.ipv4, addr.mtu)
}

func (addr *localIPv4Info) warn() {
Expand Down Expand Up @@ -183,12 +183,13 @@ func _selectHost(locIPs []*localIPv4Info, hostnames []string) (string, error) {
return "", err
}

// _localIP takes a list of local IPv4s and returns the best fit for a daemon to listen on it
// given a list of local IPv4s return the best fit to listen on
func _localIP(addrList []*localIPv4Info) (ip net.IP, _ error) {
l := len(addrList)
if l == 0 {
return nil, errors.New("no unicast addresses to choose from")
}

if l == 1 {
if ip = net.ParseIP(addrList[0].ipv4); ip == nil {
return nil, fmt.Errorf(fmtErrParseIP, addrList[0].ipv4)
Expand All @@ -198,20 +199,13 @@ func _localIP(addrList []*localIPv4Info) (ip net.IP, _ error) {
return ip, nil
}

// always log when multi-choice
nlog.Infoln(l, "local unicast IPs:")
for _, addr := range addrList {
nlog.Infoln(" ", addr.String())
}

// NOTE:
// reusing local-redirect CIDR ("AIS_CLUSTER_CIDR") for the second and separate purpose -
// to select public IP (to listen on) from the `addrList` of local unicast IP interfaces

// - try using environment to eliminate ambiguity
// - env.AIS.PubIPv4CIDR ("AIS_PUBLIC_IP_CIDR") takes precedence
var (
selected = -1
parsed net.IP
network, err = localRedirectCIDR()
network, err = _parseCIDR(env.AIS.LocalRedirectCIDR, env.AIS.PubIPv4CIDR)
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -248,14 +242,19 @@ warn:
return ip, nil
}

func localRedirectCIDR() (*net.IPNet, error) {
cidr := os.Getenv(env.AIS.LocalRedirectCIDR)
func _parseCIDR(name, name2 string) (*net.IPNet, error) {
cidr := os.Getenv(name)
if name2 != "" {
if mask := os.Getenv(name2); mask != "" {
cidr, name = mask, name2
}
}
if cidr == "" {
return nil, nil
}
_, network, err := net.ParseCIDR(cidr)
if err != nil {
return nil, fmt.Errorf("invalid '%s=%s': %v", env.AIS.LocalRedirectCIDR, cidr, err)
return nil, fmt.Errorf("invalid '%s=%s': %v", name, cidr, err)
}
return network, nil
}
Expand Down
9 changes: 7 additions & 2 deletions api/env/ais.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ var (
Endpoint string
PrimaryEP string

// networking: local redirect
// networking: two CIDR masks
LocalRedirectCIDR string
PubIPv4CIDR string

// https
UseHTTPS string
Expand All @@ -43,8 +44,12 @@ var (
Endpoint: "AIS_ENDPOINT",
PrimaryEP: "AIS_PRIMARY_EP",

// differentiate local (same CIDR) clients for faster HTTP redirect
// two CIDRs, respectively:
// 1. differentiate local (same CIDR) clients for faster HTTP redirect
// 2. at node startup: when present with multiple choices, select one matching local unicast IP
// to use it as node's public interface
LocalRedirectCIDR: "AIS_CLUSTER_CIDR",
PubIPv4CIDR: "AIS_PUBLIC_IP_CIDR",

// false: HTTP transport, with all the TLS config (below) ignored
// true: HTTPS/TLS
Expand Down
6 changes: 5 additions & 1 deletion scripts/clean_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ if [[ ${deployment} == "remote" || ${deployment} == "all" ]]; then
if [[ ${deployment} == "all" ]]; then
echo -e "\n*** Remote cluster ***"
fi
echo -e "1\n1\n3\n" | DEPLOY_AS_NEXT_TIER="true" AIS_AUTHN_ENABLED=false make deploy

## NOTE: must have the same build tags and, in particular, same backends -
## otherwise, `make deploy` below will rebuild and replace aisnode binary

echo -e "1\n1\n3\n" | DEPLOY_AS_NEXT_TIER="true" AIS_BACKEND_PROVIDERS="${AIS_BACKEND_PROVIDERS}" AIS_AUTHN_ENABLED=false make deploy

# Do not try attach remote cluster if the main cluster did not start.
if [[ ${deployment} == "all" ]]; then
Expand Down

0 comments on commit e685b40

Please sign in to comment.