Fixed a race condition that can cause agent panici
package image
import (
+ "encoding/json"
"fmt"
"sync"
"time"
@@ -98,3 +99,18 @@ func (imageState *ImageState) RemoveContainerReference(container *api.Container)
}
return fmt.Errorf("Container reference is not found in the image state container: %s", container.String())
}
+
+func (imageState *ImageState) MarshalJSON() ([]byte, error) {
+ imageState.updateLock.Lock()
+ defer imageState.updateLock.Unlock()
+
+ return json.Marshal(&struct {
+ Image *Image
+ PulledAt time.Time
+ LastUsedAt time.Time
+ }{
+ Image: imageState.Image,
+ PulledAt: imageState.PulledAt,
+ LastUsedAt: imageState.LastUsedAt,
+ })
+}
