Skip to content

Commit

Permalink
Getting the k8s versions based on rancher version
Browse files Browse the repository at this point in the history
  • Loading branch information
anupama2501 committed Jan 29, 2025
1 parent e1e1bfd commit 7f053e3
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 48 deletions.
126 changes: 102 additions & 24 deletions tests/v2/validation/pipeline/Jenkinsfile.release.upgrade.ha
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ node {
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 filename = "config.yaml"

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

def testsDir = "github.com/rancher/rancher/tests/v2/validation/"
def upgradeTestsDir = "${testsDir}upgrade"
def provisioningTestsDir = "${testsDir}provisioning"
def testRancherVersions = "testrancherk8s.yaml"

def groovyEnvironments = "environments.groovy"
def configsDir = "cattle-configs"
Expand All @@ -29,6 +32,7 @@ node {
def rancherConfig = "rancher_env.config"
def branch = "release/v2.8"
def defaultTag = "validation"
def config = env.CONFIG

if ("${env.BRANCH}" != "null" && "${env.BRANCH}" != "") {
branch = "${env.BRANCH}"
Expand All @@ -52,6 +56,7 @@ node {
paramsMap << "$it.key=$it.value"
}
}

withCredentials([ string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'AWS_ACCESS_KEY_ID'),
string(credentialsId: 'AWS_SECRET_ACCESS_KEY', variable: 'AWS_SECRET_ACCESS_KEY'),
string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'RANCHER_EKS_ACCESS_KEY'),
Expand Down Expand Up @@ -111,23 +116,106 @@ node {
dir ("./") {
try {
stage('Configure and Build') {
sh "docker volume create --name ${validationVolume}"
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("./tests/v2/validation/.ssh") {
def decoded = new String(AWS_SSH_PEM_KEY.decodeBase64())
writeFile file: AWS_SSH_KEY_NAME, text: decoded
}
}

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

try{

sh "docker run -v ${validationVolume}:/root --name ${setupContainer} -t " +
"${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 '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 '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 '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 rancher version ${rancherVersion}"

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

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)


}catch (err){
sh "docker stop ${setupContainer}"
sh "docker rm -v ${setupContainer}"
sh "docker volume rm -f ${validationVolume}"
}

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

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

writeFile file: filename, text: configContents
dir("./rancher/tests/v2/validation") {

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

sh "./tests/v2/validation/configure.sh"
sh "./tests/v2/validation/build.sh"
sh "./tests/v2/validation/configure.sh"
sh "./tests/v2/validation/build.sh"
}
stage('Setup') {
sh returnStdout: true, script: 'wget -qO ./yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64'
Expand All @@ -144,28 +232,16 @@ node {
env.HA_HOST_PREFIX= (env.HA_HOST.substring(0, env.HA_HOST.indexOf('.'))).trim()
println "HA host Prefix: ${env.HA_HOST_PREFIX}"

env.HA_CHART_VERSION= sh (
script: "./yq '.ha.chartVersion' ${initConfigPath}",
returnStdout: true
).trim()
env.HA_CHART_VERSION= env.RANCHER_VERSION
println " HA chart version: ${env.HA_CHART_VERSION}"

env.HA_CHART_VERSION_TO_UPGRADE= sh (
script: "./yq '.ha.chartVersionToUpgrade' ${initConfigPath}",
returnStdout: true
).trim()
env.HA_CHART_VERSION_TO_UPGRADE = env.RANCHER_VERSION_TO_UPGRADE
println "HA chart version to upgrade: ${env.HA_CHART_VERSION_TO_UPGRADE}"

env.HA_IMAGE_TAG= sh (
script: "./yq '.ha.imageTag' ${initConfigPath}",
returnStdout: true
).trim()
env.HA_IMAGE_TAG= "v" + env.RANCHER_VERSION
println "HA image tag: ${env.HA_IMAGE_TAG}"

env.HA_IMAGE_TAG_TO_UPGRADE= sh (
script: "./yq '.ha.imageTagToUpgrade' ${initConfigPath}",
returnStdout: true
).trim()
env.HA_IMAGE_TAG_TO_UPGRADE= env.RANCHER_VERSION_TO_UPGRADE
println "HA image tag to upgrade: ${env.HA_IMAGE_TAG_TO_UPGRADE}"

env.HA_HELM_REPO= sh (
Expand Down Expand Up @@ -270,6 +346,8 @@ node {

def configs = sh(script: "ls -1 ./${configsDir}", returnStdout: true).split()

sh "Printing configs ${configs}"

for (int i = 0; i < configs.size(); i++) {
def configName = configs[i]
echo "pushing ${configName} to the global variable"
Expand Down
Loading

0 comments on commit 7f053e3

Please sign in to comment.