Skip to content

Commit

Permalink
Envoy PreStop hook support (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
achevuru authored Jul 15, 2020
1 parent af405b4 commit f5aecef
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/inject/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
flagSidecarMemoryRequests = "sidecar-memory-requests"
flagPreview = "preview"
flagLogLevel = "sidecar-log-level"
flagPreStopDelay = "prestop-delay"

flagInitImage = "init-image"
flagIgnoredIPs = "ignored-ips"
Expand Down Expand Up @@ -42,6 +43,7 @@ type Config struct {
SidecarMemory string
Preview bool
LogLevel string
PreStopDelay string

// Init container settings
InitImage string
Expand Down Expand Up @@ -83,6 +85,8 @@ func (cfg *Config) BindFlags(fs *pflag.FlagSet) {
"Enable preview channel")
fs.StringVar(&cfg.LogLevel, flagLogLevel, "info",
"AWS App Mesh envoy log level")
fs.StringVar(&cfg.PreStopDelay, flagPreStopDelay, "20",
"AWS App Mesh envoy preStop hook sleep duration")
fs.StringVar(&cfg.InitImage, flagInitImage, "111345817488.dkr.ecr.us-west-2.amazonaws.com/aws-appmesh-proxy-route-manager:v2",
"Init container image.")
fs.StringVar(&cfg.IgnoredIPs, flagIgnoredIPs, "169.254.169.254",
Expand Down
14 changes: 14 additions & 0 deletions pkg/inject/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ const envoyContainerTemplate = `
"protocol": "TCP"
}
],
"lifecycle": {
"preStop": {
"exec": {
"command": [
"sh",
"-c",
"sleep {{.PreStopDelay}}"
]
}
}
},
"env": [
{
"name": "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -82,6 +93,7 @@ type EnvoyTemplateVariables struct {
VirtualNodeName string
Preview string
LogLevel string
PreStopDelay string
SidecarImage string
SidecarCPURequests string
SidecarMemoryRequests string
Expand All @@ -98,6 +110,7 @@ type envoyMutatorConfig struct {
awsRegion string
preview bool
logLevel string
preStopDelay string
sidecarImage string
sidecarCPURequests string
sidecarMemoryRequests string
Expand Down Expand Up @@ -156,6 +169,7 @@ func (m *envoyMutator) buildTemplateVariables(pod *corev1.Pod) EnvoyTemplateVari
VirtualNodeName: virtualNodeName,
Preview: preview,
LogLevel: m.mutatorConfig.logLevel,
PreStopDelay: m.mutatorConfig.preStopDelay,
SidecarImage: m.mutatorConfig.sidecarImage,
SidecarCPURequests: getSidecarCPURequest(m.mutatorConfig.sidecarCPURequests, pod),
SidecarMemoryRequests: getSidecarMemoryRequest(m.mutatorConfig.sidecarMemoryRequests, pod),
Expand Down
73 changes: 73 additions & 0 deletions pkg/inject/envoy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -103,6 +104,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -141,6 +150,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: true,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -173,6 +183,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -211,6 +229,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -244,6 +263,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -286,6 +313,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -319,6 +347,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -367,6 +403,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -400,6 +437,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -448,6 +493,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -481,6 +527,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -523,6 +577,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -556,6 +611,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -598,6 +661,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down Expand Up @@ -649,6 +713,14 @@ func Test_envoyMutator_mutate(t *testing.T) {
Protocol: "TCP",
},
},
Lifecycle: &corev1.Lifecycle{
PostStart: nil,
PreStop: &corev1.Handler{
Exec: &corev1.ExecAction{Command: []string{
"sh", "-c", "sleep 20",
}},
},
},
Env: []corev1.EnvVar{
{
Name: "APPMESH_VIRTUAL_NODE_NAME",
Expand Down Expand Up @@ -717,6 +789,7 @@ func Test_envoyMutator_mutate(t *testing.T) {
awsRegion: "us-west-2",
preview: false,
logLevel: "debug",
preStopDelay: "20",
sidecarImage: "envoy:v2",
sidecarCPURequests: cpuRequests.String(),
sidecarMemoryRequests: memoryRequests.String(),
Expand Down
1 change: 1 addition & 0 deletions pkg/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (m *SidecarInjector) injectAppMeshPatches(ms *appmesh.Mesh, vn *appmesh.Vir
awsRegion: m.awsRegion,
preview: m.config.Preview,
logLevel: m.config.LogLevel,
preStopDelay: m.config.PreStopDelay,
sidecarImage: m.config.SidecarImage,
sidecarCPURequests: m.config.SidecarCpu,
sidecarMemoryRequests: m.config.SidecarMemory,
Expand Down

0 comments on commit f5aecef

Please sign in to comment.