Skip to content
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

RANCHER-1970: Implement pods/deployments status check for helm deployment stages #751

Merged
merged 38 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
41c85da
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
910d7ac
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
9a00cef
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
cf5bdd1
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
76ba565
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 20, 2024
5fce6d1
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 20, 2024
f64c274
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 20, 2024
e78791e
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
0c26598
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
8c2dad2
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
9886047
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
f739cbb
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
ab9f750
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
6444f6f
RANCHER-1970: revert temp changes
sergii-msn Dec 23, 2024
fa0eabe
RANCHER-1970: revert temp changes
sergii-msn Dec 23, 2024
a0614d8
RANCHER-1970: rename method
sergii-msn Dec 23, 2024
a09831d
RANCHER-1970: rename method
sergii-msn Dec 23, 2024
28481b6
Update logic for input parameters
OHaimanov Dec 23, 2024
3d9e3d1
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
48da474
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
9ccf23f
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
9acf44a
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 19, 2024
d0a7bb9
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 20, 2024
f5c8014
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 20, 2024
3c23031
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 20, 2024
7933a10
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
3c80fbc
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
13508d2
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
a548535
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
5bd13e9
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
54cb2fd
RANCHER-1970: add checkAllDeploymentsRunning status method
sergii-msn Dec 23, 2024
3cf8447
RANCHER-1970: revert temp changes
sergii-msn Dec 23, 2024
a844161
RANCHER-1970: revert temp changes
sergii-msn Dec 23, 2024
4342a73
RANCHER-1970: rename method
sergii-msn Dec 23, 2024
4a0df75
RANCHER-1970: rename method
sergii-msn Dec 23, 2024
ca1d8c8
Update logic for input parameters
OHaimanov Dec 23, 2024
17def9f
RANCHER-1970: replace pod method to new one
sergii-msn Dec 23, 2024
d14bef4
Merge remote-tracking branch 'origin/RANCHER-1970' into RANCHER-1970
sergii-msn Dec 23, 2024
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
5 changes: 3 additions & 2 deletions vars/folioDeployFlow.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void backend(RancherNamespace namespace, Closure preStages = { -> }, Closure pos
stage('[Helm] Deploy backend') {
folioHelm.withKubeConfig(namespace.getClusterName()) {
folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules())
// folioHelm.checkAllPodsRunning(namespace.getNamespaceName())
folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules())
}
pauseBetweenStages(10)
//pauseBetweenStages(10)
}

postStages()
Expand Down Expand Up @@ -76,6 +76,7 @@ void edge(RancherNamespace namespace, boolean skipEdgeUsersCreation = false, Clo
kubectl.createConfigMap("${module.name}-ephemeral-properties", namespace.getNamespaceName(), "./${module.name}-ephemeral-properties")
}
folioHelm.deployFolioModulesParallel(namespace, edgeModules)
folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), edgeModules)
}
pauseBetweenStages()
}
Expand Down
81 changes: 81 additions & 0 deletions vars/folioHelm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,87 @@ void checkAllPodsRunning(String ns) {
}
}

void checkDeploymentsRunning(String ns, FolioModule deploymentModule) {
checkDeploymentsRunning(ns, [deploymentModule])
}

void checkDeploymentsRunning(String ns, List<FolioModule> deploymentsList) {
println('Starting deployment monitoring...')

boolean allDeploymentsUpdated = false
int timer = 0
int maxTime = 10 * 60 // 10 minutes in seconds

try {
while (!allDeploymentsUpdated) {
def jsonOutput
try {
// Execute the kubectl command
jsonOutput = sh(
script: "kubectl get deployments -n ${ns} -o json",
returnStdout: true
).trim()
} catch (Exception e) {
error("Failed to execute kubectl command: ${e.message}")
}

def deploymentsJson
try {
// Parse the JSON output
deploymentsJson = readJSON text: jsonOutput
} catch (Exception e) {
error("Failed to parse JSON output: ${e.message}")
}

// Check if there are any deployments in the namespace
if (!deploymentsJson.items || deploymentsJson.items.isEmpty()) {
error("No deployments found in namespace '${ns}'. Please check the namespace or deployment configuration.")
}

def unfinishedDeployments = []

// Check each deployment from the list
deploymentsList.each { folioModule ->
def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name }
if (deployment) {
def status = deployment.status
def specReplicas = deployment.spec.replicas
if (status.updatedReplicas != specReplicas ||
status.readyReplicas != specReplicas ||
status.unavailableReplicas > 0 ||
status.conditions.any { it.type == "Available" && it.status == "False" }) {
unfinishedDeployments << folioModule.name
}
} else {
println("Warning: Deployment '${folioModule.name}' not found in namespace '${ns}'")
}
}

if (unfinishedDeployments) {
println("Unfinished deployments: ${unfinishedDeployments}")
println("Rechecking in 30 seconds...")
sleep(time: 30, unit: 'SECONDS')
timer += 30
} else {
println("All deployments are successfully updated!")
allDeploymentsUpdated = true
}

// Check the timer
if (timer >= maxTime) {
error("Timeout: Some deployments are still not updated after 10 minutes.")
}
}
} catch (Exception e) {
// Handle general errors
println("Error occurred during deployment monitoring: ${e.message}")
throw e // Rethrow the error to mark the Jenkins build as failed
}
}




static String valuesPathOption(String path) {
return path.trim() ? "-f ${path}" : ''
}
Expand Down
1 change: 1 addition & 0 deletions vars/folioNamespaceCreate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void call(CreateNamespaceParameters args) {
folioHelm.withKubeConfig(namespace.getClusterName()) {
folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules())
// folioHelm.checkAllPodsRunning(namespace.getNamespaceName())
folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules())
}
}

Expand Down