New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update containerd to b818e749726ba18e430bb825396c85408dfaf2a4 #27693
Merged
crosbymichael
merged 1 commit into
moby:1.12.x
from
mlaventure:update-containerd-fix-json-compat
Oct 24, 2016
Merged
Update containerd to b818e749726ba18e430bb825396c85408dfaf2a4 #27693
crosbymichael
merged 1 commit into
moby:1.12.x
from
mlaventure:update-containerd-fix-json-compat
Oct 24, 2016
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This add backward compatibility with the event logs format prior to 1.12.2. Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
relates to / fixes #27627 (comment) |
diff is docker-archive/containerd@0366d7e...b818e74 From 4b4773ffb5f61a9a49f6a9f6245d50fd02878eb7 Mon Sep 17 00:00:00 2001
From: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
Date: Mon, 24 Oct 2016 11:07:23 -0700
Subject: [PATCH] Update readEventLogs to support old Event format
Previously Status was stored as an `int` and could possibly be set to `-1`.
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
---
supervisor/supervisor.go | 16 +++++++++--
supervisor/supervisor_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 2 deletions(-)
create mode 100644 supervisor/supervisor_test.go
diff --git a/supervisor/supervisor.go b/supervisor/supervisor.go
index c1232f2..6e42f85 100644
--- a/supervisor/supervisor.go
+++ b/supervisor/supervisor.go
@@ -132,14 +132,21 @@ func readEventLog(s *Supervisor) error {
defer f.Close()
dec := json.NewDecoder(f)
for {
- var e Event
+ var e eventV1
if err := dec.Decode(&e); err != nil {
if err == io.EOF {
break
}
return err
}
- s.eventLog = append(s.eventLog, e)
+
+ // We need to take care of -1 Status for backward compatibility
+ ev := e.Event
+ ev.Status = uint32(e.Status)
+ if ev.Status > runtime.UnknownStatus {
+ ev.Status = runtime.UnknownStatus
+ }
+ s.eventLog = append(s.eventLog, ev)
}
return nil
}
@@ -189,6 +196,11 @@ type Event struct {
Status uint32 `json:"status,omitempty"`
}
+type eventV1 struct {
+ Event
+ Status int `json:"status,omitempty"`
+}
+
// Events returns an event channel that external consumers can use to receive updates
// on container events
func (s *Supervisor) Events(from time.Time, storedOnly bool, id string) chan Event {
diff --git a/supervisor/supervisor_test.go b/supervisor/supervisor_test.go
new file mode 100644
index 0000000..f30ed13
--- /dev/null
+++ b/supervisor/supervisor_test.go
@@ -0,0 +1,65 @@
+package supervisor
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+
+ "github.com/docker/containerd/runtime"
+)
+
+func TestEventLogCompat(t *testing.T) {
+ tmpDir, err := ioutil.TempDir("", "")
+ if err != nil {
+ t.Errorf("Failed to create temp dir: %v", err)
+ }
+
+ path := filepath.Join(tmpDir, "events.log")
+ eventf, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_TRUNC, 0755)
+ if err != nil {
+ t.Errorf("Failed to create event logs: %v", err)
+ }
+
+ s := &Supervisor{stateDir: tmpDir}
+
+ enc := json.NewEncoder(eventf)
+ for _, ev := range []eventV1{
+ {
+ Event: Event{
+ ID: "abc",
+ Type: "event",
+ Timestamp: time.Now(),
+ PID: "42",
+ },
+ Status: -1,
+ },
+ {
+ Event: Event{
+ ID: "abc",
+ Type: "event",
+ Timestamp: time.Now(),
+ PID: "42",
+ },
+ Status: 42,
+ },
+ } {
+ enc.Encode(ev)
+ }
+ eventf.Close()
+
+ err = readEventLog(s)
+ if err != nil {
+ t.Errorf("Failed to read event logs: %v", err)
+ }
+
+ if s.eventLog[0].Status != runtime.UnknownStatus {
+ t.Errorf("Improper event status: %v", s.eventLog[0].Status)
+ }
+
+ if s.eventLog[1].Status != 42 {
+ t.Errorf("Improper event status: %v", s.eventLog[1].Status)
+ }
+} |
@thaJeztah only on 1.12.3 Doing the update for master now. |
LGTM |
1 similar comment
LGTM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This add backward compatibility with the event logs format prior to 1.12.2.
Signed-off-by: Kenfe-Mickael Laventure mickael.laventure@gmail.com
ping @tonistiigi @vieux @thaJeztah