Skip to content

Commit 9095b4b

Browse files
authored
Update kubernetespodoperator (GoogleCloudPlatform#2270)
* Remove one example of a secret, chg param names * Remove one example of a secret, chg param names * Secret object region tags * Secret object region tags * Min region tag * Min region tag * Add more region tags * Add more region tags * Move region tag * Move region tag * remove region tags` * Fix linter issues
1 parent 543a565 commit 9095b4b

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

composer/workflows/kubernetes_pod_operator.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,31 @@
1616

1717
# [START composer_kubernetespodoperator]
1818
import datetime
19-
2019
from airflow import models
21-
# [END composer_kubernetespodoperator]
2220
from airflow.contrib.kubernetes import pod
2321
from airflow.contrib.kubernetes import secret
24-
# [START composer_kubernetespodoperator]
2522
from airflow.contrib.operators import kubernetes_pod_operator
2623

27-
# [END composer_kubernetespodoperator]
2824

2925
# A Secret is an object that contains a small amount of sensitive data such as
3026
# a password, a token, or a key. Such information might otherwise be put in a
3127
# Pod specification or in an image; putting it in a Secret object allows for
3228
# more control over how it is used, and reduces the risk of accidental
3329
# exposure.
34-
secret_file = secret.Secret(
35-
# Mounts the secret as a file in RAM-backed tmpfs.
36-
deploy_type='volume',
37-
# File path of where to deploy the target, since deploy_type is 'volume'
38-
# rather than 'env'.
39-
deploy_target='/etc/sql_conn',
40-
# Name of secret in Kubernetes, if the secret is not already defined in
41-
# Kubernetes using kubectl the Pod will fail to find the secret, and in
42-
# turn, fail to launch.
43-
secret='airflow-secrets',
44-
# Key of the secret within Kubernetes.
45-
key='sql_alchemy_conn')
4630

31+
# [START composer_kubernetespodoperator_secretobject]
4732
secret_env = secret.Secret(
4833
# Expose the secret as environment variable.
4934
deploy_type='env',
5035
# The name of the environment variable, since deploy_type is `env` rather
5136
# than `volume`.
5237
deploy_target='SQL_CONN',
38+
# Name of the Kubernetes Secret
5339
secret='airflow-secrets',
40+
# Key of a secret stored in this Secret object
5441
key='sql_alchemy_conn')
42+
# [END composer_kubernetespodoperator_secretobject]
5543

56-
# [START composer_kubernetespodoperator]
5744
YESTERDAY = datetime.datetime.now() - datetime.timedelta(days=1)
5845

5946
# If a Pod fails to launch, or has an error occur in the container, Airflow
@@ -69,6 +56,8 @@
6956
# no `config_file` parameter is specified. By default it will contain the
7057
# credentials for Cloud Composer's Google Kubernetes Engine cluster that is
7158
# created upon environment creation.
59+
60+
# [START composer_kubernetespodoperator_minconfig]
7261
kubernetes_min_pod = kubernetes_pod_operator.KubernetesPodOperator(
7362
# The ID specified for the task.
7463
task_id='pod-ex-minimum',
@@ -89,8 +78,8 @@
8978
# gcr.io images if the Composer Environment is under the same
9079
# project-id as the gcr.io images.
9180
image='gcr.io/gcp-runtimes/ubuntu_16_0_4')
92-
# [END composer_kubernetespodoperator]
93-
81+
# [END composer_kubernetespodoperator_minconfig]
82+
# [START composer_kubernetespodoperator_templateconfig]
9483
kubenetes_template_ex = kubernetes_pod_operator.KubernetesPodOperator(
9584
task_id='ex-kube-templates',
9685
name='ex-kube-templates',
@@ -113,23 +102,26 @@
113102
# setting the environment variable `MY_VALUE`. The pod will fail if
114103
# `my_value` is not set in the Airflow UI.
115104
env_vars={'MY_VALUE': '{{ var.value.my_value }}'},
116-
# Sets the config file to the specified airflow.cfg airflow home. If
117-
# the configuration file does not exist or does not provide valid
118-
# credentials the pod will fail to launch.
119-
config_file="{{ conf.get('core', 'airflow_home') }}/config")
120-
105+
# Sets the config file to a kubernetes config file specified in
106+
# airflow.cfg. If the configuration file does not exist or does
107+
# not provide validcredentials the pod will fail to launch. If not
108+
# specified, config_file defaults to ~/.kube/config
109+
config_file="{{ conf.get('core', 'kube_config') }}")
110+
# [END composer_kubernetespodoperator_templateconfig]
111+
# [START composer_kubernetespodoperator_secretconfig]
121112
kubernetes_secret_vars_ex = kubernetes_pod_operator.KubernetesPodOperator(
122113
task_id='ex-kube-secrets',
123114
name='ex-kube-secrets',
124115
namespace='default',
125116
image='ubuntu',
117+
startup_timeout_seconds=300,
126118
# The secrets to pass to Pod, the Pod will fail to create if the
127119
# secrets you specify in a Secret object do not exist in Kubernetes.
128-
secrets=[secret_env, secret_file],
120+
secrets=[secret_env],
129121
# env_vars allows you to specify environment variables for your
130122
# container to use. env_vars is templated.
131123
env_vars={'EXAMPLE_VAR': '/example/value'})
132-
124+
# [END composer_kubernetespodoperator_secretconfig]
133125
# [START composer_kubernetespodaffinity]
134126
kubernetes_affinity_ex = kubernetes_pod_operator.KubernetesPodOperator(
135127
task_id='ex-pod-affinity',
@@ -163,16 +155,16 @@
163155
# The label key's value that pods can be scheduled
164156
# on.
165157
'values': [
166-
'node-pool-name-1',
167-
'node-pool-name-2',
158+
'pool-0',
159+
'pool-1',
168160
]
169161
}]
170162
}]
171163
}
172164
}
173165
})
174166
# [END composer_kubernetespodaffinity]
175-
167+
# [START composer_kubernetespodoperator_fullconfig]
176168
kubernetes_full_pod = kubernetes_pod_operator.KubernetesPodOperator(
177169
task_id='ex-all-configs',
178170
name='pi',
@@ -221,3 +213,5 @@
221213
# config. For more information see:
222214
# https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
223215
affinity={})
216+
# [END composer_kubernetespodoperator_fullconfig]
217+
# [END composer_kubernetespodoperator]

0 commit comments

Comments
 (0)