@@ -46,6 +46,7 @@ def generate_deployment_specs(containers, outputdir):
46
46
for container in containers :
47
47
container_tag = containers [container ]['image' ]
48
48
container_port = get_container_port (containers [container ]['ports' ])
49
+ container_env = containers [container ]['environment' ] if 'environment' in containers [container ] else None
49
50
fin = open ("k8s-template.yaml" , "rt" )
50
51
deployment_file = "deployment-%s.yaml" % container
51
52
fout = open (outputdir + '/' + deployment_file , "wt" )
@@ -55,10 +56,50 @@ def generate_deployment_specs(containers, outputdir):
55
56
56
57
fin .close ()
57
58
fout .close ()
59
+
60
+ add_driver_environment_variables (outputdir , container_env , container )
61
+
58
62
# If there is a configmap-<driver>.yaml file, create a ConfigMap for it and add a volumeMounts mapping for it:
59
63
add_driver_configmap_volume (outputdir , container )
60
64
add_deployment (deployment_file , outputdir )
61
65
66
+ def add_driver_environment_variables (outputdir , container_env , container ):
67
+ """
68
+ If the container has environment variables defined in the docker-compose file,
69
+ add them here.
70
+ NOTE: This does not support variable substitution
71
+ """
72
+
73
+ deployment_file = "deployment-%s.yaml" % container
74
+ with open (outputdir + '/' + deployment_file , 'r' ) as infile :
75
+ input_deployment_contents = infile .read ()
76
+
77
+ configmap_filename = 'configmap-%s.yaml' % container
78
+ configmap_path = '/app-specs/%s' % configmap_filename
79
+
80
+ if container_env is None :
81
+ print ('No environment variables found for driver ' + container )
82
+ output_deployment_contents = input_deployment_contents .replace ('{{environmentVariables}}' , '' )
83
+ else :
84
+ print ('Environment variables found for driver ' + container + ' . Adding environment to the deployment yaml.' )
85
+
86
+ # Write the environment definition to the driver Deployment spec:
87
+ env_txt = 'env:\n '
88
+
89
+ for env_var in container_env :
90
+ env_txt += ' - name: %s\n ' % env_var
91
+ env_txt += ' value: %s\n ' % container_env [env_var ]
92
+
93
+ print (env_txt )
94
+
95
+ output_deployment_contents = input_deployment_contents .replace ('{{environmentVariables}}' , env_txt )
96
+
97
+ # tmp
98
+ print (output_deployment_contents )
99
+
100
+ with open (outputdir + '/' + deployment_file , 'w' ) as outfile :
101
+ outfile .write (output_deployment_contents )
102
+
62
103
def add_driver_configmap_volume (outputdir , container ):
63
104
"""
64
105
If there is a file named /app-specs/configmap-<container>.yaml for this driver,
0 commit comments