---
# Source: sonarqube/charts/postgresql/templates/secrets.yaml
apiVersion: v1
kind: Secret
metadata:
  name: sonarqube-postgresql
  labels:
    app.kubernetes.io/name: postgresql
    helm.sh/chart: postgresql-10.15.0
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/managed-by: Helm
  namespace: sonarqube
type: Opaque
data:
  postgresql-postgres-password: "OWVQd3pUV2NkQQ=="
  postgresql-password: "dW9zTUszNUZSaUZDd1U5NDhI"
---
# Source: sonarqube/templates/secret.yaml
---
apiVersion: v1
kind: Secret
metadata:
  name: sonarqube-sonarqube-monitoring-passcode
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
type: Opaque
data:
  SONAR_WEB_SYSTEMPASSCODE: "SGtMU3ZyRWp3YUJkTjJ1"
---
# Source: sonarqube/templates/config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-config
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  sonar.properties: |
---
# Source: sonarqube/templates/init-fs.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-init-fs
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  init_fs.sh: |-
---
# Source: sonarqube/templates/init-sysctl.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-init-sysctl
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  init_sysctl.sh: |-
    if [[ "$(sysctl -n vm.max_map_count)" -lt 524288 ]]; then
      sysctl -w vm.max_map_count=524288
    fi
    if [[ "$(sysctl -n fs.file-max)" -lt 131072 ]]; then
      sysctl -w fs.file-max=131072
    fi
    if [[ "$(ulimit -n)" != "unlimited" ]]; then
      if [[ "$(ulimit -n)" -lt 131072 ]]; then
        echo "ulimit -n 131072"
        ulimit -n 131072
      fi
    fi
    if [[ "$(ulimit -u)" != "unlimited" ]]; then
      if [[ "$(ulimit -u)" -lt 8192 ]]; then
        echo "ulimit -u 8192"
        ulimit -u 8192
      fi
    fi
---
# Source: sonarqube/templates/install-plugins.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-install-plugins
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  install_plugins.sh: |-
      [ -e /opt/sonarqube/extensions/plugins/* ] && rm /opt/sonarqube/extensions/plugins/*
      cd /opt/sonarqube/extensions/plugins
      curl   -fSLO "https://downloads.remiges.tech/bse/setup/downloads/services/sonarqube/sonar-flutter-plugin-0.5.0.jar"
---
# Source: sonarqube/templates/jdbc-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-jdbc-config
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  SONAR_JDBC_USERNAME: "sonarqube"
  SONAR_JDBC_URL: "jdbc:postgresql://sonarqube-postgresql:5432/sonarqube"
---
# Source: sonarqube/templates/prometheus-ce-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-prometheus-ce-config
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  prometheus-ce-config.yaml: |-
        rules:
        - pattern: .*
---
# Source: sonarqube/templates/prometheus-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: sonarqube-sonarqube-prometheus-config
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
data:
  prometheus-config.yaml: |-
        rules:
        - pattern: .*
---
# Source: sonarqube/charts/postgresql/templates/svc-headless.yaml
apiVersion: v1
kind: Service
metadata:
  name: sonarqube-postgresql-headless
  labels:
    app.kubernetes.io/name: postgresql
    helm.sh/chart: postgresql-10.15.0
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/managed-by: Helm
    # Use this annotation in addition to the actual publishNotReadyAddresses
    # field below because the annotation will stop being respected soon but the
    # field is broken in some versions of Kubernetes:
    # https://github.com/kubernetes/kubernetes/issues/58662
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
  namespace: sonarqube
spec:
  type: ClusterIP
  clusterIP: None
  # We want all pods in the StatefulSet to have their addresses published for
  # the sake of the other Postgresql pods even before they're ready, since they
  # have to be able to talk to each other in order to become ready.
  publishNotReadyAddresses: true
  ports:
    - name: tcp-postgresql
      port: 5432
      targetPort: tcp-postgresql
  selector:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: sonarqube
---
# Source: sonarqube/charts/postgresql/templates/svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: sonarqube-postgresql
  labels:
    app.kubernetes.io/name: postgresql
    helm.sh/chart: postgresql-10.15.0
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/managed-by: Helm
  annotations:
  namespace: sonarqube
spec:
  type: ClusterIP
  ports:
    - name: tcp-postgresql
      port: 5432
      targetPort: tcp-postgresql
  selector:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: sonarqube
    role: primary
---
# Source: sonarqube/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: sonarqube-sonarqube
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm

spec:
  type: NodePort
  ports:
    - port: 3050
      targetPort: http
      nodePort: 30010
      protocol: TCP
      name: http
  selector:
    app: sonarqube
    release: sonarqube
---
# Source: sonarqube/charts/postgresql/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sonarqube-postgresql
  labels:
    app.kubernetes.io/name: postgresql
    helm.sh/chart: postgresql-10.15.0
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: primary
  annotations:
  namespace: sonarqube
spec:
  serviceName: sonarqube-postgresql-headless
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app.kubernetes.io/name: postgresql
      app.kubernetes.io/instance: sonarqube
      role: primary
  template:
    metadata:
      name: sonarqube-postgresql
      labels:
        app.kubernetes.io/name: postgresql
        helm.sh/chart: postgresql-10.15.0
        app.kubernetes.io/instance: sonarqube
        app.kubernetes.io/managed-by: Helm
        role: primary
        app.kubernetes.io/component: primary
    spec:      
      affinity:
        podAffinity:
          
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/name: postgresql
                    app.kubernetes.io/instance: sonarqube
                    app.kubernetes.io/component: primary
                namespaces:
                  - "sonarqube"
                topologyKey: kubernetes.io/hostname
              weight: 1
        nodeAffinity:
          
      securityContext:
        fsGroup: 1001
      automountServiceAccountToken: false
      nodeSelector:                 # Add nodeSelector here
        name: node-1
      containers:
        - name: sonarqube-postgresql
          image: private-repo:5000/bitnami/postgresql:11.14.0-debian-10-r22
          imagePullPolicy: "IfNotPresent"
          resources:
            limits:
              cpu: 2
              memory: 2Gi
            requests:
              cpu: 100m
              memory: 200Mi
          securityContext:
            runAsUser: 1001
          env:
            - name: BITNAMI_DEBUG
              value: "false"
            - name: POSTGRESQL_PORT_NUMBER
              value: "5432"
            - name: POSTGRESQL_VOLUME_DIR
              value: "/bitnami/postgresql"
            - name: PGDATA
              value: "/bitnami/postgresql/data"
            - name: POSTGRES_POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: sonarqube-postgresql
                  key: postgresql-postgres-password
            - name: POSTGRES_USER
              value: "sonarqube"
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: sonarqube-postgresql
                  key: postgresql-password
            - name: POSTGRES_DB
              value: "sonarqube"
            - name: POSTGRESQL_ENABLE_LDAP
              value: "no"
            - name: POSTGRESQL_ENABLE_TLS
              value: "no"
            - name: POSTGRESQL_LOG_HOSTNAME
              value: "false"
            - name: POSTGRESQL_LOG_CONNECTIONS
              value: "false"
            - name: POSTGRESQL_LOG_DISCONNECTIONS
              value: "false"
            - name: POSTGRESQL_PGAUDIT_LOG_CATALOG
              value: "off"
            - name: POSTGRESQL_CLIENT_MIN_MESSAGES
              value: "error"
            - name: POSTGRESQL_SHARED_PRELOAD_LIBRARIES
              value: "pgaudit"
          ports:
            - name: tcp-postgresql
              containerPort: 5432
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - exec pg_isready -U "sonarqube" -d "dbname=sonarqube" -h 127.0.0.1 -p 5432
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - -e
                - |
                  exec pg_isready -U "sonarqube" -d "dbname=sonarqube" -h 127.0.0.1 -p 5432
                  [ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f /bitnami/postgresql/.initialized ]
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          volumeMounts:
            - name: dshm
              mountPath: /dev/shm
            - name: data
              mountPath: /bitnami/postgresql
              subPath: 
      volumes:
        - name: dshm
          emptyDir:
            medium: Memory
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "2Gi"
        selector:
          matchLabels:
            vol: sonarqube-postgres
---
# Source: sonarqube/templates/sonarqube-sts.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sonarqube-sonarqube
  labels:
    app: sonarqube
    chart: sonarqube-8.0.3_2010
    release: sonarqube
    heritage: Helm
    app.kubernetes.io/name: sonarqube-sonarqube-sonarqube
    app.kubernetes.io/instance: sonarqube
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/part-of: sonarqube
    app.kubernetes.io/component: sonarqube-sonarqube
    app.kubernetes.io/version: "9.9.3-community"
spec:
  replicas: 1
  serviceName: sonarqube-sonarqube
  selector:
    matchLabels:
      app: sonarqube
      release: sonarqube
  template:
    metadata:
      labels:
        app: sonarqube
        release: sonarqube
      annotations:
        checksum/init-sysctl: 6affee1c241328528ab5a0dc5283b83aba72a72166c326a08fbc557695562c24
        checksum/init-fs: 3b1049958f3fbcf3cec2bcd444d33aa7faced9f446d22d503136d058054ad012
        checksum/plugins: 76abb17d6fa17f5e7c5ec528f9d3f844583d1eb48a3abbc2cae9644534bd8a0b
        checksum/config: 86ebffd9611f6efd28db4069bf6cf89da109fe81a9cff325d6a2bfa3bde71949
        checksum/secret: 13c54a2a444e2b9cb5b1ba63a8abe06393601507f91823b7cc642ed890633f18
        checksum/prometheus-config: 4ab2d26718a1a2117b87ea383f2e66a627ff9c098d2e04dd39a2f779a2bab595
        checksum/prometheus-ce-config: c6a8a1c7a91d7047bc17aeab44ec8d82ddcfadd21d2fc8eedd4868e5bbf034c6
    spec:
      securityContext:
        fsGroup: 1000
      initContainers:
        - name: "wait-for-db"
          image: private-repo:5000/busybox:1.32
          imagePullPolicy: IfNotPresent
          resources:
            {}
          command: ["/bin/sh", "-c", "for i in $(seq 1 200); do nc -z -w3 sonarqube-postgresql 5432 && exit 0 || sleep 2; done; exit 1"]
        - name: init-sysctl
          image: private-repo:5000/busybox:1.32
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          resources:
            {}
          command: ["sh",
            "-e",
            "/tmp/scripts/init_sysctl.sh"]
          volumeMounts:
            - name: init-sysctl
              mountPath: /tmp/scripts/
        - name: inject-prometheus-exporter
          image: private-repo:5000/curlimages/curl:7.76.1
          imagePullPolicy: IfNotPresent
          securityContext:
            runAsGroup: 1000
            runAsUser: 1000
          resources:
            {}
          command: ["/bin/sh","-c"]
          args: ["curl 'https://downloads.remiges.tech/bse/setup/downloads/services/sonarqube/jmx_prometheus_javaagent-0.16.0.jar'  --output /data/jmx_prometheus_javaagent.jar -v"]
          volumeMounts:
            - mountPath: /data
              name: sonarqube
              subPath: data
          env:
            - name: http_proxy
              value: 
            - name: https_proxy
              value: 
            - name: no_proxy
              value: 
        - name: install-plugins
          image: private-repo:5000/curlimages/curl:7.76.1
          imagePullPolicy: IfNotPresent
          command: ["sh",
            "-e",
            "/tmp/scripts/install_plugins.sh"]
          volumeMounts:
            - mountPath: /opt/sonarqube/extensions/plugins
              name: sonarqube
              subPath: extensions/plugins
            - name: install-plugins
              mountPath: /tmp/scripts/
          securityContext:
            runAsGroup: 1000
            runAsUser: 1000
          resources:
            {}
          env:
            - name: http_proxy
              value: 
            - name: https_proxy
              value: 
            - name: no_proxy
              value:
      nodeSelector:
        name: node-1 
      containers:
        - name: sonarqube
          image: "private-repo:5000/sonarqube:9.9.3-community"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 9000
              protocol: TCP
            - name: monitoring-web
              containerPort: 8000
              protocol: TCP
            - name: monitoring-ce
              containerPort: 8001
              protocol: TCP
          resources:
            limits:
              cpu: 800m
              memory: 4Gi
            requests:
              cpu: 400m
              memory: 2Gi
          env:
            - name: SONAR_WEB_JAVAOPTS
              value: "-javaagent:/opt/sonarqube/data/jmx_prometheus_javaagent.jar=8000:/opt/sonarqube/conf/prometheus-config.yaml"
            - name: SONAR_CE_JAVAOPTS
              value: "-javaagent:/opt/sonarqube/data/jmx_prometheus_javaagent.jar=8001:/opt/sonarqube/conf/prometheus-ce-config.yaml"
            - name: SONAR_JDBC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: sonarqube-postgresql
                  key: postgresql-password
            - name: SONAR_WEB_SYSTEMPASSCODE
              valueFrom:
                secretKeyRef:
                  name: sonarqube-sonarqube-monitoring-passcode
                  key: SONAR_WEB_SYSTEMPASSCODE
          envFrom:
            - configMapRef:
                name: sonarqube-sonarqube-jdbc-config
          livenessProbe:
            exec:
              command:
              - sh
              - -c
              - |
                host="$(hostname -i || echo '127.0.0.1')"
                reply=$(wget -qO- --header="X-Sonar-Passcode: $SONAR_WEB_SYSTEMPASSCODE" http://${host}:9000/api/system/liveness 2>&1)
                if [ -z "$reply" ]; then exit 0; else exit 1; fi
            initialDelaySeconds: 60
            periodSeconds: 30
            failureThreshold: 6
          readinessProbe:
            exec:
              command:
              - sh
              - -c
              - |
                #!/bin/bash
                # A Sonarqube container is considered ready if the status is UP, DB_MIGRATION_NEEDED or DB_MIGRATION_RUNNING
                # status about migration are added to prevent the node to be kill while sonarqube is upgrading the database.
                host="$(hostname -i || echo '127.0.0.1')"
                if wget --proxy off -qO- http://${host}:9000/api/system/status | grep -q -e '"status":"UP"' -e '"status":"DB_MIGRATION_NEEDED"' -e '"status":"DB_MIGRATION_RUNNING"'; then
                	exit 0
                fi
                exit 1
            initialDelaySeconds: 60
            periodSeconds: 30
            failureThreshold: 6
          startupProbe:
            httpGet:
              scheme: HTTP
              path: /api/system/status
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
            failureThreshold: 24
          securityContext:
            runAsUser: 1000
          volumeMounts:
            - mountPath: /opt/sonarqube/data
              name: sonarqube
              subPath: data
            - mountPath: /opt/sonarqube/extensions/plugins
              name: sonarqube
              subPath: extensions/plugins
            - mountPath: /opt/sonarqube/temp
              name: sonarqube
              subPath: temp
            - mountPath: /opt/sonarqube/logs
              name: sonarqube
              subPath: logs
            - mountPath: /tmp
              name: tmp-dir
            - mountPath: /opt/sonarqube/conf/prometheus-config.yaml
              subPath: prometheus-config.yaml
              name: prometheus-config
            - mountPath: /opt/sonarqube/conf/prometheus-ce-config.yaml
              subPath: prometheus-ce-config.yaml
              name: prometheus-ce-config
      serviceAccountName: default
      volumes:
      - name: init-sysctl
        configMap:
          name: sonarqube-sonarqube-init-sysctl
          items:
            - key: init_sysctl.sh
              path: init_sysctl.sh
      - name: init-fs
        configMap:
          name: sonarqube-sonarqube-init-fs
          items:
            - key: init_fs.sh
              path: init_fs.sh
      - name: install-plugins
        configMap:
          name: sonarqube-sonarqube-install-plugins
          items:
            - key: install_plugins.sh
              path: install_plugins.sh
      - name: prometheus-config
        configMap:
          name: sonarqube-sonarqube-prometheus-config
          items:
            - key: prometheus-config.yaml
              path: prometheus-config.yaml
      - name: prometheus-ce-config
        configMap:
          name: sonarqube-sonarqube-prometheus-ce-config
          items:
            - key: prometheus-ce-config.yaml
              path: prometheus-ce-config.yaml
      - name: sonarqube
        emptyDir:
          {}
      - name : tmp-dir
        emptyDir:
          {}
---
# Source: volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: sonarqube-postgresql-data
  labels:
    vol: sonarqube-postgres
spec:
  storageClassName: local-storage
  volumeMode: Filesystem
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: /kra-data/data/devops/sonarqube
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-1
