// Kill a process with the provided signal
Kill a process with the provided signal
// Kill a process with the provided signal
func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.Empty, err error) {
	start := time.Now()
	defer func() {
		err = toGRPC(err)
		rpcDurationsHistogram.WithLabelValues("kill").Observe(float64(time.Since(start).Nanoseconds() / int64(time.Millisecond)))
	}()
	s.mu.Lock()
	defer s.mu.Unlock()
	signum := syscall.Signal(r.Signal)
	c, err := s.getContainer(r.ID)
	if err != nil {
		return nil, err
	}
	if signum == syscall.SIGKILL || signum == syscall.SIGTERM {
		if c.status == task.StatusStopped {
			logrus.WithField("sandbox", s.sandbox.ID()).WithField("Container", c.id).Debug("Container has already been stopped")
			return empty, nil
		}
	}
	processID := c.id
	if r.ExecID != "" {
		execs, err := c.getExec(r.ExecID)
		if err != nil {
			return nil, err
		}
		processID = execs.id
		if processID == "" {
			logrus.WithFields(logrus.Fields{
				"sandbox":   s.sandbox.ID(),
				"Container": c.id,
				"ExecID":    r.ExecID,
			}).Debug("Id of exec process to be signalled is empty")
			return empty, errors.New("The exec process does not exist")
		}
	}
	return empty, s.sandbox.SignalProcess(c.id, processID, signum, r.All)
}
func ( s * service ) Kill ( ctx context . Context , r * taskAPI . KillRequest ) ( _ * ptypes . Empty , err error ) { start := time . Now ( ) defer func ( ) { err = toGRPC ( err ) rpcDurationsHistogram . WithLabelValues ( " " ) . Observe ( float64 ( time . Since ( start ) . Nanoseconds ( ) / int64 ( time . Millisecond ) ) ) } ( ) s . mu . Lock ( ) defer s . mu . Unlock ( ) signum := syscall . Signal ( r . Signal ) c , err := s . getContainer ( r . ID ) if err != nil { return nil , err } if signum == syscall . SIGKILL || signum == syscall . SIGTERM { if c . status == task . StatusStopped { logrus . WithField ( " " , s . sandbox . ID ( ) ) . WithField ( " " , c . id ) . Debug ( " " ) return empty , nil } } processID := c . id if r . ExecID != " " { execs , err := c . getExec ( r . ExecID ) if err != nil { return nil , err } processID = execs . id if processID == " " { logrus . WithFields ( logrus . Fields { " " : s . sandbox . ID ( ) , " " : c . id , " " : r . ExecID , } ) . Debug ( " " ) return empty , errors . New ( " " ) } } return empty , s . sandbox . SignalProcess ( c . id , processID , signum , r . All ) }
Kill a process with the provided signal
Kill a process with the provided signal
// According to CRI specs, kubelet will call StopPodSandbox() // at least once before calling RemovePodSandbox, and this call // is idempotent, and must not return an error if all relevant // resources have already been reclaimed. And in that call it will // send a SIGKILL signal first to try to stop the container, thus // once the container has terminated, here should ignore this signal // and return directly.