Fix issue of ExitCode and PID not show up in Task.Status.ContainerStatus
This fix tries to address the issue raised in 36139 where ExitCode and PID does not show up in Task.Status.ContainerStatus The issue was caused by `json:",omitempty"` in PID and ExitCode which interprate 0 as null. This is confusion as ExitCode 0 does have a meaning. This fix removes `json:",omitempty"` in ExitCode and PID, but changes ContainerStatus to pointer so that ContainerStatus does not show up at all if no content. If ContainerStatus does have a content, then ExitCode and PID will show up (even if they are 0). This fix fixes 36139. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
421664aba1
commit
9247e09944
|
@ -162,19 +162,19 @@ const (
|
||||||
|
|
||||||
// TaskStatus represents the status of a task.
|
// TaskStatus represents the status of a task.
|
||||||
type TaskStatus struct {
|
type TaskStatus struct {
|
||||||
Timestamp time.Time `json:",omitempty"`
|
Timestamp time.Time `json:",omitempty"`
|
||||||
State TaskState `json:",omitempty"`
|
State TaskState `json:",omitempty"`
|
||||||
Message string `json:",omitempty"`
|
Message string `json:",omitempty"`
|
||||||
Err string `json:",omitempty"`
|
Err string `json:",omitempty"`
|
||||||
ContainerStatus ContainerStatus `json:",omitempty"`
|
ContainerStatus *ContainerStatus `json:",omitempty"`
|
||||||
PortStatus PortStatus `json:",omitempty"`
|
PortStatus PortStatus `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatus represents the status of a container.
|
// ContainerStatus represents the status of a container.
|
||||||
type ContainerStatus struct {
|
type ContainerStatus struct {
|
||||||
ContainerID string `json:",omitempty"`
|
ContainerID string
|
||||||
PID int `json:",omitempty"`
|
PID int
|
||||||
ExitCode int `json:",omitempty"`
|
ExitCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
// PortStatus represents the port status of a task's host ports whose
|
// PortStatus represents the port status of a task's host ports whose
|
||||||
|
|
|
@ -42,9 +42,11 @@ func TaskFromGRPC(t swarmapi.Task) (types.Task, error) {
|
||||||
task.Status.Timestamp, _ = gogotypes.TimestampFromProto(t.Status.Timestamp)
|
task.Status.Timestamp, _ = gogotypes.TimestampFromProto(t.Status.Timestamp)
|
||||||
|
|
||||||
if containerStatus != nil {
|
if containerStatus != nil {
|
||||||
task.Status.ContainerStatus.ContainerID = containerStatus.ContainerID
|
task.Status.ContainerStatus = &types.ContainerStatus{
|
||||||
task.Status.ContainerStatus.PID = int(containerStatus.PID)
|
ContainerID: containerStatus.ContainerID,
|
||||||
task.Status.ContainerStatus.ExitCode = int(containerStatus.ExitCode)
|
PID: int(containerStatus.PID),
|
||||||
|
ExitCode: int(containerStatus.ExitCode),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworksAttachments
|
// NetworksAttachments
|
||||||
|
|
|
@ -29,10 +29,10 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) {
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
// check container mount config
|
// check container mount config
|
||||||
|
@ -143,10 +143,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
for testName, testTarget := range testPaths {
|
for testName, testTarget := range testPaths {
|
||||||
|
@ -193,10 +193,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
for _, target := range []string{"target1", "target2"} {
|
for _, target := range []string{"target1", "target2"} {
|
||||||
|
@ -290,10 +290,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
for testName, testTarget := range testPaths {
|
for testName, testTarget := range testPaths {
|
||||||
|
@ -340,10 +340,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
for _, target := range []string{"target1", "target2"} {
|
for _, target := range []string{"target1", "target2"} {
|
||||||
|
@ -372,10 +372,10 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
// check container mount config
|
// check container mount config
|
||||||
|
@ -428,10 +428,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
|
||||||
|
|
||||||
task := tasks[0]
|
task := tasks[0]
|
||||||
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
||||||
if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
||||||
task = d.GetTask(c, task.ID)
|
task = d.GetTask(c, task.ID)
|
||||||
}
|
}
|
||||||
return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil
|
return task.NodeID != "" && task.Status.ContainerStatus != nil, nil
|
||||||
}, checker.Equals, true)
|
}, checker.Equals, true)
|
||||||
|
|
||||||
// check container alias config
|
// check container alias config
|
||||||
|
|
Loading…
Reference in New Issue