diff --git a/cmd/metal-api/internal/datastore/switch.go b/cmd/metal-api/internal/datastore/switch.go index 24cabac2e..d5982c19c 100644 --- a/cmd/metal-api/internal/datastore/switch.go +++ b/cmd/metal-api/internal/datastore/switch.go @@ -201,7 +201,7 @@ func (rs *RethinkStore) ConnectMachineWithSwitches(m *metal.Machine) error { func (rs *RethinkStore) GetSwitchStatus(id string) (*metal.SwitchStatus, error) { var ss metal.SwitchStatus err := rs.findEntityByID(rs.switchStatusTable(), &ss, id) - if err != nil && !metal.IsNotFound(err) { + if err != nil { return nil, err } return &ss, nil diff --git a/cmd/metal-api/internal/service/switch-service.go b/cmd/metal-api/internal/service/switch-service.go index 0f1d4cd2c..d0a392bfb 100644 --- a/cmd/metal-api/internal/service/switch-service.go +++ b/cmd/metal-api/internal/service/switch-service.go @@ -223,25 +223,28 @@ func (r *switchResource) notifySwitch(request *restful.Request, response *restfu } } - sync := &metal.SwitchSync{ - Time: time.Now(), - Duration: requestPayload.Duration, - } + newSS := *ss if requestPayload.Error == nil { - ss.LastSync = sync + newSS.LastSync = &metal.SwitchSync{ + Time: time.Now(), + Duration: requestPayload.Duration, + } } else { - ss.LastSyncError = sync - ss.LastSyncError.Error = requestPayload.Error + newSS.LastSyncError = &metal.SwitchSync{ + Time: time.Now(), + Duration: requestPayload.Duration, + Error: requestPayload.Error, + } } - err = r.ds.SetSwitchStatus(ss) + err = r.ds.SetSwitchStatus(&newSS) if err != nil { r.sendError(request, response, defaultError(err)) return } - r.send(request, response, http.StatusOK, v1.NewSwitchNotifyResponse(ss)) + r.send(request, response, http.StatusOK, v1.NewSwitchNotifyResponse(&newSS)) } func (r *switchResource) updateSwitch(request *restful.Request, response *restful.Response) {