Skip to content

Commit

Permalink
ais: improve logging around initalization
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Marcinkiewicz <januszm@nvidia.com>
  • Loading branch information
VirrageS committed Nov 28, 2024
1 parent b5d471b commit 25940e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
19 changes: 9 additions & 10 deletions ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,22 @@ func initPID(config *cmn.Config) (pid string) {
// 1. ID from env
if pid = envDaemonID(apc.Proxy); pid != "" {
if err := cos.ValidateDaemonID(pid); err != nil {
nlog.Errorf("Warning: %v", err)
nlog.Errorln("Daemon ID loaded from env is invalid:", err)
}
nlog.Infof("Initialized %s from env", meta.Pname(pid))
return
}

// 2. proxy, K8s
// 2. ID from Kubernetes Node name.
if k8s.IsK8s() {
// NOTE: always generate i.e., compute
if net.ParseIP(k8s.NodeName) != nil { // does not parse as IP
nlog.Warningf("using K8s node name %q, an IP addr, to compute _persistent_ proxy ID", k8s.NodeName)
}
return cos.HashK8sProxyID(k8s.NodeName)
pid = cos.HashK8sProxyID(k8s.NodeName)
nlog.Infof("Initialized %s from K8s node name %q", meta.Pname(pid), k8s.NodeName)
return pid
}

// 3. try to read ID
// 3. Read ID from persistent file.
if pid = readProxyID(config); pid != "" {
nlog.Infof("p[%s] from %q", pid, fname.ProxyID)
nlog.Infof("Initialized %s from file %q", meta.Pname(pid), fname.ProxyID)
return
}

Expand All @@ -154,7 +153,7 @@ func initPID(config *cmn.Config) (pid string) {
// store ID on disk
err = os.WriteFile(filepath.Join(config.ConfigDir, fname.ProxyID), []byte(pid), cos.PermRWR)
debug.AssertNoErr(err)
nlog.Infof("p[%s] ID randomly generated", pid)
nlog.Infof("Initialized %s with randomly generated ID", meta.Pname(pid))
return
}

Expand Down
14 changes: 7 additions & 7 deletions ais/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,24 @@ func (t *target) initHostIP(config *cmn.Config) {
func initTID(config *cmn.Config) (tid string, generated bool) {
if tid = envDaemonID(apc.Target); tid != "" {
if err := cos.ValidateDaemonID(tid); err != nil {
nlog.Errorln("Warning:", err)
nlog.Errorln("Daemon ID loaded from env is invalid:", err)
}
nlog.Infof("Initialized %s from env", meta.Tname(tid))
return tid, false
}

var err error
if tid, err = fs.LoadNodeID(config.FSP.Paths); err != nil {
if tid, err := fs.LoadNodeID(config.FSP.Paths); err != nil {
cos.ExitLog(err) // FATAL
}
if tid != "" {
} else if tid != "" {
nlog.Infof("Initialized %s from file", meta.Tname(tid))
return tid, false
}

// this target: generate random ID
tid = genDaemonID(apc.Target, config)
err = cos.ValidateDaemonID(tid)
err := cos.ValidateDaemonID(tid)
debug.AssertNoErr(err)
nlog.Infoln(meta.Tname(tid) + ": ID randomly generated")
nlog.Infof("Initialized %s with randomly generated ID", meta.Tname(tid))
return tid, true
}

Expand Down
27 changes: 13 additions & 14 deletions cmn/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/NVIDIA/aistore/api/env"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/cmn/nlog"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -44,8 +45,8 @@ func Init() {

var (
pod *v1.Pod
nodeName = os.Getenv(env.AIS.K8sNode)
podName = os.Getenv(env.AIS.K8sPod)
nodeName = os.Getenv(env.AIS.K8sNode)
)
if podName != "" {
debug.Func(func() {
Expand All @@ -57,36 +58,34 @@ func Init() {
}
nlog.Infof("Checking pod: %q, node: %q", podName, nodeName)

// node name specified - proceed directly to check
if nodeName != "" {
goto checkNode
}
if podName == "" {
nlog.Infoln("environment (above) not set =>", nonK8s)
if nodeName != "" {
// If the Pod is not set but the Node is, we should continue checking.
goto checkNode
}
nlog.Infof("Env %q and %q are not set => %s", env.AIS.K8sNode, env.AIS.K8sPod, nonK8s)
return
}

// check POD
// Check Pod.
pod, err = client.Pod(podName)
if err != nil {
nlog.Errorf("Failed to get pod %q: %v", podName, err)
cos.ExitLogf("Failed to get Pod %q, err: %v", podName, err)
return
}
nodeName = pod.Spec.NodeName
nlog.Infoln("pod.Spec: Node", nodeName, "Hostname", pod.Spec.Hostname, "HostNetwork", pod.Spec.HostNetwork)
nlog.Infoln("Pod spec", "name", podName, "namespace", pod.Namespace, "node", nodeName, "hostname", pod.Spec.Hostname, "host_network", pod.Spec.HostNetwork)
_ppvols(pod.Spec.Volumes)

checkNode: // always check Node
checkNode:
// Check Node.
node, err := client.Node(nodeName)
if err != nil {
nlog.Errorf("Failed to get Node %q: %v", nodeName, err)
cos.ExitLogf("Failed to get Node %q, err: %v", nodeName, err)
return
}

NodeName = node.Name
if node.Namespace != "" {
nlog.Infoln("Node", NodeName, "Namespace", node.Namespace)
}
}

func _ppvols(volumes []v1.Volume) {
Expand Down

0 comments on commit 25940e6

Please sign in to comment.