// getCachedService logs if unable to retrieve a service for the given key.
512296
func (ic *IngressIPController) getCachedService(key string) *v1.Service {
	if len(key) == 0 {
		return nil
	}
	if obj, exists, err := ic.cache.GetByKey(key); err != nil {
		klog.V(5).Infof("Unable to retrieve service %v from store: %v", key, err)
	} else if !exists {
		klog.V(6).Infof("Service %v has been deleted", key)
	} else {
		return obj.(*v1.Service)
	}
	return nil
}
1265238
func fetchCachedSettings(c context.Context) (*Settings, error) {
	cfg := &Settings{}
	if err := settings.Get(c, SettingsKey, cfg); err != settings.ErrNoSettings {
		return cfg, err
	}
	return cfg, nil
}
296593
func (s *serverConfig) GetCacheConfig() CacheConfig {
	if globalIsDiskCacheEnabled {
		return CacheConfig{
			Drives:  globalCacheDrives,
			Exclude: globalCacheExcludes,
			Expiry:  globalCacheExpiry,
			MaxUse:  globalCacheMaxUse,
		}
	}
	if s == nil {
		return CacheConfig{}
	}
	return s.Cache
}
1364259
func (cp *ConsulClient) GetService(srvName string) ([]ServiceInfo, error) {
	keyName := "contiv.io/service/" + srvName + "/"
	srvList, _, err := cp.getServiceInstances(keyName, 0)

	return srvList, err
}
550839
func (k *kubernetesClient) GetService(appName string, includeClusterIP bool) (*caas.Service, error) {
	services := k.client().CoreV1().Services(k.namespace)
	servicesList, err := services.List(v1.ListOptions{
		LabelSelector:        applicationSelector(appName),
		IncludeUninitialized: true,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	var result caas.Service
	// We may have the stateful set or deployment but service not done yet.
	if len(servicesList.Items) > 0 {
		service := servicesList.Items[0]
		result.Id = string(service.GetUID())
		result.Addresses = getSvcAddresses(&service, includeClusterIP)
	}

	deploymentName := k.deploymentName(appName)
	statefulsets := k.client().AppsV1().StatefulSets(k.namespace)
	ss, err := statefulsets.Get(deploymentName, v1.GetOptions{})
	if err == nil {
		if ss.Spec.Replicas != nil {
			scale := int(*ss.Spec.Replicas)
			result.Scale = &scale
		}
		message, ssStatus, err := k.getStatefulSetStatus(ss)
		if err != nil {
			return nil, errors.Annotatef(err, "getting status for %s", ss.Name)
		}
		result.Status = status.StatusInfo{
			Status:  ssStatus,
			Message: message,
		}
		return &result, nil
	}
	if !k8serrors.IsNotFound(err) {
		return nil, errors.Trace(err)
	}

	deployments := k.client().AppsV1().Deployments(k.namespace)
	deployment, err := deployments.Get(deploymentName, v1.GetOptions{})
	if err != nil && !k8serrors.IsNotFound(err) {
		return nil, errors.Trace(err)
	}
	if err == nil {
		if deployment.Spec.Replicas != nil {
			scale := int(*deployment.Spec.Replicas)
			result.Scale = &scale
		}
		message, ssStatus, err := k.getDeploymentStatus(deployment)
		if err != nil {
			return nil, errors.Annotatef(err, "getting status for %s", ss.Name)
		}
		result.Status = status.StatusInfo{
			Status:  ssStatus,
			Message: message,
		}
	}

	return &result, nil
}
1093560
func (c *Client) GetServiceTemplates() (map[string]servicetemplate.ServiceTemplate, error) {
	response := map[string]servicetemplate.ServiceTemplate{}
	if err := c.call("GetServiceTemplates", empty, &response); err != nil {
		return nil, err
	}
	return response, nil
}
432855
func (s *serviceAccount) getServiceAccount(namespace string, name string) (*corev1.ServiceAccount, error) {
	serviceAccount, err := s.serviceAccountLister.ServiceAccounts(namespace).Get(name)
	if err == nil {
		return serviceAccount, nil
	}
	if !errors.IsNotFound(err) {
		return nil, err
	}

	// Could not find in cache, attempt to look up directly
	numAttempts := 1
	if name == DefaultServiceAccountName {
		// If this is the default serviceaccount, attempt more times, since it should be auto-created by the controller
		numAttempts = 10
	}
	retryInterval := time.Duration(rand.Int63n(100)+int64(100)) * time.Millisecond
	for i := 0; i < numAttempts; i++ {
		if i != 0 {
			time.Sleep(retryInterval)
		}
		serviceAccount, err := s.client.CoreV1().ServiceAccounts(namespace).Get(name, metav1.GetOptions{})
		if err == nil {
			return serviceAccount, nil
		}
		if !errors.IsNotFound(err) {
			return nil, err
		}
	}

	return nil, errors.NewNotFound(api.Resource("serviceaccount"), name)
}
1012519
func (_m *State) GetServices() []types.Service {
	ret := _m.Called()

	var r0 []types.Service
	if rf, ok := ret.Get(0).(func() []types.Service); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]types.Service)
		}
	}

	return r0
}
218554
func NewCachedStorage(backend KeyPairStorage, cache KeyPairStorage) *CachedStorage {
	return &CachedStorage{
		cache:   cache,
		backend: backend,
	}
}
969279
func (c *Client) GetEvaluatedService(serviceID string, instanceID int) (*service.Service, string, string, error) {
	request := EvaluateServiceRequest{
		ServiceID:  serviceID,
		InstanceID: instanceID,
	}
	response := EvaluateServiceResponse{}
	err := c.call("GetEvaluatedService", request, &response)
	if err != nil {
		return nil, "", "", err
	}
	return &response.Service, response.TenantID, response.ServiceNamePath, err
}
138502
func (sc *serviceRegistryCache) GetRegistryForService(serviceID string) *serviceRegistry {
	registry, ok := sc.registry[serviceID]
	if !ok {
		registry = &serviceRegistry{
			ServiceID:   serviceID,
			PublicPorts: make(map[zkr.PublicPortKey]zkr.PublicPort, 0),
			VHosts:      make(map[zkr.VHostKey]zkr.VHost, 0),
		}
		sc.registry[serviceID] = registry
	}
	return registry
}
440946
func NewCachedKeyService(baseKeyService signed.CryptoService) signed.CryptoService {
	return &cachedKeyService{
		CryptoService: baseKeyService,
		lock:          &sync.RWMutex{},
		cachedKeys:    make(map[string]*cachedKey),
	}
}
793754
func (s *storeImpl) getUpdatedCacheEntries(since time.Time) []volatileService {
	s.serviceCacheLock.RLock()
	defer s.serviceCacheLock.RUnlock()

	logger := plog.WithFields(log.Fields{
		"since": since,
	})
	logger.Debug("Querying services updated since")

	cacheEntries := []volatileService{}
	for _, cacheEntry := range s.serviceCache {
		if cacheEntry.UpdatedAt.After(since) {
			logger.WithField("serviceid", cacheEntry.ID).Debug("Adding cache entry")
			cacheEntries = append(cacheEntries, cacheEntry)
		}
	}
	logger.WithField("count", len(cacheEntries)).Debug("Returning %d cached entries")
	return cacheEntries
}
383200
func (c *Client) GetService(serviceID string) (*service.Service, error) {
	svc := &service.Service{}
	err := c.call("GetService", serviceID, svc)
	return svc, err
}
1174229
func (i *injector) GetService(t reflect.Type) reflect.Value {
	v := i.services[t]

	if v.IsValid() {
		return returnService(v)
	}

	if t.Kind() == reflect.Interface {
		for tp, val := range i.services {
			if tp.Implements(t) {
				if val.IsValid() {
					return returnService(val)
				}
			}
		}
	}

	if i.parent != nil {
		v = i.parent.GetService(t)
	}

	return returnService(v)
}
1301225
func cacheKey(req *http.Request) string {
	if req.Method == http.MethodGet {
		return req.URL.String()
	} else {
		return req.Method + " " + req.URL.String()
	}
}
977121
func (s *serviceCache) allServices() []*v1.Service {
	s.mu.Lock()
	defer s.mu.Unlock()
	services := make([]*v1.Service, 0, len(s.serviceMap))
	for _, v := range s.serviceMap {
		services = append(services, v.state)
	}
	return services
}