// AddLbService adds a LB service in non-multi tenant record
767163
func (ens *NetpluginNameServer) AddLbService(tenant string, name string, v4name string) {
	if len(v4name) > 0 {
		dnsLog.Infof("add k8s service %s ip %s", name, v4name)
		if tenant == K8sDefaultTenant {
			ens.k8sService.Set(name, nameRecord{v4Record: net.ParseIP(v4name)})
		} else {
			mc := mastercfg.CfgServiceLBState{
				Tenant:      tenant,
				ServiceName: name,
				IPAddress:   v4name,
			}
			ens.addService(&mc)
		}
	}
}
408214
func (e *Encoder) AddBE(src interface{}) error {
	e.WrittenBytes += binary.Size(src)
	return binary.Write(e.w, binary.BigEndian, src)
}
709482
func addService(containers []corev1.Container, objectMeta metav1.ObjectMeta, selector map[string]string, firstPortOnly bool) *corev1.Service {
	ports := UniqueContainerToServicePorts(AllContainerPorts(containers...))
	if len(ports) == 0 {
		return nil
	}
	if firstPortOnly {
		ports = ports[:1]
	}
	svc := GenerateService(objectMeta, selector)
	svc.Spec.Ports = ports
	return svc
}
217306
func BlockService(lc fx.Lifecycle, bs blockstore.Blockstore, rem exchange.Interface) blockservice.BlockService {
	bsvc := blockservice.New(bs, rem)

	lc.Append(fx.Hook{
		OnStop: func(ctx context.Context) error {
			return bsvc.Close()
		},
	})

	return bsvc
}
1357450
func NewLBClient(addr string) (*LBClient, error) {
	client, err := rpcutils.GetCachedClient(addr)
	if err != nil {
		return nil, err
	}
	s := new(LBClient)
	s.addr = addr
	s.rpcClient = client
	return s, nil
}
502228
func (l *State) AddService(service *structs.NodeService, token string) error {
	l.Lock()
	defer l.Unlock()
	return l.addServiceLocked(service, token)
}
900522
func (b *FusisBalancer) AddService(svc *types.Service) error {
	// Allocate a new VIP if no address provided
	if svc.Address == "" {
		if err := b.ipam.AllocateVIP(svc); err != nil {
			return err
		}
	}

	return b.store.AddService(svc)
}
400508
func (a *api) AddService(config ServiceConfig) (*service.ServiceDetails, error) {
	client, err := a.connectDAO()
	if err != nil {
		return nil, err
	}

	endpoints := make([]servicedefinition.EndpointDefinition, len(*config.LocalPorts)+len(*config.RemotePorts))
	i := 0
	for _, e := range *config.LocalPorts {
		e.Purpose = "local"
		endpoints[i] = e
		i++
	}
	for _, e := range *config.RemotePorts {
		e.Purpose = "remote"
		endpoints[i] = e
		i++
	}

	sd := &servicedefinition.ServiceDefinition{
		Name:      config.Name,
		Command:   config.Command,
		Instances: domain.MinMax{Min: 1, Max: 1, Default: 1},
		ImageID:   config.ImageID,
		Launch:    commons.AUTO,
		Endpoints: endpoints,
	}

	var serviceID string
	if err := client.DeployService(dao.ServiceDeploymentRequest{ParentID: config.ParentServiceID, Service: *sd}, &serviceID); err != nil {
		return nil, err
	}

	return a.GetServiceDetails(serviceID)
}
1075061
func (na *NetAddress) HasService(service ServiceFlag) bool {
	return na.Services&service == service
}
930234
func (_m *Store) AddService(svc *types.Service) error {
	ret := _m.Called(svc)

	var r0 error
	if rf, ok := ret.Get(0).(func(*types.Service) error); ok {
		r0 = rf(svc)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
333274
func (i *injector) AddServices(vals ...interface{}) {
	for _, v := range vals {
		i.AddService(v)
	}
}
1140163
func (p *Processor) AddOrUpdateService(apis *urisearch.APICache, serviceType policy.UserAuthorizationTypeValues, handler usertokens.Verifier, mappings map[string]string) {
	p.Lock()
	defer p.Unlock()

	p.apis = apis
	p.userTokenMappings = mappings
	p.userTokenHandler = handler
	p.userAuthorizationType = serviceType
}
44007
func (msg *MsgVersion) HasService(service ServiceFlag) bool {
	return msg.Services&service == service
}
934790
func (service *BaseService) AddFilter(filter ...Filter) Service {
	service.filterManager.AddFilter(filter...)
	return service
}
1108372
func (s *BatchServiceStateManager) AddTenant(tenantID string) error {
	s.lock.Lock()
	defer s.lock.Unlock()

	// We can't start the queue loop if we have been shutdown, so don't allow adding a tenant
	if s.shutdown == nil {
		return ErrNotRunning
	}

	select {
	case <-s.shutdown:
		return ErrNotRunning
	default:
	}

	if _, ok := s.TenantQueues[tenantID]; ok {
		return ErrDuplicateTenantID
	}

	shutdown := make(chan int)
	s.TenantQueues[tenantID] = make(map[service.DesiredState]*ServiceStateQueue)
	s.TenantQueues[tenantID][service.SVCRun] = NewServiceStateQueue(s.Facade)
	s.TenantQueues[tenantID][service.SVCStop] = NewServiceStateQueue(s.Facade)
	s.TenantShutDowns[tenantID] = shutdown
	for t, q := range s.TenantQueues[tenantID] {
		go s.queueLoop(tenantID, t.String(), q, shutdown)
	}

	plog.WithField("tenantid", tenantID).Debug("Added tenant to service state manager")

	return nil
}
542690
func CreateServiceLB(obj *ServiceLB) error {
	// Validate parameters
	err := ValidateServiceLB(obj)
	if err != nil {
		log.Errorf("ValidateServiceLB retruned error for: %+v. Err: %v", obj, err)
		return err
	}

	// Check if we handle this object
	if objCallbackHandler.ServiceLBCb == nil {
		log.Errorf("No callback registered for serviceLB object")
		return errors.New("Invalid object type")
	}

	saveObj := obj

	collections.serviceLBMutex.Lock()
	key := collections.serviceLBs[obj.Key]
	collections.serviceLBMutex.Unlock()

	// Check if object already exists
	if key != nil {
		// Perform Update callback
		err = objCallbackHandler.ServiceLBCb.ServiceLBUpdate(collections.serviceLBs[obj.Key], obj)
		if err != nil {
			log.Errorf("ServiceLBUpdate retruned error for: %+v. Err: %v", obj, err)
			return err
		}

		// save the original object after update
		collections.serviceLBMutex.Lock()
		saveObj = collections.serviceLBs[obj.Key]
		collections.serviceLBMutex.Unlock()
	} else {
		// save it in cache
		collections.serviceLBMutex.Lock()
		collections.serviceLBs[obj.Key] = obj
		collections.serviceLBMutex.Unlock()

		// Perform Create callback
		err = objCallbackHandler.ServiceLBCb.ServiceLBCreate(obj)
		if err != nil {
			log.Errorf("ServiceLBCreate retruned error for: %+v. Err: %v", obj, err)
			collections.serviceLBMutex.Lock()
			delete(collections.serviceLBs, obj.Key)
			collections.serviceLBMutex.Unlock()
			return err
		}
	}

	// Write it to modeldb
	collections.serviceLBMutex.Lock()
	err = saveObj.Write()
	collections.serviceLBMutex.Unlock()
	if err != nil {
		log.Errorf("Error saving serviceLB %s to db. Err: %v", saveObj.Key, err)
		return err
	}

	return nil
}
302809
func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer) error {
	if az.Config.shouldOmitCloudProviderBackoff() {
		ctx, cancel := getContextWithCancel()
		defer cancel()

		resp, err := az.LoadBalancerClient.CreateOrUpdate(ctx, az.ResourceGroup, *lb.Name, lb)
		klog.V(10).Infof("LoadBalancerClient.CreateOrUpdate(%s): end", *lb.Name)
		if err == nil {
			if isSuccessHTTPResponse(resp) {
				// Invalidate the cache right after updating
				az.lbCache.Delete(*lb.Name)
			} else if resp != nil {
				return fmt.Errorf("HTTP response %q", resp.Status)
			}
		}
		return err
	}

	return az.createOrUpdateLBWithRetry(service, lb)
}