Skip to content

Commit

Permalink
Add annotations parameter at the app (deployment/job/..) level
Browse files Browse the repository at this point in the history
  • Loading branch information
DilaraOflaz committed Jul 8, 2024
1 parent b9d828c commit 12c0b08
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
23 changes: 14 additions & 9 deletions kubetools/kubernetes/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ def generate_kubernetes_configs_for_project(
deployment_name=name,
default_registry=default_registry,
)
app_annotations = copy_and_update(base_annotations)
for container_name, data in containers.items():
app_annotations.update(data.get('annotations', {}))
app_annotations = copy_and_update(
base_annotations,
dependency.get('annotations', {}),
)

if container_ports:
services.append(make_service_config(
Expand Down Expand Up @@ -227,9 +228,8 @@ def generate_kubernetes_configs_for_project(
app_annotations = copy_and_update(
base_annotations,
per_deployment_annotations.get(name),
deployment.get('annotations', {}),
)
for container_name, data in containers.items():
app_annotations.update(data.get('annotations', {}))

if container_ports:
services.append(make_service_config(
Expand Down Expand Up @@ -298,12 +298,16 @@ def generate_kubernetes_configs_for_project(
node_selector_labels = job_spec.get('nodeSelector', None)
service_account_name = job_spec.get('serviceAccountName', None)
secrets = job_spec.get('secrets', None)
app_annotations = copy_and_update(
base_annotations,
job_spec.get('annotations', {}),
)

jobs.append(make_job_config(
job_spec,
app_name=project_name,
labels=job_labels,
annotations=base_annotations,
annotations=app_annotations,
envvars=job_envvars,
node_selector_labels=node_selector_labels,
service_account_name=service_account_name,
Expand All @@ -329,9 +333,10 @@ def generate_kubernetes_configs_for_project(
default_registry=default_registry,
)

app_annotations = copy_and_update(base_annotations)
for container_name, data in containers.items():
app_annotations.update(data.get('annotations', {}))
app_annotations = copy_and_update(
base_annotations,
cronjob.get('annotations', {}),
)

schedule = cronjob['schedule']
concurrency_policy = cronjob['concurrency_policy']
Expand Down
3 changes: 0 additions & 3 deletions kubetools/kubernetes/config/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ def make_container_config(
'readonly': True,
})

# Remove annotations from container data
if 'annotations' in container:
container.pop('annotations')
# Finally, attach all remaining data
container_data.update(container)

Expand Down
8 changes: 4 additions & 4 deletions tests/configs/basic_app/kubetools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ deployments:
httpGet:
path: /ping
generic-app-with-annotations:
annotations:
imageregistry: "https://hub.docker.com/"
containers:
webserver:
command: [uwsgi, --ini, /etc/uwsgi.conf]
Expand All @@ -36,8 +38,6 @@ deployments:
timeoutSeconds: 5
httpGet:
path: /ping
annotations:
imageregistry: "https://hub.docker.com/"


cronjobs:
Expand All @@ -48,10 +48,10 @@ cronjobs:
generic-container:
containerContext: generic-context
generic-cronjob-with-annotations:
annotations:
imageregistry: "https://hub.docker.com/"
schedule: "*/1 * * * *"
concurrency_policy: "Allow"
containers:
generic-container:
containerContext: generic-context
annotations:
imageregistry: "https://hub.docker.com/"
4 changes: 2 additions & 2 deletions tests/configs/dependencies/kubetools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ dependencies:
containerContext: memcache

memcache-with-annotations:
annotations:
imageregistry: https://hub.docker.com/
containers:
memcache-with-annotations:
containerContext: memcache
annotations:
imageregistry: https://hub.docker.com/

elasticsearch:
conditions:
Expand Down

0 comments on commit 12c0b08

Please sign in to comment.