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>
| ... | ... |
@@ -162,19 +162,19 @@ const ( |
| 162 | 162 |
|
| 163 | 163 |
// TaskStatus represents the status of a task. |
| 164 | 164 |
type TaskStatus struct {
|
| 165 |
- Timestamp time.Time `json:",omitempty"` |
|
| 166 |
- State TaskState `json:",omitempty"` |
|
| 167 |
- Message string `json:",omitempty"` |
|
| 168 |
- Err string `json:",omitempty"` |
|
| 169 |
- ContainerStatus ContainerStatus `json:",omitempty"` |
|
| 170 |
- PortStatus PortStatus `json:",omitempty"` |
|
| 165 |
+ Timestamp time.Time `json:",omitempty"` |
|
| 166 |
+ State TaskState `json:",omitempty"` |
|
| 167 |
+ Message string `json:",omitempty"` |
|
| 168 |
+ Err string `json:",omitempty"` |
|
| 169 |
+ ContainerStatus *ContainerStatus `json:",omitempty"` |
|
| 170 |
+ PortStatus PortStatus `json:",omitempty"` |
|
| 171 | 171 |
} |
| 172 | 172 |
|
| 173 | 173 |
// ContainerStatus represents the status of a container. |
| 174 | 174 |
type ContainerStatus struct {
|
| 175 |
- ContainerID string `json:",omitempty"` |
|
| 176 |
- PID int `json:",omitempty"` |
|
| 177 |
- ExitCode int `json:",omitempty"` |
|
| 175 |
+ ContainerID string |
|
| 176 |
+ PID int |
|
| 177 |
+ ExitCode int |
|
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
// PortStatus represents the port status of a task's host ports whose |
| ... | ... |
@@ -42,9 +42,11 @@ func TaskFromGRPC(t swarmapi.Task) (types.Task, error) {
|
| 42 | 42 |
task.Status.Timestamp, _ = gogotypes.TimestampFromProto(t.Status.Timestamp) |
| 43 | 43 |
|
| 44 | 44 |
if containerStatus != nil {
|
| 45 |
- task.Status.ContainerStatus.ContainerID = containerStatus.ContainerID |
|
| 46 |
- task.Status.ContainerStatus.PID = int(containerStatus.PID) |
|
| 47 |
- task.Status.ContainerStatus.ExitCode = int(containerStatus.ExitCode) |
|
| 45 |
+ task.Status.ContainerStatus = &types.ContainerStatus{
|
|
| 46 |
+ ContainerID: containerStatus.ContainerID, |
|
| 47 |
+ PID: int(containerStatus.PID), |
|
| 48 |
+ ExitCode: int(containerStatus.ExitCode), |
|
| 49 |
+ } |
|
| 48 | 50 |
} |
| 49 | 51 |
|
| 50 | 52 |
// NetworksAttachments |
| ... | ... |
@@ -29,10 +29,10 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) {
|
| 29 | 29 |
|
| 30 | 30 |
task := tasks[0] |
| 31 | 31 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 32 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 32 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 33 | 33 |
task = d.GetTask(c, task.ID) |
| 34 | 34 |
} |
| 35 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 35 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 36 | 36 |
}, checker.Equals, true) |
| 37 | 37 |
|
| 38 | 38 |
// check container mount config |
| ... | ... |
@@ -143,10 +143,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check |
| 143 | 143 |
|
| 144 | 144 |
task := tasks[0] |
| 145 | 145 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 146 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 146 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 147 | 147 |
task = d.GetTask(c, task.ID) |
| 148 | 148 |
} |
| 149 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 149 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 150 | 150 |
}, checker.Equals, true) |
| 151 | 151 |
|
| 152 | 152 |
for testName, testTarget := range testPaths {
|
| ... | ... |
@@ -193,10 +193,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C |
| 193 | 193 |
|
| 194 | 194 |
task := tasks[0] |
| 195 | 195 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 196 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 196 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 197 | 197 |
task = d.GetTask(c, task.ID) |
| 198 | 198 |
} |
| 199 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 199 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 200 | 200 |
}, checker.Equals, true) |
| 201 | 201 |
|
| 202 | 202 |
for _, target := range []string{"target1", "target2"} {
|
| ... | ... |
@@ -290,10 +290,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check |
| 290 | 290 |
|
| 291 | 291 |
task := tasks[0] |
| 292 | 292 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 293 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 293 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 294 | 294 |
task = d.GetTask(c, task.ID) |
| 295 | 295 |
} |
| 296 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 296 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 297 | 297 |
}, checker.Equals, true) |
| 298 | 298 |
|
| 299 | 299 |
for testName, testTarget := range testPaths {
|
| ... | ... |
@@ -340,10 +340,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C |
| 340 | 340 |
|
| 341 | 341 |
task := tasks[0] |
| 342 | 342 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 343 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 343 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 344 | 344 |
task = d.GetTask(c, task.ID) |
| 345 | 345 |
} |
| 346 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 346 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 347 | 347 |
}, checker.Equals, true) |
| 348 | 348 |
|
| 349 | 349 |
for _, target := range []string{"target1", "target2"} {
|
| ... | ... |
@@ -372,10 +372,10 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
|
| 372 | 372 |
|
| 373 | 373 |
task := tasks[0] |
| 374 | 374 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 375 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 375 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 376 | 376 |
task = d.GetTask(c, task.ID) |
| 377 | 377 |
} |
| 378 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 378 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 379 | 379 |
}, checker.Equals, true) |
| 380 | 380 |
|
| 381 | 381 |
// check container mount config |
| ... | ... |
@@ -428,10 +428,10 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
|
| 428 | 428 |
|
| 429 | 429 |
task := tasks[0] |
| 430 | 430 |
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
| 431 |
- if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" {
|
|
| 431 |
+ if task.NodeID == "" || task.Status.ContainerStatus == nil {
|
|
| 432 | 432 |
task = d.GetTask(c, task.ID) |
| 433 | 433 |
} |
| 434 |
- return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil |
|
| 434 |
+ return task.NodeID != "" && task.Status.ContainerStatus != nil, nil |
|
| 435 | 435 |
}, checker.Equals, true) |
| 436 | 436 |
|
| 437 | 437 |
// check container alias config |