mirror of https://github.com/containers/podman.git
prune exit codes only when container doesn't exist
Make sure to prune container exit codes only when the associated container does not exist anymore. This is needed when checking if any container in kube-play exited non-zero and a building block for the below linked Jira card. [NO NEW TESTS NEEDED] - there are no unit tests for exit code pruning. Jira: https://issues.redhat.com/browse/RUN-1776 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
parent
688e6dbef1
commit
6dbc138339
|
|
@ -1451,7 +1451,8 @@ func (s *BoltState) GetContainerExitCodeTimeStamp(id string) (*time.Time, error)
|
|||
})
|
||||
}
|
||||
|
||||
// PruneExitCodes removes exit codes older than 5 minutes.
|
||||
// PruneExitCodes removes exit codes older than 5 minutes unless the associated
|
||||
// container still exists.
|
||||
func (s *BoltState) PruneContainerExitCodes() error {
|
||||
if !s.valid {
|
||||
return define.ErrDBClosed
|
||||
|
|
@ -1472,7 +1473,17 @@ func (s *BoltState) PruneContainerExitCodes() error {
|
|||
return err
|
||||
}
|
||||
|
||||
ctrsBucket, err := getCtrBucket(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return timeStampBucket.ForEach(func(rawID, rawTimeStamp []byte) error {
|
||||
if ctrsBucket.Bucket(rawID) != nil {
|
||||
// If the container still exists, don't prune
|
||||
// its exit code since we may still need it.
|
||||
return nil
|
||||
}
|
||||
var timeStamp time.Time
|
||||
if err := timeStamp.UnmarshalText(rawTimeStamp); err != nil {
|
||||
return fmt.Errorf("converting raw time stamp %v of container %s from DB: %w", rawTimeStamp, string(rawID), err)
|
||||
|
|
|
|||
|
|
@ -943,7 +943,8 @@ func (s *SQLiteState) GetContainerExitCodeTimeStamp(id string) (*time.Time, erro
|
|||
return &result, nil
|
||||
}
|
||||
|
||||
// PruneExitCodes removes exit codes older than 5 minutes.
|
||||
// PruneExitCodes removes exit codes older than 5 minutes unless the associated
|
||||
// container still exists.
|
||||
func (s *SQLiteState) PruneContainerExitCodes() (defErr error) {
|
||||
if !s.valid {
|
||||
return define.ErrDBClosed
|
||||
|
|
@ -963,7 +964,7 @@ func (s *SQLiteState) PruneContainerExitCodes() (defErr error) {
|
|||
}
|
||||
}()
|
||||
|
||||
if _, err := tx.Exec("DELETE FROM ContainerExitCode WHERE (Timestamp <= ?);", fiveMinsAgo); err != nil {
|
||||
if _, err := tx.Exec("DELETE FROM ContainerExitCode WHERE (Timestamp <= ?) AND (ID NOT IN (SELECT ID FROM ContainerConfig))", fiveMinsAgo); err != nil {
|
||||
return fmt.Errorf("removing exit codes with timestamps older than 5 minutes: %w", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue