Skip to content

Commit

Permalink
local playground with disks; frename to dir
Browse files Browse the repository at this point in the history
* skip or not to skip localhost
* clarify one possible PUT fail

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jul 2, 2024
1 parent f7c581d commit a53d3b0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
31 changes: 28 additions & 3 deletions ais/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,22 @@ func getLocalIPv4s(config *cmn.Config) (addrlist []*localIPv4Info, err error) {
return
}

var skip, warned bool
for _, addr := range addrs {
curr := &localIPv4Info{}
if ipnet, ok := addr.(*net.IPNet); ok {
// production or K8s: skip loopbacks
if ipnet.IP.IsLoopback() && (!config.TestingEnv() || k8s.IsK8s()) {
continue
if ipnet.IP.IsLoopback() {
// K8s: always skip (ie, exclude) 127.0.0.1 loopback
if k8s.IsK8s() {
continue
}
// non K8s and fspaths: skip?
if !config.TestingEnv() {
skip, warned = haveFspathsSkipLoopback(config, warned)
if skip {
continue
}
}
}
if ipnet.IP.To4() == nil {
continue
Expand Down Expand Up @@ -107,6 +117,21 @@ func getLocalIPv4s(config *cmn.Config) (addrlist []*localIPv4Info, err error) {
return addrlist, nil
}

func haveFspathsSkipLoopback(config *cmn.Config, warned bool) (bool, bool) { //nolint:unparam // be warned
const haveFspaths = "deployment type is not K8s and not dev"
if config.HostNet.Hostname != "" {
if !warned {
nlog.Warningln(haveFspaths+", pub host is configured:", config.HostNet.Hostname)
nlog.Warningln("- not including loopback in the list of local unicast IPv4")
}
return true /*skip*/, true
}
if !warned {
nlog.Warningln(haveFspaths + " but still including loopback in the list of local unicast IPv4")
}
return false /*skip*/, true
}

// given configured list of hostnames, return the first one matching local unicast IPv4
func _selectHost(locIPs []*localIPv4Info, hostnames []string) (string, error) {
sb := &strings.Builder{}
Expand Down
16 changes: 13 additions & 3 deletions cmn/cos/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,25 @@ func CreateFile(fqn string) (*os.File, error) {
// (creates destination directory if doesn't exist)
func Rename(src, dst string) (err error) {
err = os.Rename(src, dst)
if err == nil || !os.IsNotExist(err) {
return
if err == nil {
return nil
}
if !os.IsNotExist(err) {
if os.IsExist(err) {
if finfo, errN := os.Stat(dst); errN == nil && finfo.IsDir() {
// [design tradeoff]
// keeping objects under their respective sha256 would avoid this one
return fmt.Errorf("destination %q is a (virtual) directory", dst)
}
}
return err
}
// create and retry (slow path)
err = CreateDir(filepath.Dir(dst))
if err == nil {
err = os.Rename(src, dst)
}
return
return err
}

// RemoveFile removes path; returns nil upon success or if the path does not exist.
Expand Down
6 changes: 3 additions & 3 deletions cmn/k8s/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Init() {
_initClient()
client, err := GetClient()
if err != nil {
nlog.Infoln(nonK8s, "(init k8s-client returned:", _short(err)+")")
nlog.Infoln(nonK8s, "(init k8s-client returned: '"+_short(err)+"')")
return
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func _ppvols(volumes []v1.Volume) {
func IsK8s() bool { return NodeName != "" }

func _short(err error) string {
const sizeLimit = 20
const sizeLimit = 32
msg := err.Error()
idx := strings.IndexByte(msg, ',')
switch {
Expand All @@ -110,6 +110,6 @@ func _short(err error) string {
case idx > sizeLimit:
return msg[:idx]
default:
return msg[:sizeLimit]
return msg[:sizeLimit] + " ..."
}
}

0 comments on commit a53d3b0

Please sign in to comment.