Skip to content

Commit

Permalink
Adding script to get rancher and k8s versions
Browse files Browse the repository at this point in the history
  • Loading branch information
anupama2501 committed Nov 13, 2024
1 parent 07757c1 commit 29d71f6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/v2/validation/pipeline/Jenkinsfile.release.upgrade.local
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ 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)
config = config.replace('${AWS_IAM_PROFILE}', env.AWS_IAM_PROFILE)
config = config.replace('${AWS_REGION}', env.AWS_REGION)
config = config.replace('${AWS_VPC}', env.AWS_VPC)
config = config.replace('${AWS_SECURITY_GROUPS}', env.AWS_SECURITY_GROUPS)
config = config.replace('${ADMIN_PASSWORD}', env.ADMIN_PASSWORD)

if (env.AWS_SSH_PEM_KEY && env.AWS_SSH_KEY_NAME) {
dir("./rancher/tests/v2/validation/.ssh") {
def decoded = new String(AWS_SSH_PEM_KEY.decodeBase64())
Expand All @@ -160,9 +168,37 @@ node {
def filename = "config.yaml"
def configContents = env.CONFIG

def rancherK8sVersions = ""
try{
rancherK8sVersions= sh (
script: "${workPath}pipeline/scripts/rancher_k8s_version.sh",
returnStdout: true
)
} catch(err){
echo "Unable to get the versions of rancher and k8s " + err
}

// Parse the output
def lines = rancherK8sVersions.split('\n')
def rancherVersion = lines[0].replace("Latest Rancher Version: ", "").trim()
def k8sVersions = lines[1].replace("Latest Kubernetes Versions: ", "").trim()

def versionArray = k8sVersions.split(',')
def preUpgradeK8s = versionArray[0]?.trim()
def postUpgradeK8s = versionArray[1]?.trim()

echo "Rancher Version: ${rancherVersion}"
echo "Kubernetes Versions: ${k8sVersions}"

sh "./yq e '.corralConfigs.corralConfigVars.rancher_image_tag = \"${rancherVersion}\"' -i ${configPath}"
sh "./yq e '.corralConfigs.corralConfigVars.rancher_version = \"${rancherVersion}\"' -i ${configPath}"
sh "./yq e '.corralConfigs.corralConfigVars.kubernetes_version = \"${preUpgradeK8s}\"' -i ${configPath}"
sh "./yq e '.rancher.host = \"${rancherHostName}\"' -i ${configPath}"

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

dir ("./") {
sh "./rancher/tests/v2/validation/configure.sh"
sh "docker build . -f ./rancher/tests/v2/validation/Dockerfile.e2e --build-arg CORRAL_VERSION=${env.CORRAL_VERSION} --build-arg RKE_VERSION=${env.RKE_VERSION} -t ${imageName}"
Expand Down
16 changes: 16 additions & 0 deletions tests/v2/validation/pipeline/scripts/rancher_k8s_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

latest_rancher_version=$(curl -s https://prime.ribs.rancher.io/index.html | grep "release-v[0-9]*" | sort -V | tail -n 1 | sed -E 's/.*release-(v[0-9]+\.[0-9]+\.[0-9]+).*/\1/')
echo "Latest Rancher Version: $latest_rancher_version"

k8s_versions=$(curl -s "https://prime.ribs.rancher.io/rancher/${latest_rancher_version}/rancher-images.txt" | grep "rancher/hardened-kubernetes:" | awk -F':' '{print $2}' | awk -F '-build' '{print $1}' | sort -V | awk -F '.' '
{versions[$1"."$2] = $0} # Keep only the latest version for each major.minor
END {
for (v in versions) print versions[v]","
}' | sort -V | tail -n 2)


# Output the results
echo "Latest Kubernetes Versions:"
echo "$k8s_versions"

0 comments on commit 29d71f6

Please sign in to comment.