|
14 | 14 | package cache |
15 | 15 |
|
16 | 16 | import ( |
17 | | - "os" |
18 | 17 | "time" |
19 | 18 |
|
20 | 19 | "github.com/go-logr/logr" |
| 20 | + "github.com/jaypipes/envutil" |
21 | 21 | kubernetes "k8s.io/client-go/kubernetes" |
22 | 22 | ) |
23 | 23 |
|
24 | 24 | const ( |
25 | | - // defaultNamespace is the default namespace to use if the environment |
26 | | - // variable NAMESPACE is not found. The NAMESPACE variable is injected |
27 | | - // using the kubernetes downward api. |
28 | | - defaultNamespace = "ack-system" |
| 25 | + // envVarACKSystemNamespace is the string key for the environment variable |
| 26 | + // storing the Kubernetes Namespace we use for ConfigMaps and other ACK |
| 27 | + // system configuration needs. |
| 28 | + envVarACKSystemNamespace = "ACK_SYSTEM_NAMESPACE" |
| 29 | + |
| 30 | + // envVarDeprecatedK8sNamespace is the string key for the old, deprecated |
| 31 | + // environment variable storing the Kubernetes Namespace we use for |
| 32 | + // ConfigMaps and other ACK system configuration needs. |
| 33 | + envVarDeprecatedK8sNamespace = "K8S_NAMESPACE" |
| 34 | + |
| 35 | + // defaultACKSystemNamespace is the namespace we look up the CARM account |
| 36 | + // map ConfigMap in if the environment variable ACK_SYSTEM_NAMESPACE is not |
| 37 | + // found. |
| 38 | + defaultACKSystemNamespace = "ack-system" |
29 | 39 |
|
30 | 40 | // informerDefaultResyncPeriod is the period at which ShouldResync |
31 | 41 | // is considered. |
| 42 | + // NOTE(jaypipes): setting this to zero means we are telling the client-go |
| 43 | + // caching system not to set up resyncs with an authoritative state source |
| 44 | + // (i.e. a Kubernetes API server) on a periodic basis. |
32 | 45 | informerResyncPeriod = 0 * time.Second |
33 | 46 | ) |
34 | 47 |
|
35 | | -// currentNamespace is the namespace in which the current service |
36 | | -// controller Pod is running |
37 | | -var currentNamespace string |
| 48 | +// ackSystemNamespace is the namespace in which we look up ACK system |
| 49 | +// configuration (ConfigMaps, etc) |
| 50 | +var ackSystemNamespace string |
38 | 51 |
|
39 | 52 | func init() { |
40 | | - currentNamespace = os.Getenv("K8S_NAMESPACE") |
41 | | - if currentNamespace == "" { |
42 | | - currentNamespace = defaultNamespace |
43 | | - } |
| 53 | + ackSystemNamespace = envutil.WithDefault( |
| 54 | + envVarACKSystemNamespace, envutil.WithDefault( |
| 55 | + envVarDeprecatedK8sNamespace, |
| 56 | + defaultACKSystemNamespace, |
| 57 | + ), |
| 58 | + ) |
44 | 59 | } |
45 | 60 |
|
46 | 61 | // Caches is used to interact with the different caches |
|
0 commit comments