###########  repo helm ################
helm repo add sonarqube https://SonarSource.github.io/helm-chart-sonarqube
helm repo update

###########  creazione ns e secret db ################
kubectl create namespace sonarqube

kubectl create secret generic sonarqube-database-cred \
  --from-literal=username=sonarqube \
  --from-literal=password=KAYQE1QA7uwUZ8uI \
  -n sonarqube
  
  
###########  creazione database ################ 
kubectl cnpg psql pg-devops -n devops

CREATE DATABASE sonarqube;
CREATE USER sonarqube WITH PASSWORD 'KAYQE1QA7uwUZ8uI';
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonarqube;
ALTER DATABASE sonarqube OWNER TO sonarqube;  
  
########### Values.yaml per installazione helm  ################  

service:
  type: ClusterIP

postgresql:
  enabled: false

jdbcOverwrite:
  enabled: true
  jdbcUrl: "jdbc:postgresql://pg-devops-rw.devops.svc.cluster.local:5432/sonarqube"
  jdbcUsername: "postgres"
  jdbcSecretName: "sonarqube-database-cred"
  jdbcSecretPasswordKey: "password"

readinessProbe:
  initialDelaySeconds: 300  # Increase initial delay to accommodate the database start time
  timeoutSeconds: 60
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3

livenessProbe:
  initialDelaySeconds: 360  # Ensure the application has enough time to start
  timeoutSeconds: 60
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3

startupProbe:
  initialDelaySeconds: 300  # Allow for sufficient startup time
  timeoutSeconds: 60
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3  
  
  
###########  installazione helm ################  
helm upgrade -f sonarvalues.yaml --install -n sonarqube sonarqube sonarqube/sonarqube --set community.enabled=true,monitoringPasscode="KAYQE1QA7uwUZ8uI"

  
  
###########  httproute ################  
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: sonarqube
  namespace: sonarqube
spec:
  hostnames:
  - sonarqube.italiadatacenter.com
  parentRefs:
  - name: main-gateway
    namespace: nginx-gateway
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: sonarqube-sonarqube
      port: 9000
	  

admin	  
$KAYQE1QA7uwUZ8uI	  