Skip to content

Commit

Permalink
Updates to rancher ha jenkins pipeline (#27)
Browse files Browse the repository at this point in the history
* Getting the k8s versions based on rancher version

debug

Updated the rancher versions script to work for community versions

Debug

Adding windows image

Updating rancherversion script for rke2 and k3s

Debug

Update global vars

Updated rancher version log

* updates to go.mod and go.sum

* resolving golang linter errors
  • Loading branch information
anupama2501 authored Feb 27, 2025
1 parent 7f0ea50 commit 2dee4ee
Show file tree
Hide file tree
Showing 10 changed files with 605 additions and 56 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-version v1.7.0
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
122 changes: 118 additions & 4 deletions validation/pipeline/Jenkinsfile.release.upgrade.ha
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ node {
job_name = job_names[job_names.size() - 1]
}

def config = env.CONFIG
def testContainer = "${job_name}${env.BUILD_NUMBER}_test"
def setupContainer = "${job_name}${env.BUILD_NUMBER}_setup"
def configGeneratorContainer = "${job_name}${env.BUILD_NUMBER}_generator"
def cleanupContainer = "${job_name}${env.BUILD_NUMBER}_cleanup"
def validationVolume = "ValidationSharedVolume-${job_name}${env.BUILD_NUMBER}"
def testRancherVersions = "testrancherk8s.yaml"

def imageName = "rancher-validation-${job_name}${env.BUILD_NUMBER}"

Expand All @@ -29,6 +32,7 @@ node {
def rancherConfig = "rancher_env.config"
def branch = "main"
def defaultTag = "validation"
def localConfigFileName = ""

if ("${env.BRANCH}" != "null" && "${env.BRANCH}" != "") {
branch = "${env.BRANCH}"
Expand Down Expand Up @@ -111,18 +115,117 @@ node {
dir ("./") {
try {
stage('Configure and Build') {
config = config.replace('${AWS_SECRET_ACCESS_KEY}', env.AWS_SECRET_ACCESS_KEY)
config = config.replace('${AWS_ACCESS_KEY_ID}', env.AWS_ACCESS_KEY_ID)
if (env.AWS_SSH_PEM_KEY && env.AWS_SSH_KEY_NAME) {
dir("./validation/.ssh") {
def decoded = new String(AWS_SSH_PEM_KEY.decodeBase64())
writeFile file: AWS_SSH_KEY_NAME, text: decoded
}
}

try{
sh "./tests/v2/validation/build.sh"

sh "docker volume create --name ${validationVolume}"

sh "docker run -v ${validationVolume}:/root --name ${setupContainer} -t -e RANCHER_VERSION=\$RANCHER_VERSION " +
" -e RANCHER_VERSION_TO_UPGRADE=\$RANCHER_VERSION_TO_UPGRADE " +
"${imageName} sh -c \"${workPath}pipeline/scripts/rancher_k8s_version.sh\""

sh "docker cp ${setupContainer}:/root/go/src/github.com/rancher/rancher/testrancherk8s.yaml ./"

println "contents of test rancher versions: ./${testRancherVersions}"

def rancherRKE2Version = sh(
script: "grep -E '^rancherRKE2Version:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE2 version ${rancherRKE2Version}"


def rancherRKE2VersionToUpgrade = sh(
script: "grep 'rancherRKE2VersionToUpgrade' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE2 version to upgrade ${rancherRKE2VersionToUpgrade}"

def rancherK3sVersion = sh(
script: "grep -E '^rancherK3sVersion:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher K3s version ${rancherK3sVersion}"

def rancherK3sVersionToUpgrade = sh(
script: "grep 'rancherK3sVersionToUpgrade' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher K3s version to upgrade ${rancherK3sVersionToUpgrade}"

def rancherRKEVersion = sh(
script: "grep -E '^rancherRKEVersion:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE version ${rancherRKEVersion}"

def rancherRKEVersionToUpgrade = sh(
script: "grep 'rancherRKEVersionToUpgrade' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE version to upgrade ${rancherRKEVersionToUpgrade}"

def rancherVersion = sh(
script: "grep 'rancherVersion:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher version ${rancherVersion}"

def rancherImageTag = sh(
script: "grep 'rancherImageTag:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher rancher image tag version ${rancherImageTag}"

def rancherVersionToUpgrade = sh(
script: "grep 'rancherVersionToUpgrade:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher version to upgrade ${rancherVersionToUpgrade}"

def rancherImageTagToUpgrade = sh(
script: "grep 'rancherImageTagToUpgrade:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher image tag to upgrade version ${rancherImageTagToUpgrade}"

config = config.replace('${RANCHER_RKE2_VERSION}', rancherRKE2Version)
config = config.replace('${RANCHER_RKE2_VERSION_TO_UPGRADE}', rancherRKE2VersionToUpgrade)
config = config.replace('${RANCHER_K3S_VERSION}', rancherK3sVersion)
config = config.replace('${RANCHER_K3S_VERSION_TO_UPGRADE}', rancherK3sVersionToUpgrade)
config = config.replace('${RANCHER_RKE_VERSION}', rancherRKEVersion)
config = config.replace('${RANCHER_RKE_VERSION_TO_UPGRADE}', rancherRKEVersionToUpgrade)
config = config.replace('${RANCHER_VERSION}', rancherVersion)
config = config.replace('${RANCHER_IMAGE_TAG}', rancherImageTag)
config = config.replace('${RANCHER_VERSION_TO_UPGRADE}', rancherVersionToUpgrade)
config = config.replace('${RANCHER_IMAGE_TAG_TO_UPGRADE}', rancherImageTagToUpgrade)
}catch (err){
sh "docker stop ${setupContainer}"
sh "docker rm -v ${setupContainer}"
sh "docker volume rm -f ${validationVolume}"
sh "docker rmi ${imageName}"
}


sh "docker stop ${setupContainer}"
sh "docker rm -v ${setupContainer}"
sh "docker volume rm -f ${validationVolume}"
sh "docker rmi ${imageName}"


dir("./validation") {
def filename = "config.yaml"
def configContents = env.CONFIG

writeFile file: filename, text: configContents
writeFile file: filename, text: config
env.CATTLE_TEST_CONFIG = workPath+filename
}

Expand Down Expand Up @@ -272,9 +375,18 @@ node {

for (int i = 0; i < configs.size(); i++) {
def configName = configs[i]
if (configName.contains('local')) {
echo "skipping pushing local to the global variable"
localConfigFileName = "$configName"
continue
}
echo "pushing ${configName} to the global variable"
configFiles << "${configName}"
}

dir("./${patchedConfigsDir}") {
sh "docker cp ${configGeneratorContainer}:${rootPath}${configsDir}/${localConfigFileName} ."
}

println "Removing the tagged image"
sh "docker rmi -f ${imageName}"
Expand All @@ -290,7 +402,7 @@ node {
configFiles.each {
def configPath = "./${configsDir}/$it"
def absoluteConfigPath = "${rootPath}${configsDir}/$it"

def testCase = sh (
script: "./yq '.testCases.provisioningTestCase' ${configPath}",
returnStdout: true
Expand Down Expand Up @@ -338,11 +450,12 @@ node {
echo "Cluster mapping had failures: " + err
}
}
echo "pushing ${localConfigFileName} to the global variable"
configFiles << "${localConfigFileName}"
}
stage('Run preupgrade checks') {
try {
jobs = [:]

configFiles.each {
try {
def configPath = "./${configsDir}/$it"
Expand Down Expand Up @@ -393,6 +506,7 @@ node {

build job: 'rancher-v3_ha_upgrade', parameters: upgradeParams
}

stage('Run postupgrade checks') {
try {
jobs = [:]
Expand Down
86 changes: 67 additions & 19 deletions validation/pipeline/Jenkinsfile.release.upgrade.local
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ node {
def rancherConfig = "rancher_env.config"
def qaseRun = "testrun"
def testRunConfig = "testrunconfig.yaml"
def testRancherVersions = "testrancherk8s.yaml"

def config = env.CONFIG
def filename = "config.yaml"
Expand Down Expand Up @@ -191,33 +192,79 @@ node {
returnStdout: true
).trim()

def lines = []
if (rancherK8sVersions != "") {
lines = rancherK8sVersions.split('\n')
sh "docker run -v ${validationVolume}:/root --name ${buildTestContainer} -t " +
"${imageName} sh -c \"${workPath}pipeline/scripts/rancher_k8s_version.sh\""

sh "docker cp ${buildTestContainer}:/root/go/src/github.com/rancher/rancher/testrancherk8s.yaml ./"

if (sh(script: "test -s ./${testRancherVersions} && echo 'not_empty' || echo 'empty'", returnStdout: true).trim() == "empty") {
error "ERROR: (${testRancherVersions}) is empty or missing!"
}

def rancherRKE2Version = sh(
script: "grep -E '^rancherRKE2Version:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE2 version ${rancherRKE2Version}"

if (lines.size() >= 8) {
def rancherImageTag = lines[0].replace("Latest Rancher Version: ", "").trim()
def rancherVersion = rancherImageTag.replace("v", "")
def preUpgradeRKE2K8s = lines[2]?.trim()
def postUpgradeRKE2K8s = lines[3]?.trim()
def preUpgradeK3sK8s = lines[4]?.trim()
def postUpgradeK3sK8s = lines[5]?.trim()
def preUpgradeRKE1K8s = lines[6]?.trim()
def postUpgradeRKE1K8s = lines[7]?.trim()

def rancherRKE2VersionToUpgrade = sh(
script: "grep 'rancherRKE2VersionToUpgrade' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE2 version to upgrade ${rancherRKE2VersionToUpgrade}"

def rancherK3sVersion = sh(
script: "grep -E '^rancherK3sVersion:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher K3s version ${rancherK3sVersion}"

def rancherK3sVersionToUpgrade = sh(
script: "grep 'rancherK3sVersionToUpgrade' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher K3s version to upgrade ${rancherK3sVersionToUpgrade}"

def rancherRKEVersion = sh(
script: "grep -E '^rancherRKEVersion:' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE version ${rancherRKEVersion}"

def rancherRKEVersionToUpgrade = sh(
script: "grep 'rancherRKEVersionToUpgrade' ./${testRancherVersions} | awk '{print \$2}'",
returnStdout: true
).trim()
println "Rancher RKE version to upgrade ${rancherRKEVersionToUpgrade}"

def rancherVersion = sh(
script: "grep 'rancherVersion:' ./${testRancherVersions} | awk '{print \$2}' | grep -v '^\$'",
returnStdout: true
).trim()
println "Rancher rancher version ${rancherVersion}"

def rancherImageTag = sh(
script: "grep 'rancherImageTag:' ./${testRancherVersions} | awk '{print \$2}' | grep -v '^\$'",
returnStdout: true
).trim()
println "Rancher rancher image tag version ${rancherImageTag}"

config = config.replace('${RANCHER_VERSION}', rancherVersion)
config = config.replace('${RANCHER_IMAGE_TAG}', rancherImageTag)
config = config.replace('${RANCHER_RKE2_VERSION}', preUpgradeRKE2K8s)
config = config.replace('${RANCHER_RKE2_VERSION_TO_UPGRADE}', postUpgradeRKE2K8s)
config = config.replace('${RANCHER_K3S_VERSION}', preUpgradeK3sK8s)
config = config.replace('${RANCHER_K3S_VERSION_TO_UPGRADE}', postUpgradeK3sK8s)
config = config.replace('${RANCHER_RKE1_VERSION}', preUpgradeRKE1K8s)
config = config.replace('${RANCHER_RKE1_VERSION_TO_UPGRADE}', postUpgradeRKE1K8s)
}
config = config.replace('${RANCHER_RKE2_VERSION}', rancherRKE2Version)
config = config.replace('${RANCHER_RKE2_VERSION_TO_UPGRADE}', rancherRKE2VersionToUpgrade)
config = config.replace('${RANCHER_K3S_VERSION}', rancherK3sVersion)
config = config.replace('${RANCHER_K3S_VERSION_TO_UPGRADE}', rancherK3sVersionToUpgrade)
config = config.replace('${RANCHER_RKE1_VERSION}', rancherVersion)
config = config.replace('${RANCHER_RKE1_VERSION_TO_UPGRADE}', rancherRKEVersionToUpgrade)
} catch (err) {
echo "Unable to get the versions of Rancher and Kubernetes: ${err}"
error "Rancher and k8s versions cannot be retrieved."
sh "docker stop ${buildTestContainer}"
sh "docker rm -v ${buildTestContainer}"
sh "docker volume rm -f ${validationVolume}"
sh "docker rmi ${imageName}"
}

dir("./tests/validation") {
Expand All @@ -238,6 +285,7 @@ node {
}
stage("Build Environment") {
try {

sh "docker run -v ${validationVolume}:/root --name ${buildTestContainer} -t --env-file ${envFile} " +
"${imageName} sh -c \"${workPath}pipeline/scripts/setup_environment.sh;${workPath}pipeline/scripts/build_qase_auto_testrun.sh\""

Expand Down
Loading

0 comments on commit 2dee4ee

Please sign in to comment.