Skip to content
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
57 changes: 51 additions & 6 deletions contents/job-create.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@ def create_job_object(data):

annotations = None
if "annotations" in data:
annotations_array = data["annotations"].split(',')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be better to keep this code to not break old jobs (maybe if the yaml parse failed, try with this)

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()
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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')

Expand Down
15 changes: 13 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down