---

- include_tasks: update_meteringconfig_status.yml
  vars:
    current_conditions:
      type: "Running"
      status: "True"
      message: "Reconciling Presto resources"
      lastTransitionTime: "{{ now(utc=False).isoformat() + 'Z' }}"

- name: Log event for reconciling the Presto resources
  k8s_event:
    state: present
    name: metering-operator-reconciling-presto
    namespace: "{{ meta.namespace }}"
    message: Reconciling Presto resources
    reason: Reconciling
    type: Normal
    source:
      component: metering-ansible-operator
    involvedObject:
      apiVersion: metering.openshift.io
      kind: MeteringConfig
      name: "{{ meta.name }}"
      namespace: "{{ meta.namespace }}"

- name: Deploy presto resources
  include_tasks: deploy_resources.yml
  vars:
    values_file: /tmp/metering-values.yaml
    resources:
      - template_file: templates/presto/presto-aws-credentials-secret.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-aws-credentials-secret
        create: "{{ meteringconfig_create_presto_aws_credentials }}"
      - template_file: templates/presto/presto-azure-credentials-secret.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-azure-credentials-secret
        create: "{{ meteringconfig_create_presto_azure_credentials }}"
      - template_file: templates/presto/presto-gcs-credentials-secret.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-gcs-credentials-secret
        create: "{{ meteringconfig_create_presto_gcs_credentials }}"
      - template_file: templates/presto/presto-s3-compatible-credentials-secret.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-s3-compatible-credentials-secret
        create: "{{ meteringconfig_create_presto_s3_compatible_credentials }}"
      - template_file: templates/presto/presto-s3-compatible-ca-secret.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-s3-compatible-ca-secret
        create: "{{ meteringconfig_create_presto_s3_compatible_ca }}"
      - template_file: templates/presto/presto-tls-secrets.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-tls-secrets
        create: "{{ meteringconfig_create_presto_tls_secrets }}"
      - template_file: templates/presto/presto-auth-secrets.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-auth-secrets
        create: "{{ meteringconfig_create_presto_auth_secrets }}"
      - template_file: templates/presto/presto-hive-metastore-tls-secrets.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-hive-metastore-tls-secrets
        create: "{{ meteringconfig_create_presto_hive_metastore_tls_secrets }}"
      - template_file: templates/presto/presto-catalog-config-secret.yaml
        apis: [ {kind: secret} ]
        prune_label_value: presto-catalog-config-secret
      - template_file: templates/presto/presto-common-config.yaml
        apis: [ {kind: configmap} ]
        prune_label_value: presto-common-config
      - template_file: templates/presto/presto-coordinator-config.yaml
        apis: [ {kind: configmap} ]
        prune_label_value: presto-coordinator-config
      - template_file: templates/presto/presto-serviceaccount.yaml
        apis: [ {kind: serviceaccount} ]
        prune_label_value: presto-serviceaccount
      - template_file: templates/presto/presto-prometheus-auth.yaml
        apis: [ {kind: serviceaccount} ]
        prune_label_value: presto-prometheus-auth
        create: "{{ meteringconfig_create_presto_prometheus_auth }}"
      - template_file: templates/presto/presto-jmx-config.yaml
        apis: [ {kind: configmap} ]
        prune_label_value: presto-jmx-config
      - template_file: templates/presto/presto-service.yaml
        apis: [ {kind: service} ]
        prune_label_value: presto-service
      - template_file: templates/presto/presto-worker-config.yaml
        apis: [ {kind: configmap} ]
        prune_label_value: presto-worker-config
      - template_file: templates/presto/presto-coordinator-statefulset.yaml
        apis: [ {kind: statefulset} ]
        prune_label_value: presto-coordinator-statefulset
      - template_file: templates/presto/presto-worker-statefulset.yaml
        apis: [ {kind: statefulset} ]
        prune_label_value: presto-worker-statefulset

- include_tasks: update_meteringconfig_status.yml
  vars:
    current_conditions:
      type: "Running"
      status: "True"
      message: "Finished reconciling Presto resources"
      lastTransitionTime: "{{ now(utc=False).isoformat() + 'Z' }}"
