Change "failed to stop sandbox" error message to use state name instead of numeric value
Signed-off-by: Brian Pursley <bpursley@cinlogic.com>
This commit is contained in:
parent
682d158399
commit
aa04fc9d53
@ -17,8 +17,11 @@
|
|||||||
package sandbox
|
package sandbox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The sandbox state machine in the CRI plugin:
|
// The sandbox state machine in the CRI plugin:
|
||||||
@ -63,7 +66,7 @@ type State uint32
|
|||||||
const (
|
const (
|
||||||
// StateReady is ready state, it means sandbox container
|
// StateReady is ready state, it means sandbox container
|
||||||
// is running.
|
// is running.
|
||||||
StateReady = iota
|
StateReady State = iota
|
||||||
// StateNotReady is notready state, it ONLY means sandbox
|
// StateNotReady is notready state, it ONLY means sandbox
|
||||||
// container is not running.
|
// container is not running.
|
||||||
// StopPodSandbox should still be called for NOTREADY sandbox to
|
// StopPodSandbox should still be called for NOTREADY sandbox to
|
||||||
@ -75,6 +78,21 @@ const (
|
|||||||
StateUnknown
|
StateUnknown
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// String returns the string representation of the state
|
||||||
|
func (s State) String() string {
|
||||||
|
switch s {
|
||||||
|
case StateReady:
|
||||||
|
return runtime.PodSandboxState_SANDBOX_READY.String()
|
||||||
|
case StateNotReady:
|
||||||
|
return runtime.PodSandboxState_SANDBOX_NOTREADY.String()
|
||||||
|
case StateUnknown:
|
||||||
|
// PodSandboxState doesn't have an unknown state, but State does, so return a string using the same convention
|
||||||
|
return "SANDBOX_UNKNOWN"
|
||||||
|
default:
|
||||||
|
return "invalid sandbox state value: " + strconv.Itoa(int(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Status is the status of a sandbox.
|
// Status is the status of a sandbox.
|
||||||
type Status struct {
|
type Status struct {
|
||||||
// Pid is the init process id of the sandbox container.
|
// Pid is the init process id of the sandbox container.
|
||||||
|
@ -18,6 +18,7 @@ package sandbox
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -59,3 +60,11 @@ func TestStatus(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(updateStatus, s.Get())
|
assert.Equal(updateStatus, s.Get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStateStringConversion(t *testing.T) {
|
||||||
|
assert := assertlib.New(t)
|
||||||
|
assert.Equal("SANDBOX_READY", fmt.Sprintf("%s", StateReady))
|
||||||
|
assert.Equal("SANDBOX_NOTREADY", fmt.Sprintf("%s", StateNotReady))
|
||||||
|
assert.Equal("SANDBOX_UNKNOWN", fmt.Sprintf("%s", StateUnknown))
|
||||||
|
assert.Equal("invalid sandbox state value: 123", fmt.Sprintf("%s", State(123)))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user