---
#deployment tasks for gitea

- name: Create a namespace for gitea
  k8s:
    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
    name: "{{apps.gitea.namespace}}"
    api_version: v1
    kind: Namespace
    state: "{{apps.gitea.state}}"
  become: true

- name: create persistent volume resources
  kubernetes.core.k8s:
    kubeconfig: "/etc/rancher/k3s/k3s.yaml"
    state: "{{apps.gitea.state}}"
    definition: "{{ lookup('template', item) | from_yaml }}"
  loop:
    - gitea/pv.yaml
    - gitea/pv-claim.yaml
  become: true


- name: Install gitea globally available
  block:
    - name: Add gitea chart helm repo
      local_action:
        module: kubernetes.core.helm_repository
        name: gitea-charts
        repo_url: https://dl.gitea.io/charts/

    - name: load variables files/gitea/values.yaml
      ansible.builtin.include_vars:
        file: files/gitea/values.yaml
        name: release_values

    - name: Install gitea Release
      local_action:
        module: kubernetes.core.helm
        release_state: "{{apps.gitea.state}}"
        name: gitea
        namespace: "{{apps.gitea.namespace}}"
        create_namespace: yes
        update_repo_cache: True
        chart_ref: gitea-charts/gitea
        values: "{{release_values}}"
        wait: true
