@@ -14,7 +14,6 @@ import (
14
14
const (
15
15
defaultNamespaceCacheTTL = 2 * time .Minute
16
16
defaultNamespaceCacheSize = 100
17
- emptyNamespaceCacheTTL = 2 * time .Minute
18
17
defaultServiceIdCacheTTL = 2 * time .Minute
19
18
defaultServiceIdCacheSize = 1024
20
19
defaultEndpointsCacheTTL = 5 * time .Second
@@ -61,7 +60,7 @@ func NewServiceDiscoveryClient(cfg *aws.Config) ServiceDiscoveryClient {
61
60
62
61
func (sdc * serviceDiscoveryClient ) ListServices (ctx context.Context , nsName string ) (svcs []* model.Service , err error ) {
63
62
namespace , err := sdc .getNamespace (ctx , nsName )
64
- if err != nil || namespace . IsEmpty () {
63
+ if err != nil || namespace == nil {
65
64
return svcs , err
66
65
}
67
66
@@ -96,7 +95,7 @@ func (sdc *serviceDiscoveryClient) CreateService(ctx context.Context, nsName str
96
95
return err
97
96
}
98
97
99
- if namespace . IsEmpty () {
98
+ if namespace == nil {
100
99
// Create HttpNamespace if the namespace is not present in the CloudMap
101
100
namespace , err = sdc .createNamespace (ctx , nsName )
102
101
if err != nil {
@@ -234,10 +233,12 @@ func (sdc *serviceDiscoveryClient) listEndpoints(ctx context.Context, serviceId
234
233
235
234
func (sdc * serviceDiscoveryClient ) getNamespace (ctx context.Context , nsName string ) (namespace * model.Namespace , err error ) {
236
235
// We are assuming a unique namespace name per account
237
- exists , namespace , err := sdc .getCachedNamespace (nsName )
238
- if exists {
236
+ if namespace , exists , err := sdc .getCachedNamespace (nsName ); exists {
239
237
return namespace , err
240
238
}
239
+ if err != nil {
240
+ return nil , err
241
+ }
241
242
242
243
namespaces , err := sdc .sdApi .ListNamespaces (ctx )
243
244
if err != nil {
@@ -255,7 +256,7 @@ func (sdc *serviceDiscoveryClient) getNamespace(ctx context.Context, nsName stri
255
256
if namespace == nil {
256
257
// This will cache empty namespace for namespaces not in Cloud Map
257
258
// This is so that we can avoid ListNamespaces call
258
- namespace = sdc .cacheEmptyNamespace (nsName )
259
+ sdc .cacheNilNamespace (nsName )
259
260
}
260
261
261
262
return namespace , nil
@@ -269,7 +270,7 @@ func (sdc *serviceDiscoveryClient) getServiceId(ctx context.Context, nsName stri
269
270
}
270
271
271
272
namespace , err := sdc .getNamespace (ctx , nsName )
272
- if err != nil || namespace . IsEmpty () {
273
+ if err != nil || namespace == nil {
273
274
return "" , err
274
275
}
275
276
@@ -311,25 +312,26 @@ func (sdc *serviceDiscoveryClient) createNamespace(ctx context.Context, nsName s
311
312
return namespace , nil
312
313
}
313
314
314
- func (sdc * serviceDiscoveryClient ) getCachedNamespace (nsName string ) (exists bool , namespace * model.Namespace , err error ) {
315
+ func (sdc * serviceDiscoveryClient ) getCachedNamespace (nsName string ) (namespace * model.Namespace , exists bool , err error ) {
315
316
if cachedValue , exists := sdc .namespaceCache .Get (nsName ); exists {
317
+ if cachedValue == nil {
318
+ return nil , exists , nil
319
+ }
316
320
ns , ok := cachedValue .(model.Namespace )
317
321
if ! ok {
318
- return exists , nil , fmt .Errorf ("failed to cast the cached value for the namespace %s" , nsName )
322
+ return nil , exists , fmt .Errorf ("failed to cast the cached value for the namespace %s" , nsName )
319
323
}
320
- return exists , & ns , nil
324
+ return & ns , exists , nil
321
325
}
322
- return exists , nil , nil
326
+ return nil , exists , nil
323
327
}
324
328
325
329
func (sdc * serviceDiscoveryClient ) cacheNamespace (namespace model.Namespace ) {
326
330
sdc .namespaceCache .Add (namespace .Name , namespace , defaultNamespaceCacheTTL )
327
331
}
328
332
329
- func (sdc * serviceDiscoveryClient ) cacheEmptyNamespace (nsName string ) * model.Namespace {
330
- emptyNamespace := model .GetEmptyNamespace ()
331
- sdc .namespaceCache .Add (nsName , emptyNamespace , emptyNamespaceCacheTTL )
332
- return & emptyNamespace
333
+ func (sdc * serviceDiscoveryClient ) cacheNilNamespace (nsName string ) {
334
+ sdc .namespaceCache .Add (nsName , nil , defaultNamespaceCacheTTL )
333
335
}
334
336
335
337
func (sdc * serviceDiscoveryClient ) cacheServiceId (nsName string , svcName string , svcId string ) {
0 commit comments