func CleanUpNamespace(args *skel.CmdArgs, logger *log.Entry) error {
	// Only try to delete the device if a namespace was passed in.
	if args.Netns != "" {
		logger.Debug("Checking namespace & device exist.")
		devErr := ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
			_, err := netlink.LinkByName(args.IfName)
			return err
		})

		if devErr == nil {
			fmt.Fprintf(os.Stderr, "Calico CNI deleting device in netns %s\n", args.Netns)
			err := ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
				_, err := ip.DelLinkByNameAddr(args.IfName, netlink.FAMILY_V4)
				return err
			})

			if err != nil {
				return err
			}
		} else {
			logger.Info("veth does not exist, no need to clean up.")
		}
	}

	return nil
}
// CleanUpNamespace deletes the devices in the network namespace.
CleanUpNamespace deletes the devices in the network namespace.
// CleanUpNamespace deletes the devices in the network namespace .
func CleanUpNamespace(args *skel.CmdArgs, logger *log.Entry) error {
	if args.Netns != "" {
		logger.Debug("Checking namespace & device exist.")
		devErr := ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
			_, err := netlink.LinkByName(args.IfName)
			return err
		})
		if devErr == nil {
			fmt.Fprintf(os.Stderr, "Calico CNI deleting device in netns %s\n", args.Netns)
			err := ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
				_, err := ip.DelLinkByNameAddr(args.IfName, netlink.FAMILY_V4)
				return err
			})
			if err != nil {
				return err
			}
		} else {
			logger.Info("veth does not exist, no need to clean up.")
		}
	}
	return nil
}
func CleanUpNamespace ( args * skel . CmdArgs , logger * log . Entry ) error { if args . Netns != " " { logger . Debug ( " " ) devErr := ns . WithNetNSPath ( args . Netns , func ( _ ns . NetNS ) error { _ , err := netlink . LinkByName ( args . IfName ) return err } ) if devErr == nil { fmt . Fprintf ( os . Stderr , " \n " , args . Netns ) err := ns . WithNetNSPath ( args . Netns , func ( _ ns . NetNS ) error { _ , err := ip . DelLinkByNameAddr ( args . IfName , netlink . FAMILY_V4 ) return err } ) if err != nil { return err } } else { logger . Info ( " " ) } } return nil }
CleanUpNamespace deletes the devices in the network namespace.
CleanUpNamespace deletes the devices in the network namespace .
// Only try to delete the device if a namespace was passed in.