diff --git a/contents/job-create.py b/contents/job-create.py index 27f76d1..04fd5d9 100644 --- a/contents/job-create.py +++ b/contents/job-create.py @@ -25,16 +25,31 @@ def create_job_object(data): annotations = None if "annotations" in data: - annotations_array = data["annotations"].split(',') - annotations = dict(s.split('=') for s in annotations_array) + annotations = yaml.full_load(data["annotations"]) meta.annotations = annotations envs = [] if "environments" in data: - envs_array = data["environments"].splitlines() - tmp_envs = dict(s.split('=', 1) for s in envs_array) - for key in tmp_envs: - envs.append(client.V1EnvVar(name=key, value=tmp_envs[key])) + env_data = yaml.full_load(data["environments"]) + for item in env_data: + if 'value' in item.keys(): + envs.append(client.V1EnvVar( + name = item['name'], + value = item['value']) + ) + elif 'valueFrom' in item.keys(): + if 'fieldRef' in item['valueFrom'].keys(): + envs.append( + client.V1EnvVar( + name = item['name'], + value_from = client.V1EnvVarSource( + field_ref = client.V1ObjectFieldSelector( + field_path=item['valueFrom']['fieldRef']['fieldPath'] + ) + ) + ) + ) + if "environments_secrets" in data: envs_array = data["environments_secrets"].splitlines() @@ -62,6 +77,32 @@ def create_job_object(data): ) ) + if "environments_configs" in data: + envs_array = data["environments_configs"].splitlines() + tmp_envs = dict(s.split('=', 1) for s in envs_array) + + for key in tmp_envs: + + if (":" in tmp_envs[key]): + # passing config env + value = tmp_envs[key] + configs = value.split(':') + config_key = configs[1] + config_name = configs[0] + + envs.append( + client.V1EnvVar( + name=key, + value="", + value_from=client.V1EnvVarSource( + config_map_key_ref=client.V1ConfigMapKeySelector( + key=config_key, + name=config_name + ) + ) + ) + ) + container = client.V1Container(name=data["container_name"], image=data["container_image"], image_pull_policy=data["image_pull_policy"] @@ -260,6 +301,10 @@ def main(): esecret = os.environ.get('RD_CONFIG_ENVIRONMENTS_SECRETS') data["environments_secrets"] = esecret + if os.environ.get('RD_CONFIG_ENVIRONMENTS_CONFIGS'): + config = os.environ.get('RD_CONFIG_ENVIRONMENTS_CONFIGS') + data["environments_configs"] = config + if os.environ.get('RD_CONFIG_IMAGEPULLSECRETS'): data["image_pull_secrets"] = os.environ.get('RD_CONFIG_IMAGEPULLSECRETS') diff --git a/plugin.yaml b/plugin.yaml index bd20da4..b075ea4 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1420,10 +1420,12 @@ providers: - name: annotations type: String title: "Annotations" - description: "Annotations. Add a comma separeted values (key=value format)" + description: "Annotations. Configure in YAML format " required: false renderingOptions: groupName: Metadata + displayType: MULTI_LINE + codeSyntaxMode: yaml - name: selectors type: String title: "Selectors" @@ -1515,11 +1517,12 @@ providers: - name: environments type: String title: "Environment Variables" - description: "List Environment Variables (key=value format)" + description: "List Environment Variables in YAML format" required: false renderingOptions: groupName: Container displayType: MULTI_LINE + codeSyntaxMode: yaml - name: environments_secrets type: String title: "Environment Variables from secret" @@ -1528,6 +1531,14 @@ providers: renderingOptions: groupName: Container displayType: MULTI_LINE + - name: environments_configs + type: String + title: "Environment Variables from config" + description: "List Environment Variables from configs variables. Use key=config-Name:config-Key-Name format" + required: false + renderingOptions: + groupName: Container + displayType: MULTI_LINE - name: env_from type: String title: "EnvFrom"