-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vault sidecar type annotation #496
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liad5h Thank you for taking this on and being patient! The PR is generally on a good path :). I have some change requests. I'm happy to sync up and help out with addressing them if you need.
Would you mind dropping a small description in the PR and something like below in CHANGELOG.md under Unreleased?
Improvements:
* Add support to configure sidecar type (proxy or agent) and proxy's auto auth token use through Pod Annotations [GH-496](https://github.com/hashicorp/vault-k8s/pull/496)
@@ -809,7 +809,7 @@ func TestConfigTelemetry(t *testing.T) { | |||
"vault.hashicorp.com/agent-telemetry-stackdriver_location": "useast-1", | |||
"vault.hashicorp.com/agent-telemetry-stackdriver_namespace": "foo", | |||
"vault.hashicorp.com/agent-telemetry-stackdriver_debug_logs": "false", | |||
"vault.hashicorp.com/agent-telemetry-prefix_filter": `["+vault.token", "-vault.expire", "+vault.expire.num_leases"]`, | |||
"vault.hashicorp.com/agent-telemetry-prefix_filter": `["+vault.token", "-vault.expire", "+vault.expire.num_leases"]`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert the accidental space?
@@ -884,3 +894,24 @@ func (a *Agent) authConfig() map[string]interface{} { | |||
|
|||
return authConfig | |||
} | |||
|
|||
func (a *Agent) sidecarType() string { | |||
if a.SidecarType != "" && !(a.SidecarType == "agent" || a.SidecarType == "proxy") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a.SidecarType != "" && !(a.SidecarType == "agent" || a.SidecarType == "proxy") { | |
if a.SidecarType != "" && (a.SidecarType == "agent" || a.SidecarType == "proxy") { |
I think you meant if a.SidecarType
is not empty, and a.SidecarType
is "agent" or "proxy", then return a.SidecarType
?
arg := fmt.Sprintf(DefaultContainerArg, agent.SidecarType) | ||
if container.Args[0] != arg { | ||
t.Errorf("arg value wrong, should have been %s, got %s", arg, container.Args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add a similar assertion for agent.ProxyUseAutoAuthToken
?
@@ -285,8 +285,9 @@ func TestContainerSidecar(t *testing.T) { | |||
t.Errorf("wrong number of args, got %d, should have been %d", len(container.Args), 1) | |||
} | |||
|
|||
if container.Args[0] != DefaultContainerArg { | |||
t.Errorf("arg value wrong, should have been %s, got %s", DefaultContainerArg, container.Args[0]) | |||
arg := fmt.Sprintf(DefaultContainerArg, agent.SidecarType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add different test cases under TestContainerSidecar()
to test varying annotation sets containing 2 new annotations?
vault-k8s/agent-inject/agent/annotations.go
Lines 20 to 28 in 412e109
// AnnotationAgentSidecarType is the key of the annotation that controls whether | |
// a Vault agent or Vault proxy is injected into the pod | |
// Should be set to one of "agent" / "proxy", defaults to "agent". | |
AnnotationAgentSidecarType = "vault.hashicorp.com/sidecar-type" | |
// AnnotationAgentProxyUseAutoAuthToken is the key of the annotation that controls whether | |
// the auto auth token should be used in the vault proxy. | |
// configures the "use_auto_auth_token" key in the "api_proxy" stanza. | |
AnnotationAgentProxyUseAutoAuthToken = "vault.hashicorp.com/sidecar-proxy-use-auto-auth-token" |
vault-k8s/agent-inject/agent/container_sidecar_test.go
Lines 210 to 216 in 412e109
func TestContainerSidecar(t *testing.T) { | |
annotations := map[string]string{ | |
AnnotationVaultRole: "foobar", | |
} | |
pod := testPod(annotations) | |
No description provided.