MCPcopy Create free account
hub / github.com/containerd/nerdctl / onPostStop

Function onPostStop

pkg/ocihook/ocihook.go:663–768  ·  view source on GitHub ↗
(opts *handlerOpts)

Source from the content-addressed store, hash-verified

661}
662
663func onPostStop(opts *handlerOpts) error {
664 lf, err := state.New(opts.state.Annotations[labels.StateDir])
665 if err != nil {
666 return err
667 }
668
669 var shouldExit bool
670 err = lf.Transform(func(lf *state.Store) error {
671 // See https://github.com/containerd/nerdctl/issues/3357
672 // Check if we actually errored during runtimeCreate
673 // If that is the case, CreateError is set, and we are in postStop while the container will NOT be deleted (see ticket).
674 // Thus, do NOT treat this as a deletion, as the container is still there.
675 // Reset CreateError, and return.
676 shouldExit = lf.CreateError
677 lf.CreateError = false
678 return nil
679 })
680 if err != nil {
681 return err
682 }
683 if shouldExit {
684 return nil
685 }
686
687 ctx := context.Background()
688 ns := opts.state.Annotations[labels.Namespace]
689 if opts.cni != nil {
690 var err error
691 b4nnEnabled, b4nnBindEnabled, err := bypass4netnsutil.IsBypass4netnsEnabled(opts.state.Annotations)
692 if err != nil {
693 return err
694 }
695 if rootlessutil.IsRootlessChild() {
696 if b4nnEnabled {
697 bm, err := bypass4netnsutil.NewBypass4netnsCNIBypassManager(opts.bypassClient, opts.rootlessKitClient, opts.state.Annotations)
698 if err != nil {
699 return err
700 }
701 err = bm.StopBypass(ctx, opts.state.ID)
702 if err != nil {
703 return err
704 }
705 }
706 if !b4nnBindEnabled && len(opts.ports) > 0 {
707 if err := unexposePortsRootless(ctx, opts.rootlessKitClient, opts.ports); err != nil {
708 return fmt.Errorf("failed to unexpose ports in rootless mode: %w", err)
709 }
710 }
711 }
712 portMapOpts, err := getPortMapOpts(opts)
713 if err != nil {
714 return err
715 }
716 ipAddressOpts, err := getIPAddressOpts(opts)
717 if err != nil {
718 return err
719 }
720 macAddressOpts, err := getMACAddressOpts(opts)

Callers 1

RunFunction · 0.85

Calls 15

StopBypassMethod · 0.95
NewFunction · 0.92
IsBypass4netnsEnabledFunction · 0.92
IsRootlessChildFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
getPortMapOptsFunction · 0.85
getIPAddressOptsFunction · 0.85
getMACAddressOptsFunction · 0.85
getIP6AddressOptsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…