Skip to content

CLOUD-915: Add flags to disable monitoring and logging in PR job #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 56 additions & 18 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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
"""
Expand All @@ -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}
"""
}
}
Expand All @@ -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
"""
Expand Down Expand Up @@ -149,26 +165,48 @@ 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 = '<testsuite name=\\"PSMDB\\">\n'

void makeReport() {
def wholeTestAmount=tests.size()
def wholeTestAmount = tests.size()
def startedTestAmount = 0
def totalTestTime = 0

for (int i=0; i<tests.size(); i++) {
def testName = tests[i]["name"]
def testResult = tests[i]["result"]
def testTime = tests[i]["time"]
def testUrl = "${testUrlPrefix}/${env.GIT_BRANCH}/${env.GIT_SHORT_COMMIT}/${testName}.log"

if (testTime instanceof Number) {
totalTestTime += testTime
}

if (tests[i]["result"] != "skipped") {
startedTestAmount++
}
TestsReport = TestsReport + "\r\n| "+ testName +" | ["+ testResult +"]("+ testUrl +") |"
TestsReport = TestsReport + "\r\n| " + testName + " | [" + testResult + "](" + testUrl + ") | " + formatTime(testTime) + " |"
TestsReportXML = TestsReportXML + '<testcase name=\\"' + testName + '\\" time=\\"' + testTime + '\\"><'+ testResult +'/></testcase>\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 + '</testsuite>\n'

sh """
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -499,7 +537,7 @@ pipeline {
}
}
options {
timeout(time: 3, unit: 'HOURS')
timeout(time: 4, unit: 'HOURS')
}
parallel {
stage('cluster1') {
Expand Down
Loading