From 415e6ec8bd0dd0fb5865e72e725952f167d986af Mon Sep 17 00:00:00 2001 From: Julio Pasinatto Date: Thu, 3 Jul 2025 15:53:33 -0300 Subject: [PATCH 1/2] CLOUD-915: Add flags to disable monitoring and logging in PR job --- Jenkinsfile | 72 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 846fda3e5..fd381422b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,25 +1,41 @@ -region="us-central1-a" -testUrlPrefix="https://percona-jenkins-artifactory-public.s3.amazonaws.com/cloud-psmdb-operator" -tests=[] +region = 'us-central1-a' +testUrlPrefix = 'https://percona-jenkins-artifactory-public.s3.amazonaws.com/cloud-psmdb-operator' +tests = [] void createCluster(String CLUSTER_SUFFIX) { withCredentials([string(credentialsId: 'GCP_PROJECT_ID', variable: 'GCP_PROJECT'), file(credentialsId: 'gcloud-key-file', variable: 'CLIENT_SECRET_FILE')]) { sh """ - NODES_NUM=3 export KUBECONFIG=/tmp/$CLUSTER_NAME-${CLUSTER_SUFFIX} + gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE + gcloud config set project $GCP_PROJECT ret_num=0 while [ \${ret_num} -lt 15 ]; do ret_val=0 - gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE - gcloud config set project $GCP_PROJECT - gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true - gcloud container clusters create --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.30 --machine-type=n1-standard-4 --preemptible --disk-size 30 --num-nodes=\$NODES_NUM --network=jenkins-vpc --subnetwork=jenkins-${CLUSTER_SUFFIX} --no-enable-autoupgrade --cluster-ipv4-cidr=/21 --labels delete-cluster-after-hours=6 --enable-ip-alias --workload-pool=cloud-dev-112233.svc.id.goog && \ + gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone ${region} --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone ${region} --quiet || true + gcloud container clusters create $CLUSTER_NAME-${CLUSTER_SUFFIX} \ + --preemptible \ + --zone=${region} \ + --machine-type='n1-standard-2' \ + --cluster-version='1.30' \ + --num-nodes=3 \ + --labels='delete-cluster-after-hours=6' \ + --disk-size=30 \ + --network=jenkins-vpc \ + --subnetwork=jenkins-${CLUSTER_SUFFIX} \ + --cluster-ipv4-cidr=/21 \ + --enable-ip-alias \ + --no-enable-autoupgrade \ + --monitoring=NONE \ + --logging=NONE \ + --no-enable-managed-prometheus \ + --workload-pool=cloud-dev-112233.svc.id.goog \ + --quiet && \ kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user jenkins@"$GCP_PROJECT".iam.gserviceaccount.com || ret_val=\$? if [ \${ret_val} -eq 0 ]; then break; fi ret_num=\$((ret_num + 1)) done if [ \${ret_num} -eq 15 ]; then - gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true + gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone ${region} --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone ${region} --quiet || true exit 1 fi """ @@ -41,7 +57,7 @@ void shutdownCluster(String CLUSTER_SUFFIX) { kubectl delete pods --all -n \$namespace --force --grace-period=0 || true done kubectl get svc --all-namespaces || true - gcloud container clusters delete --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} + gcloud container clusters delete --zone ${region} $CLUSTER_NAME-${CLUSTER_SUFFIX} """ } } @@ -65,7 +81,7 @@ void deleteOldClusters(String FILTER) { break fi done - gcloud container clusters delete --async --zone $region --quiet \$GKE_CLUSTER || true + gcloud container clusters delete --async --zone ${region} --quiet \$GKE_CLUSTER || true done fi """ @@ -149,12 +165,30 @@ void printKubernetesStatus(String LOCATION, String CLUSTER_SUFFIX) { """ } -TestsReport = '| Test name | Status |\r\n| ------------- | ------------- |' +String formatTime(def time) { + if (!time || time == "N/A") return "N/A" + + try { + def totalSeconds = time as Double + def hours = (totalSeconds / 3600) as Integer + def minutes = ((totalSeconds % 3600) / 60) as Integer + def seconds = (totalSeconds % 60) as Integer + + return String.format("%02d:%02d:%02d", hours, minutes, seconds) + + } catch (Exception e) { + println("Error converting time: ${e.message}") + return time.toString() + } +} + +TestsReport = '| Test Name | Result | Time |\r\n| ----------- | -------- | ------ |' TestsReportXML = '\n' void makeReport() { - def wholeTestAmount=tests.size() + def wholeTestAmount = tests.size() def startedTestAmount = 0 + def totalTestTime = 0 for (int i=0; i<'+ testResult +'/>\n' } - TestsReport = TestsReport + "\r\n| We run $startedTestAmount out of $wholeTestAmount|" + TestsReport = TestsReport + "\r\n| We run $startedTestAmount out of $wholeTestAmount | | " + formatTime(totalTestTime) + " |" TestsReportXML = TestsReportXML + '\n' sh """ @@ -244,10 +282,10 @@ void runTest(Integer TEST_ID) { void prepareNode() { sh """ - sudo curl -s -L -o /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl + sudo curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl kubectl version --client --output=yaml - curl -fsSL https://get.helm.sh/helm-v3.12.3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm + curl -fsSL https://get.helm.sh/helm-v3.18.3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm sudo curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq sudo curl -fsSL https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux64 -o /usr/local/bin/jq && sudo chmod +x /usr/local/bin/jq From 9d5456508def1bb97ffa7da79b450ff41a98b5fb Mon Sep 17 00:00:00 2001 From: Julio Pasinatto Date: Thu, 3 Jul 2025 20:59:43 -0300 Subject: [PATCH 2/2] Increase stages timeout --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fd381422b..bd5f9bbdc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -537,7 +537,7 @@ pipeline { } } options { - timeout(time: 3, unit: 'HOURS') + timeout(time: 4, unit: 'HOURS') } parallel { stage('cluster1') {