Skip to content

Commit

Permalink
feat: Configure proxy pod to exit 0 on SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
hessjcg committed Sep 14, 2023
1 parent e4d0382 commit 46070ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions internal/workload/podspec_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ const (
// DefaultHealthCheckPort is the used by the proxy to expose prometheus
// and kubernetes health checks.
DefaultHealthCheckPort int32 = 9801

// DefaultAdminPort is the used by the proxy to expose prometheus
// and kubernetes health checks.
DefaultAdminPort int32 = 9802
)

var l = logf.Log.WithName("internal.workload")
Expand Down Expand Up @@ -815,6 +811,9 @@ func (s *updateState) addHealthCheck(p *cloudsqlapi.AuthProxyWorkload, c *corev1
s.addProxyContainerEnvVar(p, "CSQL_PROXY_HTTP_PORT", fmt.Sprintf("%d", port))
s.addProxyContainerEnvVar(p, "CSQL_PROXY_HTTP_ADDRESS", "0.0.0.0")
s.addProxyContainerEnvVar(p, "CSQL_PROXY_HEALTH_CHECK", "true")
// For graceful exits as a sidecar, the proxy should exit with exit code 0
// when it receives a SIGTERM.
s.addProxyContainerEnvVar(p, "CSQL_PROXY_EXIT_ZERO_ON_SIGTERM", "true")
}

func (s *updateState) addAdminServer(p *cloudsqlapi.AuthProxyWorkload) {
Expand Down
13 changes: 6 additions & 7 deletions internal/workload/podspec_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,12 @@ func TestProxyCLIArgs(t *testing.T) {
}},
},
wantWorkloadEnv: map[string]string{
"CSQL_PROXY_STRUCTURED_LOGS": "true",
"CSQL_PROXY_HEALTH_CHECK": "true",
"CSQL_PROXY_HTTP_PORT": fmt.Sprintf("%d", workload.DefaultHealthCheckPort),
"CSQL_PROXY_HTTP_ADDRESS": "0.0.0.0",
"CSQL_PROXY_USER_AGENT": "cloud-sql-proxy-operator/dev",
"CSQL_PROXY_STRUCTURED_LOGS": "true",
"CSQL_PROXY_HEALTH_CHECK": "true",
"CSQL_PROXY_EXIT_ZERO_ON_SIGTERM": "true",
"CSQL_PROXY_HTTP_PORT": fmt.Sprintf("%d", workload.DefaultHealthCheckPort),
"CSQL_PROXY_HTTP_ADDRESS": "0.0.0.0",
"CSQL_PROXY_USER_AGENT": "cloud-sql-proxy-operator/dev",
},
},
{
Expand Down Expand Up @@ -691,7 +692,6 @@ func TestProxyCLIArgs(t *testing.T) {
},
},
{
desc: "No admin port enabled when AdminServerSpec is nil",
proxySpec: cloudsqlapi.AuthProxyWorkloadSpec{
AuthProxyContainer: &cloudsqlapi.AuthProxyContainerSpec{},
Instances: []cloudsqlapi.InstanceSpec{{
Expand All @@ -705,7 +705,6 @@ func TestProxyCLIArgs(t *testing.T) {
wantWorkloadEnv: map[string]string{
"CSQL_PROXY_HEALTH_CHECK": "true",
},
dontWantEnvSet: []string{"CSQL_PROXY_DEBUG", "CSQL_PROXY_ADMIN_PORT"},
},
{
desc: "port conflict with other instance causes error",
Expand Down

0 comments on commit 46070ad

Please sign in to comment.