// DeleteLease returns the http handler for the DELETE /lease/{token} endpoint
166966
func DeleteLease(services k8s.ServiceGetterUpdater,
	k8sServiceName string,
	gkeClusterLister gke.ClusterLister,
	azureClusterLister azure.ClusterLister,
	azureConfig *config.Azure,
	googleConfig *config.Google,
	clearNamespaces bool,
	nsFunc func(*k8s.KubeConfig) (k8s.NamespaceListerDeleter, error)) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		pathElts := htp.SplitPath(r)
		if len(pathElts) != 3 {
			log.Println("Path must be in the format /lease/{provider}/{token}")
			htp.Error(w, http.StatusBadRequest, "Path must be in the format /lease/{token}")
			return
		}

		provider := pathElts[1]
		leaseToken := uuid.Parse(pathElts[2])
		if leaseToken == nil {
			log.Printf("Lease token %s is invalid", pathElts[1])
			htp.Error(w, http.StatusBadRequest, "Lease token %s is invalid", pathElts[1])
			return
		}

		svc, err := services.Get(k8sServiceName)
		if err != nil {
			log.Printf("Error getting the %s service -- %s", k8sServiceName, err)
			htp.Error(w, http.StatusInternalServerError, "Error getting the %s service -- %s", k8sServiceName, err)
			return
		}
		leaseMap, err := leases.ParseMapFromAnnotations(svc.Annotations)
		if err != nil {
			log.Printf("Error getting annotations for the %s service -- %s", k8sServiceName, err)
			htp.Error(w, http.StatusInternalServerError, "Error getting annotations for the %s service -- %s", k8sServiceName, err)
			return
		}
		lease, existed := leaseMap.LeaseForUUID(leaseToken)
		if !existed {
			log.Printf("Lease %s doesn't exist", leaseToken)
			htp.Error(w, http.StatusConflict, "Lease %s doesn't exist", leaseToken)
			return
		}

		var cfg *k8s.KubeConfig
		switch provider {
		case "google":
			if googleConfig.ValidConfig() {
				cluster, err := gke.GetClusterFromLease(lease, gkeClusterLister, googleConfig.ProjectID, googleConfig.Zone)
				if err != nil {
					log.Printf("Couldn't get cluster from lease -- %s for google provider", err)
					htp.Error(w, http.StatusInternalServerError, "Couldn't get cluster from lease -- %s", err)
					return
				}
				cfg, err = k8s.CreateKubeConfigFromCluster(cluster)
				if err != nil {
					log.Printf("Couldn't create kube config from cluster -- %s", err)
					htp.Error(w, http.StatusInternalServerError, "Couldn't create kube config from cluster -- %s", err)
					return
				}
			} else {
				log.Println("Unable to satisfy this request because the Google provider is not properly configured.")
				htp.Error(w, http.StatusInternalServerError, "Unable to satisfy this request because the Google provider is not properly configured.")
			}
		case "azure":
			if azureConfig.ValidConfig() {
				cluster, err := azure.GetClusterFromLease(lease, azureClusterLister)
				if err != nil {
					log.Printf("Couldn't get cluster from lease -- %s for azure provider", err)
					htp.Error(w, http.StatusInternalServerError, "Couldn't get cluster from lease -- %s", err)
					return
				}
				log.Printf("Cluster when deleting:%+v\n", cluster)
				cfg, err = azure.FetchKubeConfig(*cluster.MasterProfile.Fqdn)
				if err != nil {
					log.Printf("Couldn't create kube config from cluster -- %s", err)
					htp.Error(w, http.StatusInternalServerError, "Couldn't create kube config from cluster -- %s", err)
					return
				}
			} else {
				log.Println("Unable to satisfy this request because the Azure provider is not properly configured.")
				htp.Error(w, http.StatusInternalServerError, "Unable to satisfy this request because the Azure provider is not properly configured.")
			}
		default:
			log.Printf("Unable to find suitable provider for this request -- Provider:%s", provider)
			htp.Error(w, http.StatusBadRequest, "Unable to find suitable provider for this request -- Provider:%s", provider)
			return
		}

		// blow away the lease, regardless of whether it's expired or not. the create endpoint deletes
		// the lease from annotations, replacing the lease for a cluster with a new UUID anyway
		deleted := leaseMap.DeleteLease(leaseToken)
		if !deleted {
			log.Printf("Lease %s doesn't exist", leaseToken)
			htp.Error(w, http.StatusConflict, "Lease %s doesn't exist", leaseToken)
			return
		}

		if clearNamespaces {
			namespaces, err := nsFunc(cfg)
			if err != nil {
				log.Printf("Couldn't create namespaces lister/deleter implementation  -- %s", err)
				htp.Error(w, http.StatusInternalServerError, "Couldn't create namespaces lister/deleter implementation  -- %s", err)
				return
			}
			if err := deleteNamespaces(namespaces, skipDeleteNamespaces); err != nil {
				log.Printf("Error deleting namespaces -- %s", err)
				htp.Error(w, http.StatusInternalServerError, "Error deleting namespaces -- %s", err)
				return
			}
		}

		if err := k8s.SaveAnnotations(services, svc, leaseMap); err != nil {
			log.Printf("Error saving new annotations -- %s", err)
			htp.Error(w, http.StatusInternalServerError, "Error saving new annotations -- %s", err)
			return
		}

		w.WriteHeader(http.StatusOK)
	})
}
1262571
func (t *MemoryPool) PurgeLeases() error {
	t.poolLock.Lock()
	defer t.poolLock.Unlock()

	t.pool = nil
	t.pool = make([]leasepool.Lease, 0)
	return nil
}
1277970
func (m *ExpirationManager) deleteEntry(ctx context.Context, le *leaseEntry) error {
	view := m.leaseView(le.namespace)
	if err := view.Delete(ctx, le.LeaseID); err != nil {
		return errwrap.Wrapf("failed to delete lease entry: {{err}}", err)
	}
	return nil
}
917132
func (s *storageLeases) RemoveLease(ip string) error {
	return s.storage.Delete(apirequest.NewDefaultContext(), s.baseKey+"/"+ip, &corev1.Endpoints{}, nil)
}
775948
func (lm *LeaseManager) Delete(ctx context.Context, lease leases.Lease, _ ...leases.DeleteOpt) error {
	namespace, err := namespaces.NamespaceRequired(ctx)
	if err != nil {
		return err
	}

	topbkt := getBucket(lm.tx, bucketKeyVersion, []byte(namespace), bucketKeyObjectLeases)
	if topbkt == nil {
		return errors.Wrapf(errdefs.ErrNotFound, "lease %q", lease.ID)
	}
	if err := topbkt.DeleteBucket([]byte(lease.ID)); err != nil {
		if err == bolt.ErrBucketNotFound {
			err = errors.Wrapf(errdefs.ErrNotFound, "lease %q", lease.ID)
		}
		return err
	}
	return nil
}
1087649
func (c *Client) Delete(endpoint string) (tumblr.Response, error) {
	return c.DeleteWithParams(endpoint, url.Values{})
}
700142
func ValidateLease(lease *coordination.Lease) field.ErrorList {
	allErrs := validation.ValidateObjectMeta(&lease.ObjectMeta, true, validation.NameIsDNSSubdomain, field.NewPath("metadata"))
	allErrs = append(allErrs, ValidateLeaseSpec(&lease.Spec, field.NewPath("spec"))...)
	return allErrs
}
374671
func (c *client) OrgSecretDelete(namespace, name string) error {
	uri := fmt.Sprintf(pathSecretsName, c.addr, namespace, name)
	return c.delete(uri)
}
256852
func (c *consulClient) Delete(key string) error {
	duration := spanstat.Start()
	_, err := c.KV().Delete(key, nil)
	increaseMetric(key, metricDelete, "Delete", duration.EndError(err).Total(), err)
	return err
}
739598
func Delete(req *http.Request, key interface{}) {
	crc := getContextReadCloser(req)
	delete(crc.Context(), key)
}
931285
func (a *API) Delete(url string, params Params) error {
	resp, err := a.client.Delete(url, params, a.token)
	resp.Body.Close()
	return err
}
1283309
func (s *Service) Lease(id int64, apileaserequestbodymessage *ApiLeaseRequestBodyMessage) *LeaseCall {
	c := &LeaseCall{s: s, urlParams_: make(gensupport.URLParams)}
	c.id = id
	c.apileaserequestbodymessage = apileaserequestbodymessage
	return c
}
181034
func (t *MemoryPool) GetLease(leaseIP net.IP) (bool, leasepool.Lease, error) {
	t.poolLock.Lock()
	defer t.poolLock.Unlock()

	for i := range t.pool {
		if t.pool[i].IP.Equal(leaseIP) {
			return true, t.pool[i], nil
		}
	}
	return false, leasepool.Lease{}, nil
}
381249
func (s *spaceService) DeleteSpace(ctx context.Context, byIdentityID uuid.UUID, spaceID string) error {

	err := s.ExecuteInTransaction(func() error {
		// Check if the space exists first to make sure we return NotFoundError if it doesn't instead of Forbidden when checking permissions
		err := s.Repositories().ResourceRepository().CheckExists(ctx, spaceID)
		if err != nil {
			return err
		}
		err = s.Services().PermissionService().RequireScope(ctx, byIdentityID, spaceID, authorization.DeleteSpaceScope)
		if err != nil {
			return err
		}
		return s.Services().ResourceService().Delete(ctx, spaceID)
	})

	return err
}
587745
func (c *Client) Delete(key string) error {
	return c.deleteRecurse(key, false)
}
80633
func (c *FakeLeases) Delete(name string, options *v1.DeleteOptions) error {
	_, err := c.Fake.
		Invokes(testing.NewDeleteAction(leasesResource, c.ns, name), &v1beta1.Lease{})

	return err
}
969945
func (a *ACL) DeleteTokens(args *structs.ACLTokenDeleteRequest, reply *structs.GenericResponse) error {
	// Ensure ACLs are enabled, and always flow modification requests to the authoritative region
	if !a.srv.config.ACLEnabled {
		return aclDisabled
	}

	// Validate non-zero set of tokens
	if len(args.AccessorIDs) == 0 {
		return fmt.Errorf("must specify as least one token")
	}

	if done, err := a.srv.forward("ACL.DeleteTokens", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "acl", "delete_tokens"}, time.Now())

	// Check management level permissions
	if acl, err := a.srv.ResolveToken(args.AuthToken); err != nil {
		return err
	} else if acl == nil || !acl.IsManagement() {
		return structs.ErrPermissionDenied
	}

	// Snapshot the state
	state, err := a.srv.State().Snapshot()
	if err != nil {
		return err
	}

	// Determine if we are deleting local or global tokens
	hasGlobal := false
	allGlobal := true
	nonexistentTokens := make([]string, 0)
	for _, accessor := range args.AccessorIDs {
		token, err := state.ACLTokenByAccessorID(nil, accessor)
		if err != nil {
			return fmt.Errorf("token lookup failed: %v", err)
		}
		if token == nil {
			nonexistentTokens = append(nonexistentTokens, accessor)
			continue
		}
		if token.Global {
			hasGlobal = true
		} else {
			allGlobal = false
		}
	}

	if len(nonexistentTokens) != 0 {
		return fmt.Errorf("Cannot delete nonexistent tokens: %v", strings.Join(nonexistentTokens, ", "))
	}

	// Disallow mixed requests with global and non-global tokens since we forward
	// the entire request as a single batch.
	if hasGlobal {
		if !allGlobal {
			return fmt.Errorf("cannot delete mixed global and non-global tokens")
		}

		// Force the request to the authoritative region if it has global
		if a.srv.config.Region != a.srv.config.AuthoritativeRegion {
			args.Region = a.srv.config.AuthoritativeRegion
			_, err := a.srv.forward("ACL.DeleteTokens", args, args, reply)
			return err
		}
	}

	// Update via Raft
	_, index, err := a.srv.raftApply(structs.ACLTokenDeleteRequestType, args)
	if err != nil {
		return err
	}

	// Update the index
	reply.Index = index
	return nil
}