Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/lib/sandbox/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ func infraPid(infra *oci.Container) int {
if infra != nil {
var err error
pid, err = infra.Pid()
if err != nil {
// There are some cases where ErrNotInitialized is expected.
// For instance, when we're creating a pod sandbox while managing namespace lifecycle,
// we create the network stack before we create the infra container.
// Since we're pinning namespaces, we already have the namespace we need.
// Later users of this pid will either find we have a valid pinned namespace (which we will in this case),
// or find we have an invalid /proc entry (a negative pid).
// Thus, we don't need to error here if the pid is not initialized
if err != nil && err != oci.ErrNotInitialized {
logrus.Errorf("pid for infra container %s not found: %v", infra.ID(), err)
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/oci/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
defaultStopSignal = strconv.Itoa(defaultStopSignalInt)
ErrContainerStopped = errors.New("container is already stopped")
ErrNotFound = errors.New("container process not found")
ErrNotInitialized = errors.New("container PID not initialized")
)

// Container represents a runtime container.
Expand Down Expand Up @@ -413,10 +414,10 @@ func (c *Container) Pid() (int, error) {
// and it is the same process that was originally started by the runtime.
func (c *Container) pid() (int, error) {
if c.state == nil {
return 0, errors.New("state not initialized")
return 0, ErrNotInitialized
}
if c.state.InitPid <= 0 {
return 0, errors.New("PID not initialized")
return 0, ErrNotInitialized
}

// container has stopped (as pid is initialized but the runc state has overwritten it)
Expand Down