From db0b564443862049e1b2b2fc61c1eae55ad4912c Mon Sep 17 00:00:00 2001 From: Leonardo Rossetti Date: Jan 06 2022 00:11:11 +0000 Subject: simplify kojihub resource --- diff --git a/operator/config/samples/buildsys_v1alpha1_kojihub.yaml b/operator/config/samples/buildsys_v1alpha1_kojihub.yaml index d2d4fd3..f4b2fde 100644 --- a/operator/config/samples/buildsys_v1alpha1_kojihub.yaml +++ b/operator/config/samples/buildsys_v1alpha1_kojihub.yaml @@ -3,24 +3,11 @@ kind: KojiHub metadata: name: sample spec: - image: quay.io/fedora/koji-hub:f34 + image: quay.io/fedora-kube-sig/koji-hub:latest replicas: 1 - persistent: true - host: koji.mbox.dev # change it to match the external web url/route of koji-hub - configmap: koji-hub - ca_cert_secret: koji-hub-ca-cert - service_cert_secret: koji-hub-service-cert + host: koji.localdomain postgres_secret: postgres http_enabled: true https_enabled: true - ingress_backend: nginx # default - # ingress_backend: openshift - httpd_pvc_name: koji-hub-httpd-pvc - httpd_pvc_size: 1Gi - mnt_pvc_name: koji-hub-mnt-pvc - mnt_pvc_size: 10Gi - web_client_cert_secret: koji-hub-web-client-cert - web_client_username: kojiweb - admin_client_cert: koji-hub-admin-cert - admin_username: kojiadmin - svc_name: koji-hub + ingress_backend: nginx + mnt_pvc_size: 10Gi \ No newline at end of file diff --git a/operator/molecule/default/tasks/kojihub_test.yml b/operator/molecule/default/tasks/kojihub_test.yml index beb2305..6f87df1 100644 --- a/operator/molecule/default/tasks/kojihub_test.yml +++ b/operator/molecule/default/tasks/kojihub_test.yml @@ -19,7 +19,7 @@ api_version: v1 kind: ConfigMap namespace: "{{ namespace }}" - name: koji-hub + name: koji-hub-sample register: koji_configmap - assert: that: @@ -35,7 +35,7 @@ api_version: v1 kind: Secret namespace: "{{ namespace }}" - name: koji-hub-ca-cert + name: koji-hub-sample-ca register: kojihub_secrets - assert: that: @@ -49,7 +49,7 @@ api_version: v1 kind: Secret namespace: "{{ namespace }}" - name: koji-hub-service-cert + name: koji-hub-sample-httpd-certs register: kojihub_secrets - assert: that: @@ -64,7 +64,7 @@ api_version: v1 kind: Secret namespace: "{{ namespace }}" - name: koji-hub-web-client-cert + name: koji-hub-sample-client-web register: kojihub_secrets - assert: that: @@ -77,7 +77,7 @@ api_version: v1 kind: PersistentVolumeClaim namespace: "{{ namespace }}" - name: koji-hub-mnt-pvc + name: koji-hub-sample register: kojihub_pvcs - assert: that: @@ -85,18 +85,6 @@ - kojihub_pvcs.resources[0].metadata.labels['app'] == 'koji-hub' - "'ReadWriteMany' in kojihub_pvcs.resources[0].spec.accessModes" - "kojihub_pvcs.resources[0].spec.resources.requests.storage == '10Gi'" - - k8s_info: - api_version: v1 - kind: PersistentVolumeClaim - namespace: "{{ namespace }}" - name: koji-hub-httpd-pvc - register: kojihub_pvcs - - assert: - that: - - kojihub_pvcs.resources|length == 1 - - kojihub_pvcs.resources[0].metadata.labels['app'] == 'koji-hub' - - "'ReadWriteOnce' in kojihub_pvcs.resources[0].spec.accessModes" - - "kojihub_pvcs.resources[0].spec.resources.requests.storage == '1Gi'" - block: - name: 'TEST: kojihub.service' @@ -104,7 +92,7 @@ api_version: v1 kind: Service namespace: "{{ namespace }}" - name: koji-hub + name: koji-hub-sample register: kojihub_ingress - assert: that: @@ -117,7 +105,7 @@ api_version: networking.k8s.io/v1 kind: Ingress namespace: "{{ namespace }}" - name: koji-hub-http + name: koji-hub-sample-http register: kojihub_ingress - assert: that: diff --git a/operator/roles/koji-builder/tasks/main.yml b/operator/roles/koji-builder/tasks/main.yml index 8c019c9..b71c2d3 100644 --- a/operator/roles/koji-builder/tasks/main.yml +++ b/operator/roles/koji-builder/tasks/main.yml @@ -19,34 +19,28 @@ msg: "Failed to fetch kojibuilder {{ meta.name }} " when: koji_builder_k8s.resources | length == 0 -- name: Retrieve koji-hub data - koji_hub_info: - hub: "{{ koji_builder_k8s.resources.0.metadata.annotations['buildsys.apps.fedoraproject.org/hub'] }}" - register: koji_builder_hub_info - -- name: Play variables setup - set_fact: - koji_builder_koji_hub_url: "https://{{ koji_builder_hub_info['result']['svc'] }}" - koji_builder_cacert_secret: "{{ koji_builder_hub_info['result']['hub']['spec']['ca_cert_secret'] }}" - koji_dir_path: "{{ koji_dir.path }}" - koji_builder_configmap: "kojid-{{ meta.name }}-conf" - koji_builder_client_cert_secret: "kojid-{{ meta.name }}-client-cert" - koji_builder_replicas: 1 - koji_builder_shared_pvc: "{{ koji_builder_hub_info['result']['hub']['spec']['mnt_pvc_name'] }}" - koji_builder_obj: "{{ koji_builder_k8s.resources[0] }}" - - name: Get the annotation value from the retrieved KojiBuilder resource set_fact: - koji_builder_hub: "{{ koji_builder_obj.metadata.annotations['buildsys.apps.fedoraproject.org/hub'].split('/') }}" + koji_builder_hub: "{{ koji_builder_k8s.resources[0].metadata.annotations['buildsys.apps.fedoraproject.org/hub'].split('/') }}" - name: Set variables for both hub name and namespace set_fact: koji_builder_hub_name: "{{ koji_builder_hub.0 }}" koji_builder_hub_namespace: "{{ koji_builder_hub.1 }}" + +- name: Play variables setup + set_fact: + koji_builder_koji_hub_url: "https://koji-hub-{{ koji_builder_hub_name }}.{{ koji_builder_hub_namespace }}.svc.cluster.local" + koji_builder_cacert_secret: "koji-hub-{{ koji_builder_hub_name }}-ca" + koji_dir_path: "{{ koji_dir.path }}" + koji_builder_configmap: "kojid-{{ meta.name }}-conf" + koji_builder_client_cert_secret: "kojid-{{ meta.name }}-client-cert" + koji_builder_replicas: 1 + koji_builder_shared_pvc: "koji-hub-{{ koji_builder_hub_name }}" - name: Create koji-builder client certificate koji_client_cert: - k8s_ca: "{{ meta.namespace }}/{{ koji_builder_hub_info['result']['hub']['spec']['ca_cert_secret'] }}" + k8s_ca: "{{ meta.namespace }}/koji-hub-{{ koji_builder_hub_name }}-ca" k8s_cert: "{{ meta.namespace }}/{{ koji_builder_client_cert_secret }}" k8s_meta: labels: diff --git a/operator/roles/koji-hub/defaults/main.yml b/operator/roles/koji-hub/defaults/main.yml index 1dfff9b..15ee800 100644 --- a/operator/roles/koji-hub/defaults/main.yml +++ b/operator/roles/koji-hub/defaults/main.yml @@ -1,31 +1,16 @@ --- # defaults file for koji-hub -koji_hub_image: "{{ image | default('quay.io/fedora/koji-hub:latest') }}" +koji_hub_image: "{{ image | default('quay.io/fedora-kube-sig/koji-hub:latest') }}" koji_hub_replicas: "{{ replicas | default(1) }}" koji_hub_postgres_secret: "{{ postgres_secret | default('postgres') }}" -koji_hub_configmap: "{{ configmap | default('koji-hub-configmap') }}" -koji_hub_ca_cert_secret: "{{ ca_cert_secret | default('koji-hub-ca-cert') }}" -koji_hub_service_cert_secret: "{{ service_cert_secret | default('koji-hub-service-cert') }}" - -koji_hub_httpd_pvc_name: "{{ httpd_pvc_name | default('koji-hub-httpd-pvc') }}" -koji_hub_httpd_pvc_size: "{{ httpd_pvc_size | default('1Gi') }}" - -koji_hub_mnt_pvc_name: "{{ mnt_pvc_name | default('koji-hub-mnt-pvc') }}" koji_hub_mnt_pvc_size: "{{ mnt_pvc_size | default('10Gi') }}" koji_hub_http_port: "{{ http_port | default('8080') }}" koji_hub_https_port: "{{ https_port | default('8443') }}" -koji_hub_svc_name: "{{ svc_name | default('koji-hub') }}" koji_hub_http_enabled: "{{ http_enabled | default(false) }}" koji_hub_https_enabled: "{{ https_enabled | default(true) }}" koji_hub_host: "{{ host | default('kojihub.mbox.dev') }}" -koji_hub_ingress_backend: "{{ ingress_backend | default('nginx') }}" - -koji_hub_admin_client_cert: "{{ admin_client_cert | default('koji-hub-admin-cert') }}" -koji_hub_admin_username: "{{ admin_username | default('kojiadmin') }}" - -koji_hub_web_client_cert: "{{ web_client_cert | default('koji-hub-web-client-cert') }}" -koji_hub_web_client_username: "{{ web_client_username | default('kojiweb') }}" +koji_hub_ingress_backend: "{{ ingress_backend | default('nginx') }}" \ No newline at end of file diff --git a/operator/roles/koji-hub/tasks/main.yml b/operator/roles/koji-hub/tasks/main.yml index 5190d0f..77ad018 100644 --- a/operator/roles/koji-hub/tasks/main.yml +++ b/operator/roles/koji-hub/tasks/main.yml @@ -13,6 +13,18 @@ - set_fact: psql_secret: "{{ k8s_psql_secrets.resources[0] }}" +- name: Set role vars + set_fact: + koji_hub_configmap: "koji-hub-{{ meta.name }}" + koji_hub_ca_cert_secret: "koji-hub-{{ meta.name }}-ca" + koji_hub_service_cert_secret: "koji-hub-{{ meta.name }}-httpd-certs" + koji_hub_mnt_pvc_name: "koji-hub-{{ meta.name }}" + koji_hub_web_client_cert: "koji-hub-{{ meta.name }}-client-web" + koji_hub_web_client_username: "{{ meta.name }}-web" + koji_hub_admin_client_cert: "koji-hub-{{ meta.name }}-client-admin" + koji_hub_svc_name: "koji-hub-{{ meta.name }}" + koji_hub_admin_username: "{{ meta.name }}-admin" + - block: - name: Ensure koji-hub configmap is updated template: @@ -37,20 +49,6 @@ - include_tasks: cert.yml - block: - - name: PVC creation - k8s_info: - api_version: v1 - kind: PersistentVolumeClaim - namespace: "{{ meta.namespace }}" - name: "{{ koji_hub_httpd_pvc_name }}" - register: k8s_httpd_pvc - - include_tasks: pvc.yml - vars: - pvc_name: "{{ koji_hub_httpd_pvc_name }}" - pvc_size: "{{ koji_hub_httpd_pvc_size }}" - pvc_mode: ReadWriteOnce - pvc_namespace: "{{ meta.namespace }}" - when: k8s_httpd_pvc.resources|length == 0 - k8s_info: api_version: v1 kind: PersistentVolumeClaim @@ -84,7 +82,7 @@ src: ingress.yml.j2 dest: /tmp/ingress.yml vars: - koji_hub_ingress_name: koji-hub-http + koji_hub_ingress_name: "koji-hub-{{ meta.name }}-http" koji_hub_ingress_svc: "{{ koji_hub_svc_name }}" koji_hub_ingress_port: "{{ koji_hub_http_port }}" - k8s: diff --git a/operator/roles/koji-hub/templates/deployment.yml.j2 b/operator/roles/koji-hub/templates/deployment.yml.j2 index e6cdec9..a2c9101 100644 --- a/operator/roles/koji-hub/templates/deployment.yml.j2 +++ b/operator/roles/koji-hub/templates/deployment.yml.j2 @@ -62,9 +62,8 @@ spec: - name: config-volume configMap: name: "{{ koji_hub_configmap }}" - - name: koji-hub-httpd - persistentVolumeClaim: - claimName: "{{ koji_hub_httpd_pvc_name }}" - name: koji-hub-mnt persistentVolumeClaim: claimName: "{{ koji_hub_mnt_pvc_name }}" + - name: koji-hub-httpd + emptyDir: {} diff --git a/operator/roles/kojira/tasks/main.yml b/operator/roles/kojira/tasks/main.yml index c49ebcf..068d033 100644 --- a/operator/roles/kojira/tasks/main.yml +++ b/operator/roles/kojira/tasks/main.yml @@ -19,26 +19,41 @@ msg: "Failed to fetch kojira {{ meta.name }} " when: kojira_k8s.resources | length == 0 -- name: Retrieve koji-hub data - koji_hub_info: - hub: "{{ kojira_k8s.resources.0.metadata.annotations['buildsys.apps.fedoraproject.org/hub'] }}" - register: kojira_hub_info +# - name: Retrieve koji-hub data +# koji_hub_info: +# hub: "{{ kojira_k8s.resources.0.metadata.annotations['buildsys.apps.fedoraproject.org/hub'] }}" +# register: kojira_hub_info - name: Get the annotation value from the retrieved KojiBuilder resource set_fact: kojira_hub: "{{ kojira_k8s.resources.0.metadata.annotations['buildsys.apps.fedoraproject.org/hub'].split('/') }}" +# - name: Set play variables +# set_fact: +# kojira_replicas: 1 +# kojira_configmap: "kojira-{{ meta.name }}-conf" +# kojira_hub_username: "{{ meta.name }}" +# kojira_hub_host: "{{ kojira_hub_info['result']['svc'] }}" +# kojira_cacert_secret: "{{ kojira_hub_info['result']['hub']['spec']['ca_cert_secret'] }}" +# kojira_client_cert_secret: "kojira-{{ meta.name }}-client-cert" +# kojira_shared_pvc: "{{ kojira_hub_info['result']['hub']['spec']['mnt_pvc_name'] }}" +# kojira_hub_name: "{{ kojira_hub.0 }}" +# kojira_hub_namespace: "{{ kojira_hub.1 }}" + +- name: Set koji-hub variables + set_fact: + kojira_hub_name: "{{ kojira_hub.0 }}" + kojira_hub_namespace: "{{ kojira_hub.1 }}" + - name: Set play variables set_fact: kojira_replicas: 1 kojira_configmap: "kojira-{{ meta.name }}-conf" kojira_hub_username: "{{ meta.name }}" - kojira_hub_host: "{{ kojira_hub_info['result']['svc'] }}" - kojira_cacert_secret: "{{ kojira_hub_info['result']['hub']['spec']['ca_cert_secret'] }}" + kojira_hub_host: "koji-hub-{{ kojira_hub_name }}.{{ kojira_hub_namespace }}.svc.cluster.local" + kojira_cacert_secret: "koji-hub-{{ kojira_hub_name }}-ca" kojira_client_cert_secret: "kojira-{{ meta.name }}-client-cert" - kojira_shared_pvc: "{{ kojira_hub_info['result']['hub']['spec']['mnt_pvc_name'] }}" - kojira_hub_name: "{{ kojira_hub.0 }}" - kojira_hub_namespace: "{{ kojira_hub.1 }}" + kojira_shared_pvc: "koji-hub-{{ kojira_hub_name }}" - include_tasks: cert.yml diff --git a/operator/roles/kojiuser/tasks/create.yml b/operator/roles/kojiuser/tasks/create.yml index 8c8a6e7..8cd9a4f 100644 --- a/operator/roles/kojiuser/tasks/create.yml +++ b/operator/roles/kojiuser/tasks/create.yml @@ -23,16 +23,8 @@ state: enabled - block: - - name: Create user secret - k8s_info: - api_version: buildsys.apps.fedoraproject.org/v1alpha1 - kind: KojiHub - namespace: "{{ koji_user_hub_namespace }}" - name: "{{ koji_user_hub_name }}" - register: k8s_query - - koji_client_cert: - k8s_ca: "{{ koji_user_hub_namespace }}/{{ k8s_query.resources[0]['spec']['ca_cert_secret'] }}" + k8s_ca: "{{ koji_user_hub_namespace }}/koji-hub-{{ koji_user_hub_name }}-ca" k8s_cert: "{{ meta.namespace }}/{{ meta.name }}-koji-client-cert" k8s_meta: labels: