From c2840dd6228f15547dcd5334c768875a3134c785 Mon Sep 17 00:00:00 2001 From: Kevin Parsons Date: Fri, 28 May 2021 15:45:08 -0700 Subject: [PATCH 1/3] shim: Clean up delete invocation behavior This changes the behavior when the shim is invoked with the "delete" command line argument. Previously, the delete path did two things it should not: - Attempted to locate the sandbox container for the pod and delete it as well. This meant if "shim delete" was invoked for a workload container, it could bring down the whole pod. The only reason we did not see this in the past is that prior to containerd 1.5 "shim delete" was not called for successful container stop operations. - Deleted the bundle directory. We shouldn't do this in the shim, as containerd does it itself. For reference on what the Linux shim does, see here: https://github.com/containerd/containerd/blob/master/runtime/v2/runc/v2/service.go#L291 Signed-off-by: Kevin Parsons (cherry picked from commit 450cdb150a74aa594d7fe63bb0b3a2a37f5dd782) Signed-off-by: Kevin Parsons --- cmd/containerd-shim-runhcs-v1/delete.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/cmd/containerd-shim-runhcs-v1/delete.go b/cmd/containerd-shim-runhcs-v1/delete.go index ec673c4bec..0beaf8a506 100644 --- a/cmd/containerd-shim-runhcs-v1/delete.go +++ b/cmd/containerd-shim-runhcs-v1/delete.go @@ -71,31 +71,6 @@ The delete command will be executed in the container's bundle as its cwd. } } - // Determine if the config file was a POD and if so kill the whole POD. - if s, err := getSpecAnnotations(bundleFlag); err != nil { - if !os.IsNotExist(err) { - return err - } - } else { - if containerType := s["io.kubernetes.cri.container-type"]; containerType == "container" { - if sandboxID := s["io.kubernetes.cri.sandbox-id"]; sandboxID != "" { - if sys, _ := hcs.OpenComputeSystem(ctx, sandboxID); sys != nil { - if err := sys.Terminate(ctx); err != nil { - fmt.Fprintf(os.Stderr, "failed to terminate '%s': %v", idFlag, err) - } else if err := sys.Wait(); err != nil { - fmt.Fprintf(os.Stderr, "failed to wait for '%s' to terminate: %v", idFlag, err) - } - sys.Close() - } - } - } - } - - // Remove the bundle on disk - if err := os.RemoveAll(bundleFlag); err != nil && !os.IsNotExist(err) { - return err - } - if data, err := proto.Marshal(&task.DeleteResponse{ ExitedAt: time.Now(), ExitStatus: 255, From a09d65b8923bb4183e3c6ca18d06b0a6ab57b1a2 Mon Sep 17 00:00:00 2001 From: Kevin Parsons Date: Wed, 7 Jul 2021 15:16:49 -0700 Subject: [PATCH 2/3] Remove ERROR_PROC_NOT_FOUND from error checks Previously, certain error check functions like IsAlreadyStopped returned true if the error was ERROR_PROC_NOT_FOUND. Based on the comment in the file, this was intended to be used to indicate a case where the process could not be found. However, it seems this may have been added erroneously. ERROR_PROC_NOT_FOUND is actually typically used to mean that a _procedure_ lookup failed, and has nothing to do with processes. The original change[1] to check against ERROR_PROC_NOT_FOUND was made five years ago, and did not contain much information on why this error would be returned. We are removing this now based on several factors: - We are not aware of any condition where HCS would intentionally return ERROR_PROC_NOT_FOUND to indicate a condition "process does not exist". - There is an issue where HcsShutdownComputeSystem sometimes returns ERROR_PROC_NOT_FOUND due to something failing internally. The current error checks are causing this to be treated as "the container has already exited", causing moby to not properly stop the container via HcsTerminateComputeSystem. This change leaves the definition for ErrProcNotFound in the code, as it may be used by external callers, but fixes its comment. [1]: See commit 0ae7e7ecebd7b5609582153ed680c35ba666a264 Signed-off-by: Kevin Parsons (cherry picked from commit d78544d6c2c2cbfde54155662138bf275cab7fca) Signed-off-by: Kevin Parsons --- errors.go | 6 +++--- internal/hcs/errors.go | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/errors.go b/errors.go index 7943086733..f367022e71 100644 --- a/errors.go +++ b/errors.go @@ -59,7 +59,7 @@ var ( // ErrVmcomputeOperationInvalidState is an error encountered when the compute system is not in a valid state for the requested operation ErrVmcomputeOperationInvalidState = hcs.ErrVmcomputeOperationInvalidState - // ErrProcNotFound is an error encountered when the the process cannot be found + // ErrProcNotFound is an error encountered when a procedure look up fails. ErrProcNotFound = hcs.ErrProcNotFound // ErrVmcomputeOperationAccessIsDenied is an error which can be encountered when enumerating compute systems in RS1/RS2 @@ -159,7 +159,7 @@ func (e *ProcessError) Error() string { // IsNotExist checks if an error is caused by the Container or Process not existing. // Note: Currently, ErrElementNotFound can mean that a Process has either // already exited, or does not exist. Both IsAlreadyStopped and IsNotExist -// will currently return true when the error is ErrElementNotFound or ErrProcNotFound. +// will currently return true when the error is ErrElementNotFound. func IsNotExist(err error) bool { if _, ok := err.(EndpointNotFoundError); ok { return true @@ -192,7 +192,7 @@ func IsTimeout(err error) bool { // a Container or Process being already stopped. // Note: Currently, ErrElementNotFound can mean that a Process has either // already exited, or does not exist. Both IsAlreadyStopped and IsNotExist -// will currently return true when the error is ErrElementNotFound or ErrProcNotFound. +// will currently return true when the error is ErrElementNotFound. func IsAlreadyStopped(err error) bool { return hcs.IsAlreadyStopped(getInnerError(err)) } diff --git a/internal/hcs/errors.go b/internal/hcs/errors.go index 7696e4b481..644f0ab711 100644 --- a/internal/hcs/errors.go +++ b/internal/hcs/errors.go @@ -60,7 +60,7 @@ var ( // ErrVmcomputeOperationInvalidState is an error encountered when the compute system is not in a valid state for the requested operation ErrVmcomputeOperationInvalidState = syscall.Errno(0xc0370105) - // ErrProcNotFound is an error encountered when the the process cannot be found + // ErrProcNotFound is an error encountered when a procedure look up fails. ErrProcNotFound = syscall.Errno(0x7f) // ErrVmcomputeOperationAccessIsDenied is an error which can be encountered when enumerating compute systems in RS1/RS2 @@ -242,12 +242,11 @@ func makeProcessError(process *Process, op string, err error, events []ErrorEven // IsNotExist checks if an error is caused by the Container or Process not existing. // Note: Currently, ErrElementNotFound can mean that a Process has either // already exited, or does not exist. Both IsAlreadyStopped and IsNotExist -// will currently return true when the error is ErrElementNotFound or ErrProcNotFound. +// will currently return true when the error is ErrElementNotFound. func IsNotExist(err error) bool { err = getInnerError(err) return err == ErrComputeSystemDoesNotExist || - err == ErrElementNotFound || - err == ErrProcNotFound + err == ErrElementNotFound } // IsAlreadyClosed checks if an error is caused by the Container or Process having been @@ -278,12 +277,11 @@ func IsTimeout(err error) bool { // a Container or Process being already stopped. // Note: Currently, ErrElementNotFound can mean that a Process has either // already exited, or does not exist. Both IsAlreadyStopped and IsNotExist -// will currently return true when the error is ErrElementNotFound or ErrProcNotFound. +// will currently return true when the error is ErrElementNotFound. func IsAlreadyStopped(err error) bool { err = getInnerError(err) return err == ErrVmcomputeAlreadyStopped || - err == ErrElementNotFound || - err == ErrProcNotFound + err == ErrElementNotFound } // IsNotSupported returns a boolean indicating whether the error is caused by From 27e98d33ea2e1e813d751942f4011b859525d4d2 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Thu, 15 Apr 2021 14:28:19 -0700 Subject: [PATCH 3/3] WS 2004 supports dual stack