func checkTimeSync(s ssh.Interface, ipList []string) error {
logger.Info("checker:timeSync %v", ipList)
for _, ip := range ipList {
timeStamp, err := s.CmdToString(ip, "date +%s", "")
if err != nil {
return fmt.Errorf("failed to get %s timestamp, %v", ip, err)
}
ts, err := strconv.Atoi(timeStamp)
if err != nil {
return fmt.Errorf("failed to reverse timestamp %s, %v", timeStamp, err)
}
timeDiff := time.Since(time.Unix(int64(ts), 0)).Minutes()
if timeDiff < -1 || timeDiff > 1 {
return fmt.Errorf("the time of %s node is not synchronized", ip)
}
}
return nil
}