Skip to content

Commit

Permalink
Add Vault agent annotation 'log-format' (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejvanderzee authored Feb 1, 2021
1 parent 3e98362 commit 40b3854
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions agent-inject/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ type Vault struct {
// LogLevel sets the Vault Agent log level. Defaults to info.
LogLevel string

// LogFormat sets the Vault Agent log format. Defaults to standard.
LogFormat string

// Namespace is the Vault namespace to prepend to secret paths.
Namespace string

Expand Down Expand Up @@ -249,6 +252,7 @@ func New(pod *corev1.Pod, patches []*jsonpatch.JsonPatchOperation) (*Agent, erro
ClientMaxRetries: pod.Annotations[AnnotationVaultClientMaxRetries],
ClientTimeout: pod.Annotations[AnnotationVaultClientTimeout],
LogLevel: pod.Annotations[AnnotationVaultLogLevel],
LogFormat: pod.Annotations[AnnotationVaultLogFormat],
Namespace: pod.Annotations[AnnotationVaultNamespace],
Role: pod.Annotations[AnnotationVaultRole],
TLSSecret: pod.Annotations[AnnotationVaultTLSSecret],
Expand Down
7 changes: 7 additions & 0 deletions agent-inject/agent/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ const (
// AnnotationVaultLogLevel sets the Vault Agent log level.
AnnotationVaultLogLevel = "vault.hashicorp.com/log-level"

// AnnotationVaultLogFormat sets the Vault Agent log format.
AnnotationVaultLogFormat = "vault.hashicorp.com/log-format"

// AnnotationVaultRole specifies the role to be used for the Kubernetes auto-auth
// method.
AnnotationVaultRole = "vault.hashicorp.com/role"
Expand Down Expand Up @@ -290,6 +293,10 @@ func Init(pod *corev1.Pod, cfg AgentConfig) error {
pod.ObjectMeta.Annotations[AnnotationVaultLogLevel] = DefaultAgentLogLevel
}

if _, ok := pod.ObjectMeta.Annotations[AnnotationVaultLogFormat]; !ok {
pod.ObjectMeta.Annotations[AnnotationVaultLogFormat] = DefaultAgentLogFormat
}

if _, securityContextIsSet = pod.ObjectMeta.Annotations[AnnotationAgentSetSecurityContext]; !securityContextIsSet {
pod.ObjectMeta.Annotations[AnnotationAgentSetSecurityContext] = strconv.FormatBool(cfg.SetSecurityContext)
}
Expand Down
8 changes: 8 additions & 0 deletions agent-inject/agent/container_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"encoding/base64"

corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -31,6 +32,13 @@ func (a *Agent) ContainerEnvVars(init bool) ([]corev1.EnvVar, error) {
})
}

if a.Vault.LogFormat != "" {
envs = append(envs, corev1.EnvVar{
Name: "VAULT_LOG_FORMAT",
Value: a.Vault.LogFormat,
})
}

if a.ConfigMapName == "" {
config, err := a.newConfig(init)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions agent-inject/agent/container_sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
DefaultContainerArg = "echo ${VAULT_CONFIG?} | base64 -d > /home/vault/config.json && vault agent -config=/home/vault/config.json"
DefaultRevokeGrace = 5
DefaultAgentLogLevel = "info"
DefaultAgentLogFormat = "standard"
)

// ContainerSidecar creates a new container to be added
Expand Down

0 comments on commit 40b3854

Please sign in to comment.