Skip to content

Commit

Permalink
Make namespace configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Florianisme committed Dec 15, 2024
1 parent 651b9c5 commit 21f2d53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ This is what the output of another Pod's startup event would look like:
## Configuration
The application is configurable via the environment variables:

| Environment Variable | Description | Default Value |
|:--------------------:|------------------------------------------------------------------|:-------------:|
| TZ | Timezone of the logged event's timestamp (UTC for example) | |
| LOG_LEVEL | The application's internal logging level (not related to events) | INFO |
| Environment Variable | Description | Default Value |
|:--------------------:|-----------------------------------------------------------------------------------------------------------------------------------------------------|:-------------:|
| TZ | Timezone of the logged event's timestamp (UTC for example) | UTC |
| NAMESPACE | Namespace in which this application is running. If not set, tries to detect it automatically from the injected environment variable "POD_NAMESPACE" | event-logging |
| LOG_LEVEL | The application's internal logging level (not related to events) | INFO |
18 changes: 17 additions & 1 deletion persistence/timestamp_persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"os"
"strconv"
"time"
)

var namespace = "event-logging"
var namespace string
var timestampConfigMapName = "timestamp"

type TimestampPersister struct {
Expand All @@ -22,6 +23,7 @@ type TimestampPersister struct {
}

func Init(client *kubernetes.Clientset, logger *logging.Logger) *TimestampPersister {
namespace = getConfiguredNamespace()
configMap, err := getConfigMap(client)
var currentTimestamp time.Time

Expand Down Expand Up @@ -59,6 +61,20 @@ func Init(client *kubernetes.Clientset, logger *logging.Logger) *TimestampPersis
return persister
}

// getConfiguredNamespace returns the namespace in which the ConfigMap should be updated.
// It returns the value in the following priority order:
// Environment variable "POD_NAMESPACE", Environment variable "NAMESPACE" or else "event-logging" by default
func getConfiguredNamespace() string {
if podNamespace, isSet := os.LookupEnv("POD_NAMESPACE"); isSet {
return podNamespace
}
if namespace, isSet := os.LookupEnv("NAMESPACE"); isSet {
return namespace
}

return "event-logging"
}

func (s *TimestampPersister) runScheduledUpdates() {
for {
select {
Expand Down

0 comments on commit 21f2d53

Please sign in to comment.