add missing error handling

This commit is contained in:
2026-05-27 18:59:45 +00:00
parent dd54866c4e
commit 72ca7b8fc5
2 changed files with 42 additions and 15 deletions
+13 -6
View File
@@ -35,9 +35,12 @@ func Run() {
cluster := Cluster{}
cluster.Init(client)
start := time.Now()
log.Printf("[INFO] starting cluster sync\n")
cluster.Sync()
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
err := cluster.Sync()
if err != nil {
log.Printf("[Error] error encountered while syncing cluster: %s", err)
} else {
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
}
// set repeating update for full rebuilds
ticker := time.NewTicker(time.Duration(config.ReloadInterval) * time.Second)
@@ -51,8 +54,12 @@ func Run() {
case <-ticker.C:
start := time.Now()
log.Printf("[INFO] starting cluster sync\n")
cluster.Sync()
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
err := cluster.Sync()
if err != nil {
log.Printf("[Error] error encountered while syncing cluster: %s", err)
} else {
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
}
}
}
}()
@@ -188,7 +195,7 @@ func Run() {
})
log.Printf("[INFO] starting API listening on 0.0.0.0:%d", config.ListenPort)
err := router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
err = router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
if err != nil {
log.Fatalf("[Err] Error starting router: %s", err.Error())
}
+29 -9
View File
@@ -249,23 +249,39 @@ func (host *Node) RebuildInstance(instancetype InstanceType, vmid uint) error {
host.Instances[instanceID] = instance
for volid := range instance.configDisks {
instance.RebuildVolume(host, volid)
err = instance.RebuildVolume(host, volid)
if err != nil {
err_ch <- err
}
}
for netid := range instance.configNets {
instance.RebuildNet(host, netid)
err = instance.RebuildNet(host, netid)
if err != nil {
err_ch <- err
}
}
for deviceid := range instance.configHostPCIs {
instance.RebuildDevice(host, deviceid)
err = instance.RebuildDevice(host, deviceid)
if err != nil {
err_ch <- err
}
}
if instance.Type == VM {
instance.RebuildBoot(host)
err = instance.RebuildBoot(host)
if err != nil {
err_ch <- err
}
}
// after synchronizing an instance, resync pool membership
host.cluster.ResolvePoolMembership()
err = host.cluster.ResolvePoolMembership()
if err != nil {
err_ch <- err
}
err_ch <- nil
}()
@@ -302,11 +318,11 @@ func (instance *Instance) RebuildNet(host *Node, netid string) error {
return nil
}
func (instance *Instance) RebuildDevice(host *Node, deviceid string) {
func (instance *Instance) RebuildDevice(host *Node, deviceid string) error {
instanceDevice, ok := instance.configHostPCIs[deviceid]
if !ok { // if device does not exist
log.Printf("[WARN] %s not found in devices", deviceid)
return
log.Printf("[WARN] %s not found in devices on node %s", deviceid, host.Name)
return nil
}
hostDeviceBusID := DeviceID(strings.Split(instanceDevice, ",")[0])
@@ -322,9 +338,11 @@ func (instance *Instance) RebuildDevice(host *Node, deviceid string) {
}
instance.Devices[DeviceID(instanceDeviceBusID)].Device_ID = DeviceID(deviceid)
return nil
}
func (instance *Instance) RebuildBoot(host *Node) {
func (instance *Instance) RebuildBoot(host *Node) error {
instance.Boot = BootOrder{}
eligibleBoot := map[string]bool{}
@@ -365,4 +383,6 @@ func (instance *Instance) RebuildBoot(host *Node) {
log.Printf("[WARN] encountered disabled and non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
}
}
return nil
}