Ejemplo n.º 1
0
func cmdDel(args *skel.CmdArgs) error {
	c, err := cnc.NewDefaultClient()
	if err != nil {
		return fmt.Errorf("error while starting cilium-client: %s", err)
	}

	ep, err := c.EndpointGetByDockerID(args.ContainerID)
	if err != nil {
		return fmt.Errorf("error while retrieving endpoint from cilium daemon: %s", err)
	}
	if ep == nil {
		return fmt.Errorf("endpoint with container ID %s not found", args.ContainerID)
	}

	ipv6addr := ep.IPv6.IP()
	if err = c.ReleaseIP(ipam.CNIIPAMType, ipam.IPAMReq{IP: &ipv6addr}); err != nil {
		log.Warningf("failed to release allocated IPv6 of container ID %q: %s", args.ContainerID, err)
	}
	ipv4addr := ep.IPv4.IP()
	if ep.IPv4 != nil {
		if err = c.ReleaseIP(ipam.CNIIPAMType, ipam.IPAMReq{IP: &ipv4addr}); err != nil {
			log.Warningf("failed to release allocated IPv4 of container ID %q: %s", args.ContainerID, err)
		}
	}

	if err := c.EndpointLeave(ep.ID); err != nil {
		log.Warningf("leaving the endpoint failed: %s\n", err)
	}

	return ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error {
		return plugins.DelLinkByName(args.IfName)
	})
}
Ejemplo n.º 2
0
func (driver *driver) deleteEndpoint(w http.ResponseWriter, r *http.Request) {
	var del api.DeleteEndpointRequest
	if err := json.NewDecoder(r.Body).Decode(&del); err != nil {
		sendError(w, "Could not decode JSON encode payload", http.StatusBadRequest)
		return
	}
	log.Debugf("Delete endpoint request: %+v", &del)

	if err := plugins.DelLinkByName(plugins.Endpoint2IfName(del.EndpointID)); err != nil {
		log.Warningf("Error while deleting link: %s", err)
	}

	emptyResponse(w)
}
Ejemplo n.º 3
0
func (driver *driver) leaveEndpoint(w http.ResponseWriter, r *http.Request) {
	var l api.LeaveRequest
	if err := json.NewDecoder(r.Body).Decode(&l); err != nil {
		sendError(w, "Could not decode JSON encode payload", http.StatusBadRequest)
		return
	}
	log.Debugf("Leave request: %+v", &l)

	if err := driver.client.EndpointLeaveByDockerEPID(l.EndpointID); err != nil {
		log.Warningf("Leaving the endpoint failed: %s", err)
	}

	if err := plugins.DelLinkByName(plugins.Endpoint2IfName(l.EndpointID)); err != nil {
		log.Warningf("Error while deleting link: %s", err)
	}
	emptyResponse(w)
}