Skip to content
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

Make cloudsql-proxy into a proper sidecar container #588

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/resourcecreator/google/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func CloudSqlProxyContainer(port int32, googleCloudSQLProxyContainerImage, proje
Name: "cloudsql-proxy",
Image: googleCloudSQLProxyContainerImage,
ImagePullPolicy: corev1.PullIfNotPresent,
RestartPolicy: ptr.To(corev1.ContainerRestartPolicyAlways),
Ports: []corev1.ContainerPort{{
ContainerPort: port,
Protocol: corev1.ProtocolTCP,
Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcecreator/google/sql/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func CreateInstance(source Source, ast *resource.Ast, cfg Config) error {

if needsCloudSqlProxyContainer {
cloudSqlProxyContainer := google.CloudSqlProxyContainer(5432, cfg.GetGoogleCloudSQLProxyContainerImage(), googleTeamProjectID, googleSqlInstance.Name)
ast.Containers = append(ast.Containers, cloudSqlProxyContainer)
ast.InitContainers = append(ast.InitContainers, cloudSqlProxyContainer)
}

return nil
Expand Down Expand Up @@ -311,4 +311,4 @@ func CreateSqlSSLCertResource(ast *resource.Ast, instanceName string, source Sou
ast.VolumeMounts = append(ast.VolumeMounts, pod.FromFilesVolumeMount(sqeletorVolumeName, nais_io_v1alpha1.DefaultSqeletorMountPath, "", true))

ast.AppendOperation(resource.OperationCreateIfNotExists, sqlSSLCert)
}
}
2 changes: 2 additions & 0 deletions pkg/resourcecreator/testdata/gcp_database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ tests:
value: team-project-id
- name: GCP_TEAM_PROJECT_ID
value: team-project-id
initContainers:
- name: cloudsql-proxy
command:
- /cloud-sql-proxy
Expand All @@ -242,6 +243,7 @@ tests:
cpu: 50m
memory: 32Mi
imagePullPolicy: IfNotPresent
restartPolicy: Always
securityContext:
allowPrivilegeEscalation: false
runAsUser: 2
2 changes: 2 additions & 0 deletions pkg/resourcecreator/testdata/gcp_database_private_ip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ tests:
value: team-project-id
- name: GCP_TEAM_PROJECT_ID
value: team-project-id
initContainers:
- name: cloudsql-proxy
command:
- /cloud-sql-proxy
Expand All @@ -201,6 +202,7 @@ tests:
cpu: 50m
memory: 32Mi
imagePullPolicy: IfNotPresent
restartPolicy: Always
securityContext:
allowPrivilegeEscalation: false
runAsUser: 2
2 changes: 2 additions & 0 deletions pkg/resourcecreator/testdata/gcp_database_with_insights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ tests:
value: team-project-id
- name: GCP_TEAM_PROJECT_ID
value: team-project-id
initContainers:
- name: cloudsql-proxy
command:
- /cloud-sql-proxy
Expand All @@ -234,6 +235,7 @@ tests:
protocol: TCP
resources: {}
imagePullPolicy: IfNotPresent
restartPolicy: Always
securityContext:
allowPrivilegeEscalation: false
runAsUser: 2
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ tests:
value: team-project-id
- name: GCP_TEAM_PROJECT_ID
value: team-project-id
initContainers:
- name: cloudsql-proxy
command:
- /cloud-sql-proxy
Expand All @@ -221,3 +222,4 @@ tests:
ports:
- containerPort: 5432
protocol: TCP
restartPolicy: Always
4 changes: 3 additions & 1 deletion pkg/synchronizer/synchronizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ func TestSynchronizerResourceOptions(t *testing.T) {
err = rig.client.Get(ctx, req.NamespacedName, deploy)
assert.NoError(t, err)
expectedInstanceName := fmt.Sprintf("%s:%s:%s", testProjectId, google.Region, app.Name)
assert.Equal(t, expectedInstanceName, deploy.Spec.Template.Spec.Containers[1].Command[6])
cloudsqlProxyContainer := deploy.Spec.Template.Spec.InitContainers[0]
actualInstanceNameFromCommand := cloudsqlProxyContainer.Command[6]
assert.Equal(t, expectedInstanceName, actualInstanceNameFromCommand)

err = rig.client.Get(ctx, req.NamespacedName, sqlinstance)
assert.NoError(t, err)
Expand Down