Skip to content
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

Conversation

mlaventure
Copy link
Contributor

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

This add backward compatibility with the event logs format prior to
1.12.2.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
@thaJeztah thaJeztah added this to the 1.12.3 milestone Oct 24, 2016
@thaJeztah
Copy link
Member

relates to / fixes #27627 (comment)

@thaJeztah
Copy link
Member

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)
+   }
+}

@mlaventure
Copy link
Contributor Author

@thaJeztah only on 1.12.3

Doing the update for master now.

@tonistiigi
Copy link
Member

LGTM

1 similar comment
@vieux
Copy link
Contributor

vieux commented Oct 24, 2016

LGTM

@crosbymichael crosbymichael merged commit ca151de into moby:1.12.x Oct 24, 2016
@mlaventure mlaventure deleted the update-containerd-fix-json-compat branch October 24, 2016 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants