From df78327b47be732c33aea2b5ed8dcd11105d3ebd Mon Sep 17 00:00:00 2001
From: Leonardo Rossetti <lrossett@redhat.com>
Date: Dec 13 2021 12:36:15 +0000
Subject: deploying koji components


---

diff --git a/deploy/minikube/pod.yaml b/deploy/minikube/pod.yaml
index 25a5e2d..690e4b1 100644
--- a/deploy/minikube/pod.yaml
+++ b/deploy/minikube/pod.yaml
@@ -10,20 +10,259 @@ data:
   uninstall.sh: |
     #!/bin/bash
 
-    kubectl delete kojira/default -n koji-system
+    # delete resouces
+    kubectl delete deployment/postgres -n koji-system
+    kubectl delete kojihub/sample -n koji-system
     kubectl delete kojibuilder/createrepo -n koji-system
     kubectl delete kojibuilder/builder -n koji-system
-    kubectl delete kojihub/default -n koji-system
+    kubectl delete kojira/kojira -n koji-system
 
-    kubectl delete -f /manifests/koji-operator.yaml
+    # delete koji-operator
+    kubectl delete -f https://pagure.io/kube-sig/koji-operator/raw/main/f/deploy/koji-operator.yaml
   install.sh: |
     #!/bin/bash
+    kubectl apply -f https://pagure.io/kube-sig/koji-operator/raw/main/f/deploy/koji-operator.yaml
+
+    while true; do
+      if [[ $(kubectl get deployment/controller-manager -o jsonpath='{.status.conditions[?(@.type=="Available")].status}' -n koji-system) == "True" ]]; then
+        echo deployment/controller-manager ready
+        break
+      else
+        echo deployment/controller-manager waiting readiness
+        sleep 5
+      fi
+    done
+
+    echo "
+    apiVersion: v1
+    kind: Secret
+    metadata:
+      name: postgres
+      namespace: koji-system
+      labels:
+        app: postgres
+    stringData:
+      POSTGRES_HOST: postgres
+      POSTGRES_DB: koji
+      POSTGRES_USER: koji
+      POSTGRES_PASSWORD: koji
+    ---
+    apiVersion: apps/v1
+    kind: Deployment
+    metadata:
+      name: postgres
+      namespace: koji-system
+    spec:
+      replicas: 1
+      selector:
+        matchLabels:
+          app: postgres
+      template:
+        metadata:
+          labels:
+            app: postgres
+        spec:
+          volumes:
+            - name: data
+              emptyDir: {}
+          containers:
+            - name: postgres
+              volumeMounts:
+                - mountPath: /var/lib/postgresql
+                  name: data
+              image: postgres:10.4
+              imagePullPolicy: Always
+              ports:
+                - containerPort: 5432
+              envFrom:
+                - secretRef:
+                    name: postgres
+    ---
+    apiVersion: v1
+    kind: Service
+    metadata:
+      name: postgres
+      namespace: koji-system
+      labels:
+        app: postgres
+    spec:
+      type: NodePort
+      ports:
+        - port: 5432
+      selector:
+        app: postgres
+    " | kubectl apply -f -
+
+    while true; do
+      if [[ $(kubectl  get deployment/postgres -o jsonpath='{.status.conditions[?(@.type=="Available")].status}' -n koji-system) == "True" ]]; then
+        echo deployment/postgres ready
+        break
+      else
+        echo deployment/postgres waiting readiness
+        sleep 5
+      fi
+    done
+
+    echo "
+    apiVersion: v1
+    kind: Secret
+    metadata:
+      name: rabbitmq-certs
+      namespace: koji-system
+    data:
+      ca: |-
+        Y2hhbmdlbWU=
+      cert: |-
+        Y2hhbmdlbWU=
+      key: |-
+        Y2hhbmdlbWU=
+    ---
+    apiVersion: v1
+    kind: Secret
+    metadata:
+      name: koji-hub-msg
+      namespace: koji-system
+    data:
+      koji.ca: |-
+        Y2hhbmdlbWU=
+      koji.crt: |-
+        Y2hhbmdlbWU=
+      koji.key: |-
+        Y2hhbmdlbWU=
+    " | kubectl apply -f -
+
+    echo "
+    apiVersion: buildsys.apps.fedoraproject.org/v1alpha1
+    kind: KojiHub
+    metadata:
+      name: sample
+      namespace: koji-system
+    spec:
+      image: quay.io/fedora-kube-sig/koji-hub:latest
+      replicas: 1
+      persistent: true
+      host: koji.myservice.test
+      configmap: koji-hub
+      ca_cert_secret: koji-hub-ca-cert
+      service_cert_secret: koji-hub-service-cert
+      postgres_secret: postgres
+      http_enabled: true
+      https_enabled: true
+      topic_prefix: kojikube
+      fedora_messaging_url: amqps://koji:something@rabbitmq
+      messaging_cert_secret: koji-hub-msg
+      ingress_backend: nginx # default
+      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
+      " | kubectl apply -f -
+
+      while true; do
+        if [[ $(kubectl  get kojihubs/sample -o jsonpath='{.status.conditions[?(@.reason=="Successful")].status}' -n koji-system) == "True" ]]; then
+          echo kojihubs/sample ready
+          break
+        else
+          echo kojihubs/sample waiting readiness
+          sleep 5
+        fi
+      done
+
+      echo "
+      apiVersion: buildsys.apps.fedoraproject.org/v1alpha1
+      kind: KojiBuilder
+      metadata:
+        name: createrepo
+        namespace: koji-system
+        annotations:
+          buildsys.apps.fedoraproject.org/hub: sample/koji-system
+      spec:
+        image: quay.io/fedora-kube-sig/koji-builder:latest
+        type: repo
+        max_jobs: 5
+        archs:
+          - x86_64
+        channels:
+          - createrepo
+        ssl_verify: false
+        volume: true
+      " | kubectl apply -f -
+
+      while true; do
+        if [[ $(kubectl  get kojibuilder/createrepo -o jsonpath='{.status.conditions[?(@.reason=="Successful")].status}' -n koji-system) == "True" ]]; then
+          echo kojibuilder/createrepo ready
+          break
+        else
+          echo kojibuilder/createrepo waiting readiness
+          sleep 5
+        fi
+      done
+
+      echo "
+      apiVersion: buildsys.apps.fedoraproject.org/v1alpha1
+      kind: Kojira
+      metadata:
+        name: kojira
+        namespace: koji-system
+        annotations:
+          buildsys.apps.fedoraproject.org/hub: sample/koji-system
+      spec:
+        image: quay.io/fedora/kojira:latest
+        src: 'no'
+        max_repo_tasks: 15
+        repo_tasks_limit: 15
+      " | kubectl apply -f -
+
+      while true; do
+        if [[ $(kubectl  get kojira/kojira -o jsonpath='{.status.conditions[?(@.reason=="Successful")].status}' -n koji-system) == "True" ]]; then
+          echo kojira/kojira ready
+          break
+        else
+          echo kojira/kojira waiting readiness
+          sleep 5
+        fi
+      done
+
+      if [[ "$(egrep 'svm|vmx' /proc/cpuinfo)" != "" ]]; then
+        echo "
+        apiVersion: buildsys.apps.fedoraproject.org/v1alpha1
+        kind: KojiBuilder
+        metadata:
+          name: builder
+          namespace: koji-system
+          annotations:
+            buildsys.apps.fedoraproject.org/hub: sample/koji-system
+        spec:
+          image: quay.io/fedora-kube-sig/koji-builder-kubevirt:latest
+          type: kubevirt
+          max_jobs: 5
+          archs:
+            - x86_64
+          channels:
+            - default
+          ssl_verify: false
+          volume: false
+          running: true
+        " | kubectl apply -f -
+
+        while true; do
+          if [[ $(kubectl get kojibuilder/builder -o jsonpath='{.status.conditions[?(@.reason=="Successful")].status}' -n koji-system) == "True" ]]; then
+            echo kojibuilder/builder ready
+            break
+          else
+            echo kojibuilder/builder waiting readiness
+            sleep 5
+          fi
+        done
+      else
+        echo "virt disabled, skipping kkubevirt builder deployment."
+      fi
 
-    curl -Ls https://pagure.io/kube-sig/koji-operator/raw/main/f/deploy/koji-operator.yaml -o /manifests/koji-operator.yaml
-    kubectl create -f /manifests/koji-operator.yaml
-    
-    # TODO: create koji resources with kubectl
-    
     sleep infinity
 ---
 apiVersion: v1

