// DelSvcSpec deletes a service from the proxy
327904
func (p *NodeSvcProxy) DelSvcSpec(svcName string, spec *core.ServiceSpec) error {
	p.Mutex.Lock()
	defer p.Mutex.Unlock()
	p.deleteSvc(svcName) // delete it if it exists
	return nil
}
1197238
func mergeSpecs(staticSpec *spec.Swagger, crdSpecs ...*spec.Swagger) *spec.Swagger {
	// create shallow copy of staticSpec, but replace paths and definitions because we modify them.
	specToReturn := *staticSpec
	if staticSpec.Definitions != nil {
		specToReturn.Definitions = spec.Definitions{}
		for k, s := range staticSpec.Definitions {
			specToReturn.Definitions[k] = s
		}
	}
	if staticSpec.Paths != nil {
		specToReturn.Paths = &spec.Paths{
			Paths: map[string]spec.PathItem{},
		}
		for k, p := range staticSpec.Paths.Paths {
			specToReturn.Paths.Paths[k] = p
		}
	}

	for _, s := range crdSpecs {
		mergeSpec(&specToReturn, s)
	}

	return &specToReturn
}
1360973
func (env *azureEnviron) deleteVirtualMachine(
	ctx context.ProviderCallContext,
	sdkCtx stdcontext.Context,
	instId instance.Id,
	maybeStorageClient internalazurestorage.Client,
	networkInterfaces []network.Interface,
	publicIPAddresses []network.PublicIPAddress,
) error {
	vmClient := compute.VirtualMachinesClient{env.compute}
	diskClient := compute.DisksClient{env.disk}
	nicClient := network.InterfacesClient{env.network}
	nsgClient := network.SecurityGroupsClient{env.network}
	securityRuleClient := network.SecurityRulesClient{env.network}
	pipClient := network.PublicIPAddressesClient{env.network}
	deploymentsClient := resources.DeploymentsClient{env.resources}
	vmName := string(instId)

	// TODO(axw) delete resources concurrently.

	// The VM must be deleted first, to release the lock on its resources.
	logger.Debugf("- deleting virtual machine (%s)", vmName)
	vmErrMsg := "deleting virtual machine"
	vmFuture, err := vmClient.Delete(sdkCtx, env.resourceGroup, vmName)
	if err != nil {
		if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResponse(vmFuture.Response()) {
			return errors.Annotate(err, vmErrMsg)
		}
	} else {
		err = vmFuture.WaitForCompletionRef(sdkCtx, vmClient.Client)
		if err != nil {
			return errorutils.HandleCredentialError(errors.Annotate(err, vmErrMsg), ctx)
		}
		result, err := vmFuture.Result(vmClient)
		if err != nil {
			if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResult(result) {
				return errors.Annotate(err, vmErrMsg)
			}
		}
	}
	if maybeStorageClient != nil {
		logger.Debugf("- deleting OS VHD (%s)", vmName)
		blobClient := maybeStorageClient.GetBlobService()
		vhdContainer := blobClient.GetContainerReference(osDiskVHDContainer)
		vhdBlob := vhdContainer.Blob(vmName)
		_, err := vhdBlob.DeleteIfExists(nil)
		return errorutils.HandleCredentialError(errors.Annotate(err, "deleting OS VHD"), ctx)
	}

	// Delete the managed OS disk.
	logger.Debugf("- deleting OS disk (%s)", vmName)
	diskErrMsg := "deleting OS disk"
	diskFuture, err := diskClient.Delete(sdkCtx, env.resourceGroup, vmName)
	if err != nil {
		if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResponse(diskFuture.Response()) {
			return errors.Annotate(err, diskErrMsg)
		}
	}
	if err == nil {
		err = diskFuture.WaitForCompletionRef(sdkCtx, diskClient.Client)
		if err != nil {
			return errorutils.HandleCredentialError(errors.Annotate(err, diskErrMsg), ctx)
		}
		result, err := diskFuture.Result(diskClient)
		if err != nil {
			if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResult(result) {
				return errors.Annotate(err, diskErrMsg)
			}
		}
	}
	logger.Debugf("- deleting security rules (%s)", vmName)
	if err := deleteInstanceNetworkSecurityRules(
		ctx,
		env.resourceGroup, instId,
		nsgClient, securityRuleClient,
	); err != nil {
		return errors.Annotate(err, "deleting network security rules")
	}

	logger.Debugf("- deleting network interfaces (%s)", vmName)
	networkErrMsg := "deleting NIC"
	for _, nic := range networkInterfaces {
		nicName := to.String(nic.Name)
		logger.Tracef("deleting NIC %q", nicName)
		nicFuture, err := nicClient.Delete(sdkCtx, env.resourceGroup, nicName)
		if err != nil {
			if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResponse(nicFuture.Response()) {
				return errors.Annotate(err, networkErrMsg)
			}
		} else {
			err = nicFuture.WaitForCompletionRef(sdkCtx, nicClient.Client)
			if err != nil {
				return errorutils.HandleCredentialError(errors.Annotate(err, networkErrMsg), ctx)
			}
			result, err := nicFuture.Result(nicClient)
			if err != nil {
				if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResult(result) {
					return errors.Annotate(err, networkErrMsg)
				}
			}
		}
	}

	logger.Debugf("- deleting public IPs (%s)", vmName)
	ipErrMsg := "deleting public IP"
	for _, pip := range publicIPAddresses {
		pipName := to.String(pip.Name)
		logger.Tracef("deleting public IP %q", pipName)
		ipFuture, err := pipClient.Delete(sdkCtx, env.resourceGroup, pipName)
		if err != nil {
			if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResponse(ipFuture.Response()) {
				return errors.Annotate(err, ipErrMsg)
			}
		} else {
			err = ipFuture.WaitForCompletionRef(sdkCtx, pipClient.Client)
			if err != nil {
				return errorutils.HandleCredentialError(errors.Annotate(err, ipErrMsg), ctx)
			}
			result, err := ipFuture.Result(pipClient)
			if err != nil {
				if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResult(result) {
					return errors.Annotate(err, ipErrMsg)
				}
			}
		}
	}

	// The deployment must be deleted last, or we risk leaking resources.
	logger.Debugf("- deleting deployment (%s)", vmName)
	deploymentFuture, err := deploymentsClient.Delete(sdkCtx, env.resourceGroup, vmName)
	deploymentErrMsg := "deleting deployment"
	if err != nil {
		if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResponse(deploymentFuture.Response()) {
			return errors.Annotate(err, deploymentErrMsg)
		}
	} else {
		err = deploymentFuture.WaitForCompletionRef(sdkCtx, deploymentsClient.Client)
		if err != nil {
			return errorutils.HandleCredentialError(errors.Annotate(err, deploymentErrMsg), ctx)
		}
		deploymentResult, err := deploymentFuture.Result(deploymentsClient)
		if err != nil {
			if errorutils.MaybeInvalidateCredential(err, ctx) || !isNotFoundResult(deploymentResult) {
				return errors.Annotate(err, deploymentErrMsg)
			}
		}
	}
	return nil
}
46702
func ParseService(svc *types.Service) (ServiceID, *Service) {
	scopedLog := log.WithFields(logrus.Fields{
		logfields.K8sSvcName:    svc.ObjectMeta.Name,
		logfields.K8sNamespace:  svc.ObjectMeta.Namespace,
		logfields.K8sAPIVersion: svc.TypeMeta.APIVersion,
		logfields.K8sSvcType:    svc.Spec.Type,
	})

	svcID := ParseServiceID(svc)

	switch svc.Spec.Type {
	case v1.ServiceTypeClusterIP, v1.ServiceTypeNodePort, v1.ServiceTypeLoadBalancer:
		break

	case v1.ServiceTypeExternalName:
		// External-name services must be ignored
		return svcID, nil

	default:
		scopedLog.Warn("Ignoring k8s service: unsupported type")
		return svcID, nil
	}

	if svc.Spec.ClusterIP == "" {
		return svcID, nil
	}

	clusterIP := net.ParseIP(svc.Spec.ClusterIP)
	headless := false
	if strings.ToLower(svc.Spec.ClusterIP) == "none" {
		headless = true
	}
	svcInfo := NewService(clusterIP, headless, svc.Labels, svc.Spec.Selector)
	svcInfo.IncludeExternal = getAnnotationIncludeExternal(svc)
	svcInfo.Shared = getAnnotationShared(svc)

	// FIXME: Add support for
	//  - NodePort
	for _, port := range svc.Spec.Ports {
		p := loadbalancer.NewFEPort(loadbalancer.L4Type(port.Protocol), uint16(port.Port))
		if _, ok := svcInfo.Ports[loadbalancer.FEPortName(port.Name)]; !ok {
			svcInfo.Ports[loadbalancer.FEPortName(port.Name)] = p
		}
	}

	return svcID, svcInfo
}
210090
func (p *NetPlugin) DeleteServiceLB(servicename string, spec *core.ServiceSpec) error {
	p.Lock()
	defer p.Unlock()
	return p.NetworkDriver.DelSvcSpec(servicename, spec)
}
462096
func (r *Ref) Refspec() string {
	if r == nil {
		return ""
	}

	prefix, ok := r.Type.Prefix()
	if ok {
		return fmt.Sprintf("%s/%s", prefix, r.Name)
	}

	return r.Name
}
1100803
func (s *VPNService) DeleteVpnCustomerGateway(p *DeleteVpnCustomerGatewayParams) (*DeleteVpnCustomerGatewayResponse, error) {
	resp, err := s.cs.newRequest("deleteVpnCustomerGateway", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r DeleteVpnCustomerGatewayResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
114758
func (cfg *Config) envNameForSpec(c context.Context, s *vpython.Spec, rt *vpython.Runtime) string {
	uid := "<unknown>"
	if user, err := user.Current(); err == nil {
		uid = user.Uid
	} else {
		logging.Warningf(c, "Unable to find current user ID: %s", err)
	}

	name := spec.Hash(s, rt, EnvironmentVersion,
		string(assets.GetAssetSHA256(siteCustomizePy)), uid)
	if cfg.MaxHashLen > 0 && len(name) > cfg.MaxHashLen {
		name = name[:cfg.MaxHashLen]
	}
	return name
}
1285312
func deleteResource(ctx context.Context, client *AzureClient, resourceType string, resourceName string, resourceGroupName string) error {
	switch resourceType {
	case "Microsoft.Compute/virtualMachines":
		f, err := client.VirtualMachinesClient.Delete(ctx, resourceGroupName, resourceName)
		if err == nil {
			err = f.WaitForCompletion(ctx, client.VirtualMachinesClient.Client)
		}
		return err
	case "Microsoft.KeyVault/vaults":
		// TODO(paulmey): not sure why VaultClient doesn't do cancellation
		_, err := client.VaultClientDelete.Delete(resourceGroupName, resourceName)
		return err
	case "Microsoft.Network/networkInterfaces":
		f, err := client.InterfacesClient.Delete(ctx, resourceGroupName, resourceName)
		if err == nil {
			err = f.WaitForCompletion(ctx, client.InterfacesClient.Client)
		}
		return err
	case "Microsoft.Network/virtualNetworks":
		f, err := client.VirtualNetworksClient.Delete(ctx, resourceGroupName, resourceName)
		if err == nil {
			err = f.WaitForCompletion(ctx, client.VirtualNetworksClient.Client)
		}
		return err
	case "Microsoft.Network/publicIPAddresses":
		f, err := client.PublicIPAddressesClient.Delete(ctx, resourceGroupName, resourceName)
		if err == nil {
			err = f.WaitForCompletion(ctx, client.PublicIPAddressesClient.Client)
		}
		return err
	}
	return nil
}
1201823
func (g *Cloud) DeleteSslCertificate(name string) error {
	ctx, cancel := cloud.ContextWithCallTimeout()
	defer cancel()

	mc := newCertMetricContext("delete")
	return mc.Observe(g.c.SslCertificates().Delete(ctx, meta.GlobalKey(name)))
}
1257617
func (lb *LoadBalancer) DeleteService(svc *LBSVC) {
	log.WithFields(logrus.Fields{
		logfields.ServiceName: svc.FE.String(),
		logfields.SHA:         svc.Sha256,
	}).Debug("deleting service from loadbalancer")
	delete(lb.SVCMap, svc.Sha256)
	delete(lb.SVCMapID, ServiceID(svc.FE.ID))
	deleteMetric.Inc()
}
388022
func (d *VppDriver) AddSvcSpec(svcName string, spec *core.ServiceSpec) error {
	log.Infof("Not implemented")
	return nil
}
208431
func RemotesDocs(serverType string, services map[string]*component.Service, getPtrNames bool) (map[string]interface{}, error) {
	docs := &docs{
		Remotes: map[string]*doc{},
	}

	for serviceName, service := range services {
		for name, remote := range service.Remotes {
			routeName := route.NewRoute(serverType, serviceName, name)
			docs.Remotes[routeName.String()] = docForMethod(remote.Method, getPtrNames)
		}
	}

	return docs.Remotes.toMap()
}
1235153
func (f *Facade) DeleteServiceConfig(ctx datastore.Context, fileID string) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.DeleteServiceConfig"))
	logger := plog.WithField("fileid", fileID)

	alog := f.auditLogger.Message(ctx, "Removing Service Configuration").
		Action(audit.Remove).ID(fileID).Type(servicedefinition.GetConfigFileType())

	if err := f.configStore.Delete(ctx, serviceconfigfile.Key(fileID)); err != nil {
		logger.WithError(err).Debug("Could not delete service config file")
		return alog.Error(err)
	}

	logger.Debug("Deleted service config file")
	alog.Succeeded()
	return nil
}
683846
func (s *BrocadeVCSService) DeleteBrocadeVcsDevice(p *DeleteBrocadeVcsDeviceParams) (*DeleteBrocadeVcsDeviceResponse, error) {
	resp, err := s.cs.newRequest("deleteBrocadeVcsDevice", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r DeleteBrocadeVcsDeviceResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
1149500
func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceEndpoint) {
	for _, epSvcPair := range connectionMap {
		if svcInfo, ok := proxier.serviceMap[epSvcPair.ServicePortName]; ok && svcInfo.GetProtocol() == v1.ProtocolUDP {
			endpointIP := utilproxy.IPPart(epSvcPair.Endpoint)
			nodePort := svcInfo.GetNodePort()
			var err error
			if nodePort != 0 {
				err = conntrack.ClearEntriesForPortNAT(proxier.exec, endpointIP, nodePort, v1.ProtocolUDP)
			} else {
				err = conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIPString(), endpointIP, v1.ProtocolUDP)
			}
			if err != nil {
				klog.Errorf("Failed to delete %s endpoint connections, error: %v", epSvcPair.ServicePortName.String(), err)
			}
			for _, extIP := range svcInfo.ExternalIPStrings() {
				err := conntrack.ClearEntriesForNAT(proxier.exec, extIP, endpointIP, v1.ProtocolUDP)
				if err != nil {
					klog.Errorf("Failed to delete %s endpoint connections for externalIP %s, error: %v", epSvcPair.ServicePortName.String(), extIP, err)
				}
			}
			for _, lbIP := range svcInfo.LoadBalancerIPStrings() {
				err := conntrack.ClearEntriesForNAT(proxier.exec, lbIP, endpointIP, v1.ProtocolUDP)
				if err != nil {
					klog.Errorf("Failed to delete %s endpoint connections for LoabBalancerIP %s, error: %v", epSvcPair.ServicePortName.String(), lbIP, err)
				}
			}
		}
	}
}
463628
func (d *OvsDriver) AddSvcSpec(svcName string, spec *core.ServiceSpec) error {
	log.Infof("AddSvcSpec: %s", svcName)
	ss := convSvcSpec(spec)
	errs := ""
	for _, sw := range d.switchDb {
		log.Infof("sw AddSvcSpec: %s", svcName)
		err := sw.AddSvcSpec(svcName, ss)
		if err != nil {
			errs += err.Error()
		}
	}

	err := d.HostProxy.AddSvcSpec(svcName, spec)
	if err != nil {
		errs += err.Error()
	}

	if errs != "" {
		return errors.New(errs)
	}

	d.nameServer.AddLbService(nameserver.K8sDefaultTenant, svcName, spec.IPAddress)

	return nil
}