Skip to content

Commit 39dff48

Browse files
irvifaTakashi Matsuo
and
Takashi Matsuo
authored
Add example of mounting secret as a volume in Google Composer. (#3379)
Co-authored-by: Takashi Matsuo <[email protected]>
1 parent a74ca46 commit 39dff48

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

composer/workflows/kubernetes_pod_operator.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
secret='airflow-secrets',
3939
# Key of a secret stored in this Secret object
4040
key='sql_alchemy_conn')
41+
secret_volume = secret.Secret(
42+
'volume',
43+
# Path where we mount the secret as volume
44+
'/var/secrets/google',
45+
# Name of Kubernetes Secret
46+
'service-account',
47+
# Key in the form of service account file name
48+
'service-account.json')
4149
# [END composer_kubernetespodoperator_secretobject]
4250

4351
YESTERDAY = datetime.datetime.now() - datetime.timedelta(days=1)
@@ -118,10 +126,12 @@
118126
startup_timeout_seconds=300,
119127
# The secrets to pass to Pod, the Pod will fail to create if the
120128
# secrets you specify in a Secret object do not exist in Kubernetes.
121-
secrets=[secret_env],
129+
secrets=[secret_env, secret_volume],
122130
# env_vars allows you to specify environment variables for your
123131
# container to use. env_vars is templated.
124-
env_vars={'EXAMPLE_VAR': '/example/value'})
132+
env_vars={
133+
'EXAMPLE_VAR': '/example/value',
134+
'GOOGLE_APPLICATION_CREDENTIALS': '/var/secrets/google/service-account.json'})
125135
# [END composer_kubernetespodoperator_secretconfig]
126136
# [START composer_kubernetespodaffinity]
127137
kubernetes_affinity_ex = kubernetes_pod_operator.KubernetesPodOperator(

0 commit comments

Comments
 (0)