Skip to content

Commit

Permalink
Merge pull request #15 from O1ahmad/ahmad/add_helm_release_setup
Browse files Browse the repository at this point in the history
feat: add Kubernetes/helm release setup logic
  • Loading branch information
O1ahmad authored Jun 25, 2024
2 parents 830ffd1 + f1db1b3 commit 572d670
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
meta/main.yml schema[meta]
tasks/common/download-binary.yml jinja[spacing]
tasks/systemd/setup.yml var-naming[no-role-prefix]
tasks/k8s/setup.yml no-changed-when
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ Systemd, [Docker SDK](https://docker-py.readthedocs.io/en/stable/) for Python (f
| _ports_ | listening port information for a service | `{}` |
| _dataDir_ | directory to store service runtime/operational data | `/tmp` |
| _restart_policy_ | service restart policy | `unless-stopped` |
| _cpus_ | available CPU resources each deployed service can use | `1.0` |
| _memory_ | available memory resources each deployed service can use | `4g` |

### Container

| var | description | default |
| :-------------: | :--------------------------------------------------------: | :--------------: |
| _image_ | service container image to deploy | ` ` |
| _resources.cpuLimit_ | limit of CPU resources each deployed service can use | `1.0` |
| _resources.memLimit_ | limit of memory resources each deployed service can use | `1G` |
| _resources.memRequest_ | requested memory resources each deployed service can use | `1G` |

### Systemd

Expand All @@ -49,7 +50,16 @@ Systemd, [Docker SDK](https://docker-py.readthedocs.io/en/stable/) for Python (f
| _binary_file_name_override_ | Override the binary file name after moving it to the destination directory | ` ` |
| _destination_directory_ | directory where the binary file will be placed after downloading/extracting | `/usr/local/bin` |
| _systemd_ | Systemd deployment custom unit, service and install properties | `{}` |
| _cpus_ | percentage of CPU resources each deployed service can use | `100%` |
| _memory_ | available memory resources each deployed service can use | `1G` |

### Kubernetes (k8s)

| var | description | default |
| :-------------: | :--------------------------------------------------------: | :--------------: |
| _helm_chart_path_ | path to Helm chart to use for the service deployment/release | `../../helm` |
| _helm_namespace_ | Kubernetes namespace to deploy to | `default` |
| _helm_values_path_ | file to load Helm chart values (see [here](./helm/README.md) for available values) | `values.yml` |

## Containerized Apps
- [O1 Containers](https://github.com/0x0I/containers)
Expand Down
19 changes: 14 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,38 @@ data_dirs: {}
# hostPath: /mnt/data
# appPath: /app/data

resources:
cpuLimit: 1
memRequest: 1G
memLimit: 1G

restart_policy: unless-stopped
uninstall: false
volume_list: []
port_list: []

### Container ###
image:
resources:
cpuLimit: 1
memRequest: 1G
memLimit: 1G

### Systemd ###
binary_url:
# (Optional) Override the binary file name after moving it to the destination directory
binary_file_name_override:

cpus: 100%
memory: 1G

systemd: {}
# unit_properties: {}
# service_properties: {}
# install_properties: {}

systemd_environment_directive: ""

### Kubernetes ###
helm_chart_path: ../../helm
helm_namespace: default
helm_values_path: values.yml

###

setup_iptables: false
4 changes: 3 additions & 1 deletion tasks/common/download-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
src: /tmp/{{ binary_file_name }}
dest: "{{ destination_directory }}"
remote_src: true
when: binary_file_name.endswith('.tar') or binary_file_name.endswith('.tar.gz') or binary_file_name.endswith('.tgz') or binary_file_name.endswith('.zip')
when: >
binary_file_name.endswith('.tar') or binary_file_name.endswith('.tar.gz') or
binary_file_name.endswith('.tgz') or binary_file_name.endswith('.zip')
- name: Move the file if it's not an archive

Check warning on line 27 in tasks/common/download-binary.yml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: mv /tmp/{{ binary_file_name }} {{ destination_directory }}/{{ binary_file_name_override|default(binary_file_name) }}
ansible.builtin.command: >
Expand Down
19 changes: 19 additions & 0 deletions tasks/k8s/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Ensure Helm is installed

Check warning on line 2 in tasks/k8s/setup.yml

View workflow job for this annotation

GitHub Actions / lint

no-changed-when

Commands should not change things if nothing needs doing.
ansible.builtin.command: helm version
register: helm_version
ignore_errors: true

- name: Install Helm if not installed
ansible.builtin.aptapt:
name: helm
state: present
when: helm_version.failed

- name: Deploy Helm chart
kubernetes.core.helm:
name: "{{ name }}"
chart_ref: "{{ helm_chart_path }}"
release_namespace: "{{ helm_namespace }}"
values_files:
- "{{ helm_values_path }}"

0 comments on commit 572d670

Please sign in to comment.