fix(host): SetDirtyContainer when updating container status error (#21901)

This commit is contained in:
Zexi Li
2024-12-26 14:14:57 +08:00
committed by GitHub
parent 41b8579fc5
commit 56efaed760
3 changed files with 27 additions and 9 deletions
@@ -31,6 +31,7 @@ limitations under the License.
package prober
import (
"fmt"
"sync"
"yunion.io/x/log"
@@ -85,7 +86,7 @@ type Manager interface {
// Start starts the Manager sync loops.
Start()
SetDirtyContainer(ctrId string)
SetDirtyContainer(ctrId string, reason string)
}
type manager struct {
@@ -128,7 +129,8 @@ func NewManager(
}
}
func (m *manager) SetDirtyContainer(ctrId string) {
func (m *manager) SetDirtyContainer(ctrId string, reason string) {
log.Infof("[set dirty container] %s: %s", ctrId, reason)
m.dirtyContainers.Store(ctrId, true)
}
@@ -235,11 +237,14 @@ func (m *manager) updateStartup() {
update := <-m.startupManager.Updates()
started := update.Result.Result == results.Success
m.statusManager.SetContainerStartup(
if err := m.statusManager.SetContainerStartup(
update.PodUID,
update.ContainerID,
started,
update.Result,
update.Pod,
)
); err != nil {
reason := fmt.Sprintf("set container %s/%s startup error: %v", update.PodUID, update.ContainerID, err)
m.SetDirtyContainer(update.ContainerID, reason)
}
}
+16 -3
View File
@@ -16,9 +16,11 @@ package status
import (
"context"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/apis"
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
@@ -29,7 +31,7 @@ import (
type Manager interface {
// SetContainerStartup updates the container status with the given startup
// and triggers a status update.
SetContainerStartup(podId string, containerId string, started bool, result results.ProbeResult, pod results.IPod)
SetContainerStartup(podId string, containerId string, started bool, result results.ProbeResult, pod results.IPod) error
}
type manager struct{}
@@ -38,7 +40,7 @@ func NewManager() Manager {
return &manager{}
}
func (m *manager) SetContainerStartup(podId string, containerId string, started bool, result results.ProbeResult, pod results.IPod) {
func (m *manager) SetContainerStartup(podId string, containerId string, started bool, result results.ProbeResult, pod results.IPod) error {
status := computeapi.CONTAINER_STATUS_PROBE_FAILED
if started {
status = computeapi.CONTAINER_STATUS_RUNNING
@@ -54,8 +56,19 @@ func (m *manager) SetContainerStartup(podId string, containerId string, started
},
}
if _, err := hostutils.UpdateContainerStatus(context.Background(), containerId, input); err != nil {
log.Errorf("set container(%s/%s) status failed: %s", podId, containerId, err)
err = errors.Wrapf(err, "set container(%s/%s) status failed, input: %s", podId, containerId, jsonutils.Marshal(input))
log.Warningf(err.Error())
errMsg := []string{
"service is abnormal",
"connection refused",
}
for _, msg := range errMsg {
if strings.Contains(err.Error(), msg) {
return errors.Wrap(err, "update container status")
}
}
} else {
log.Infof("set container(%s/%s) status to %s", podId, containerId, jsonutils.Marshal(input).String())
}
return nil
}
+2 -2
View File
@@ -1930,8 +1930,8 @@ func (s *sPodGuestInstance) getContainerStatus(ctx context.Context, ctrId string
func (s *sPodGuestInstance) markContainerProbeDirty(status, ctrId string, reason string) {
if status == computeapi.CONTAINER_STATUS_PROBING {
log.Infof("mark container %s to dirty: %s", ctrId, reason)
s.getProbeManager().SetDirtyContainer(ctrId)
reason = fmt.Sprintf("status is probing: %s", reason)
s.getProbeManager().SetDirtyContainer(ctrId, reason)
}
}