From 41c85da559fb63aecd173ddf3583ab57c1479f7a Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Thu, 19 Dec 2024 16:10:08 +0200 Subject: [PATCH 01/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- .../createNamespaceFromBranch/Jenkinsfile | 2 +- vars/folioDeployFlow.groovy | 4 +- vars/folioHelm.groovy | 69 ++++++++++++++----- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile index 7c3cb55a8..b67c867c8 100644 --- a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile @@ -5,7 +5,7 @@ import org.folio.models.RancherNamespace import org.folio.models.parameters.CreateNamespaceParameters import org.folio.models.parameters.CypressTestsParameters -@Library('pipelines-shared-library') _ +@Library('pipelines-shared-library@RANCHER-1970') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index 204441abb..8a8bd375b 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -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.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules) } - pauseBetweenStages(10) + //pauseBetweenStages(10) } postStages() diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 1a42cfc70..57ad5e8be 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -128,26 +128,63 @@ void checkPodRunning(String ns, String podName) { } } -void checkAllPodsRunning(String ns) { - timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { - boolean notAllRunning = true - while (notAllRunning) { - sleep(time: 30, unit: 'SECONDS') +//void checkAllPodsRunning(String ns) { +// timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { +// boolean notAllRunning = true +// while (notAllRunning) { +// sleep(time: 30, unit: 'SECONDS') +// +// def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() +// +// notAllRunning = result.split('\n').any { status -> status != 'Running' } +// +// if (notAllRunning) { +// def evictedPodsList +// println('Not all pods are running. Retrying...') +// try { +// evictedPodsList = sh(script: "kubectl delete pod -n ${ns} --field-selector=\"status.phase==Failed\"", returnStdout: true) +// } catch (Error err) { +// new Logger(this, "managePods").warning("Error: " + err.getMessage() + "\nList of evicted pods: ${evictedPodsList}") +// } +// } else { +// println('All pods are running.') +// } +// } +// } +//} - def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() +void checkAllDeploymentsRunning(String ns, List deploymentNames) { + timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { + println('Checking deployment statuses...') + boolean allDeploymentsUpdated = false - notAllRunning = result.split('\n').any { status -> status != 'Running' } + while (!allDeploymentsUpdated) { + sleep(time: 30, unit: 'SECONDS') + try { + def unfinishedDeployments = [] + deploymentNames.each { name -> + def output = sh( + script: """ + kubectl get deployment ${name} -n ${ns} -o jsonpath='{.metadata.name}' --field-selector=status.updatedReplicas Date: Thu, 19 Dec 2024 17:26:29 +0200 Subject: [PATCH 02/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioNamespaceCreate.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/folioNamespaceCreate.groovy b/vars/folioNamespaceCreate.groovy index 3909c598f..c81517891 100644 --- a/vars/folioNamespaceCreate.groovy +++ b/vars/folioNamespaceCreate.groovy @@ -136,6 +136,7 @@ void call(CreateNamespaceParameters args) { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) // folioHelm.checkAllPodsRunning(namespace.getNamespaceName()) + folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } } From 9a00cef8dc218d41bae08d6786c04ca91f53390c Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 00:40:54 +0200 Subject: [PATCH 03/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- .../moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile | 2 +- vars/folioHelm.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile index 5bf8a2b6c..70d4bef7d 100644 --- a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile @@ -9,7 +9,7 @@ import org.folio.rest_v2.Main import org.folio.utilities.GitHubClient import org.folio.utilities.Logger -@Library('pipelines-shared-library') _ +@Library('pipelines-shared-library@RANCHER-1970') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 57ad5e8be..9d5815b0e 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,7 +153,7 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, List deploymentNames) { +void checkAllDeploymentsRunning(String ns, List deploymentNames) { timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { println('Checking deployment statuses...') boolean allDeploymentsUpdated = false From cf5bdd194677a419988f209b0106cec144ff6d99 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 01:37:36 +0200 Subject: [PATCH 04/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 9d5815b0e..57ad5e8be 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,7 +153,7 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, List deploymentNames) { +void checkAllDeploymentsRunning(String ns, List deploymentNames) { timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { println('Checking deployment statuses...') boolean allDeploymentsUpdated = false From 76ba565d4ea6fe27689e294b6aa5f16ee4541127 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 10:58:59 +0200 Subject: [PATCH 05/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 57ad5e8be..971fc5a90 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -165,7 +165,7 @@ void checkAllDeploymentsRunning(String ns, List deploymentNames) { deploymentNames.each { name -> def output = sh( script: """ - kubectl get deployment ${name} -n ${ns} -o jsonpath='{.metadata.name}' --field-selector=status.updatedReplicas Date: Fri, 20 Dec 2024 15:01:52 +0200 Subject: [PATCH 06/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 70 +++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 971fc5a90..2fc7c0bec 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,43 +153,55 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, List deploymentNames) { - timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { - println('Checking deployment statuses...') - boolean allDeploymentsUpdated = false +void checkAllDeploymentsRunning(String namespace, List deploymentNames) { + println('Starting deployment monitoring...') + boolean allDeploymentsUpdated = false - while (!allDeploymentsUpdated) { - sleep(time: 30, unit: 'SECONDS') - try { - def unfinishedDeployments = [] - deploymentNames.each { name -> - def output = sh( - script: """ - kubectl get deployment ${name} -n ${ns} -o jsonpath='{.metadata.name}' --field-selector=status.updatedReplicas=0 - """, - returnStdout: true - ).trim() - - if (output) { - unfinishedDeployments << output - } - } + while (!allDeploymentsUpdated) { + def deploymentJsonList = [] + def unfinishedDeployments = [] - if (unfinishedDeployments) { - println("Deployments not fully updated: ${unfinishedDeployments}") - println("Rechecking in 30 seconds...") - } else { - println("All deployments are updated successfully!") - allDeploymentsUpdated = true + // Сбор JSON-объектов для каждого деплоймента + deploymentNames.each { name -> + try { + def output = sh( + script: """ + kubectl get deployment ${name} -n ${namespace} -o json + """, + returnStdout: true + ).trim() + + if (output) { + def deploymentJson = new JsonSlurper().parseText(output) + deploymentJsonList << deploymentJson } - } catch (Exception err) { - println("Error occurred: ${err.getMessage()}") - break + } catch (Exception e) { + println("Error fetching deployment '${name}': ${e.message}") } } + println("Collected JSON objects: ${deploymentJsonList}") + // Проверка условий для каждого деплоймента + deploymentJsonList.each { deployment -> + def replicas = deployment?.status?.replicas ?: 0 + def updatedReplicas = deployment?.status?.updatedReplicas ?: 0 + + if (updatedReplicas < replicas) { + unfinishedDeployments << deployment.metadata.name + } + } + + if (unfinishedDeployments) { + println("Unfinished deployments: ${unfinishedDeployments}") + println("Rechecking in 30 seconds...") + sleep(time: 30, unit: 'SECONDS') + } else { + println("All deployments are successfully updated!") + allDeploymentsUpdated = true + } } } + static String valuesPathOption(String path) { return path.trim() ? "-f ${path}" : '' } From f64c274effe8ed880845ab9484eef387708bbbfc Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 15:16:30 +0200 Subject: [PATCH 07/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 2fc7c0bec..2eca3e498 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -172,7 +172,7 @@ void checkAllDeploymentsRunning(String namespace, List deploymentNames) ).trim() if (output) { - def deploymentJson = new JsonSlurper().parseText(output) + def deploymentJson = readJSON(text: output) deploymentJsonList << deploymentJson } } catch (Exception e) { From e78791efea05563c408bfa788616d75ce18dffcb Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 10:24:52 +0200 Subject: [PATCH 08/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 98 ++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 2eca3e498..5a5b43f71 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -1,6 +1,7 @@ import org.folio.Constants import org.folio.models.RancherNamespace import org.folio.models.module.FolioModule +import org.folio.models.module.ModuleType import org.folio.utilities.Logger import java.time.LocalDateTime @@ -153,55 +154,86 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String namespace, List deploymentNames) { +void checkAllDeploymentsRunning(String ns, def deploymentsInput) { println('Starting deployment monitoring...') - boolean allDeploymentsUpdated = false - while (!allDeploymentsUpdated) { - def deploymentJsonList = [] - def unfinishedDeployments = [] + // Check the input parameter and convert it to a list + List deploymentsList + if (deploymentsInput instanceof List) { + deploymentsList = deploymentsInput + } else if (deploymentsInput instanceof FolioModule) { + deploymentsList = [deploymentsInput] + } + + boolean allDeploymentsUpdated = false + int timer = 0 + int maxTime = 10 * 60 // 10 minutes in seconds - // Сбор JSON-объектов для каждого деплоймента - deploymentNames.each { name -> + try { + while (!allDeploymentsUpdated) { + def jsonOutput try { - def output = sh( - script: """ - kubectl get deployment ${name} -n ${namespace} -o json - """, + // 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}") + } - if (output) { - def deploymentJson = readJSON(text: output) - deploymentJsonList << deploymentJson - } + def deploymentsJson + try { + // Parse the JSON output + deploymentsJson = readJSON text: jsonOutput } catch (Exception e) { - println("Error fetching deployment '${name}': ${e.message}") + error("Failed to parse JSON output: ${e.message}") } - } - println("Collected JSON objects: ${deploymentJsonList}") - // Проверка условий для каждого деплоймента - deploymentJsonList.each { deployment -> - def replicas = deployment?.status?.replicas ?: 0 - def updatedReplicas = deployment?.status?.updatedReplicas ?: 0 - - if (updatedReplicas < replicas) { - unfinishedDeployments << deployment.metadata.name + + // 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.") } - } - if (unfinishedDeployments) { - println("Unfinished deployments: ${unfinishedDeployments}") - println("Rechecking in 30 seconds...") - sleep(time: 30, unit: 'SECONDS') - } else { - println("All deployments are successfully updated!") - allDeploymentsUpdated = true + def unfinishedDeployments = [] + + // Check each deployment from the list + deploymentsList.each { folioModule -> + def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } + if (deployment) { + if (deployment.status.updatedReplicas != deployment.spec.replicas) { + 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}" : '' } From 0c26598f411d678375dc4f9974268fc8c0754e7a Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 12:18:15 +0200 Subject: [PATCH 09/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioDeployFlow.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index 8a8bd375b..c59b352d1 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -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.checkAllDeploymentsRunning(namespace.getNamespaceName(), edgeModules) } pauseBetweenStages() } From 8c2dad21baf3f632f4cd92fb6c079c091c4418be Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 13:24:24 +0200 Subject: [PATCH 10/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioDeployFlow.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index c59b352d1..63b193f62 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -41,7 +41,7 @@ void backend(RancherNamespace namespace, Closure preStages = { -> }, Closure pos stage('[Helm] Deploy backend') { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) - folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules) + folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } //pauseBetweenStages(10) } From 98860470910895e8f73711acbecd589babf5cfe6 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:06:12 +0200 Subject: [PATCH 11/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- resources/helm/development.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/helm/development.yaml b/resources/helm/development.yaml index a1dbe7c0f..a3183a199 100644 --- a/resources/helm/development.yaml +++ b/resources/helm/development.yaml @@ -1566,6 +1566,15 @@ mod-inventory: memory: 1609Mi extraJavaOpts: - -XX:MaxRAMPercentage=85.0 + readinessProbe: + httpGet: + path: /admin/health + port: 9402 + initialDelaySeconds: 60 + periodSeconds: 20 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 30 startupProbe: httpGet: path: /admin/health From f739cbb29871b00354a1dd3e963956755e5a5cff Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:38:53 +0200 Subject: [PATCH 12/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 5a5b43f71..36386cd76 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -201,7 +201,10 @@ void checkAllDeploymentsRunning(String ns, def deploymentsInput) { deploymentsList.each { folioModule -> def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } if (deployment) { - if (deployment.status.updatedReplicas != deployment.spec.replicas) { + if (if (deployment.status.updatedReplicas != deployment.spec.replicas || + deployment.status.readyReplicas != deployment.spec.replicas || + deployment.status.unavailableReplicas > 0 || + deployment.status.conditions.any { it.type == "Available" && it.status == "False" })) { unfinishedDeployments << folioModule.name } } else { From ab9f750a05eaddcf2ecdfc323fe337b70ae60c10 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:42:20 +0200 Subject: [PATCH 13/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 36386cd76..5cb2b907e 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -201,10 +201,10 @@ void checkAllDeploymentsRunning(String ns, def deploymentsInput) { deploymentsList.each { folioModule -> def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } if (deployment) { - if (if (deployment.status.updatedReplicas != deployment.spec.replicas || + if (deployment.status.updatedReplicas != deployment.spec.replicas || deployment.status.readyReplicas != deployment.spec.replicas || deployment.status.unavailableReplicas > 0 || - deployment.status.conditions.any { it.type == "Available" && it.status == "False" })) { + deployment.status.conditions.any { it.type == "Available" && it.status == "False" }) { unfinishedDeployments << folioModule.name } } else { From 6444f6f0ba585eb9cb8efb0e40865cdd163bdca9 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:54:41 +0200 Subject: [PATCH 14/37] RANCHER-1970: revert temp changes --- resources/helm/development.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/resources/helm/development.yaml b/resources/helm/development.yaml index a3183a199..a1dbe7c0f 100644 --- a/resources/helm/development.yaml +++ b/resources/helm/development.yaml @@ -1566,15 +1566,6 @@ mod-inventory: memory: 1609Mi extraJavaOpts: - -XX:MaxRAMPercentage=85.0 - readinessProbe: - httpGet: - path: /admin/health - port: 9402 - initialDelaySeconds: 60 - periodSeconds: 20 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 30 startupProbe: httpGet: path: /admin/health From fa0eabe405eb99105e250c92b90b60ff536ee73e Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:59:21 +0200 Subject: [PATCH 15/37] RANCHER-1970: revert temp changes --- .../moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile | 2 +- .../manageNamespace/createNamespaceFromBranch/Jenkinsfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile index 70d4bef7d..5bf8a2b6c 100644 --- a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile @@ -9,7 +9,7 @@ import org.folio.rest_v2.Main import org.folio.utilities.GitHubClient import org.folio.utilities.Logger -@Library('pipelines-shared-library@RANCHER-1970') _ +@Library('pipelines-shared-library') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), diff --git a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile index b67c867c8..7c3cb55a8 100644 --- a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile @@ -5,7 +5,7 @@ import org.folio.models.RancherNamespace import org.folio.models.parameters.CreateNamespaceParameters import org.folio.models.parameters.CypressTestsParameters -@Library('pipelines-shared-library@RANCHER-1970') _ +@Library('pipelines-shared-library') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), From a0614d86eed277066b26dca4a0896592809e2bf7 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 17:10:08 +0200 Subject: [PATCH 16/37] RANCHER-1970: rename method --- vars/folioDeployFlow.groovy | 4 ++-- vars/folioHelm.groovy | 12 +++++++----- vars/folioNamespaceCreate.groovy | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index 63b193f62..f9dfd6fbd 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -41,7 +41,7 @@ void backend(RancherNamespace namespace, Closure preStages = { -> }, Closure pos stage('[Helm] Deploy backend') { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) - folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } //pauseBetweenStages(10) } @@ -76,7 +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.checkAllDeploymentsRunning(namespace.getNamespaceName(), edgeModules) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), edgeModules) } pauseBetweenStages() } diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 5cb2b907e..57e9308d0 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -154,7 +154,7 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, def deploymentsInput) { +void checkDeploymentsRunning(String ns, def deploymentsInput) { println('Starting deployment monitoring...') // Check the input parameter and convert it to a list @@ -201,10 +201,12 @@ void checkAllDeploymentsRunning(String ns, def deploymentsInput) { deploymentsList.each { folioModule -> def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } if (deployment) { - if (deployment.status.updatedReplicas != deployment.spec.replicas || - deployment.status.readyReplicas != deployment.spec.replicas || - deployment.status.unavailableReplicas > 0 || - deployment.status.conditions.any { it.type == "Available" && it.status == "False" }) { + 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 { diff --git a/vars/folioNamespaceCreate.groovy b/vars/folioNamespaceCreate.groovy index c81517891..141c6cb3e 100644 --- a/vars/folioNamespaceCreate.groovy +++ b/vars/folioNamespaceCreate.groovy @@ -136,7 +136,7 @@ void call(CreateNamespaceParameters args) { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) // folioHelm.checkAllPodsRunning(namespace.getNamespaceName()) - folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } } From a09831d539ecadfeafaa0bde245c38827856c126 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 17:16:59 +0200 Subject: [PATCH 17/37] RANCHER-1970: rename method --- vars/folioHelm.groovy | 49 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 57e9308d0..ce7f7d2c4 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -1,7 +1,6 @@ import org.folio.Constants import org.folio.models.RancherNamespace import org.folio.models.module.FolioModule -import org.folio.models.module.ModuleType import org.folio.utilities.Logger import java.time.LocalDateTime @@ -129,30 +128,30 @@ void checkPodRunning(String ns, String podName) { } } -//void checkAllPodsRunning(String ns) { -// timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { -// boolean notAllRunning = true -// while (notAllRunning) { -// sleep(time: 30, unit: 'SECONDS') -// -// def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() -// -// notAllRunning = result.split('\n').any { status -> status != 'Running' } -// -// if (notAllRunning) { -// def evictedPodsList -// println('Not all pods are running. Retrying...') -// try { -// evictedPodsList = sh(script: "kubectl delete pod -n ${ns} --field-selector=\"status.phase==Failed\"", returnStdout: true) -// } catch (Error err) { -// new Logger(this, "managePods").warning("Error: " + err.getMessage() + "\nList of evicted pods: ${evictedPodsList}") -// } -// } else { -// println('All pods are running.') -// } -// } -// } -//} +void checkAllPodsRunning(String ns) { + timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { + boolean notAllRunning = true + while (notAllRunning) { + sleep(time: 30, unit: 'SECONDS') + + def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() + + notAllRunning = result.split('\n').any { status -> status != 'Running' } + + if (notAllRunning) { + def evictedPodsList + println('Not all pods are running. Retrying...') + try { + evictedPodsList = sh(script: "kubectl delete pod -n ${ns} --field-selector=\"status.phase==Failed\"", returnStdout: true) + } catch (Error err) { + new Logger(this, "managePods").warning("Error: " + err.getMessage() + "\nList of evicted pods: ${evictedPodsList}") + } + } else { + println('All pods are running.') + } + } + } +} void checkDeploymentsRunning(String ns, def deploymentsInput) { println('Starting deployment monitoring...') From 28481b6e041359e12cfac8a5fbde8091cb862fba Mon Sep 17 00:00:00 2001 From: Oleksandr Haimanov Date: Mon, 23 Dec 2024 18:36:27 +0200 Subject: [PATCH 18/37] Update logic for input parameters --- vars/folioHelm.groovy | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index ce7f7d2c4..d605e7529 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,16 +153,12 @@ void checkAllPodsRunning(String ns) { } } -void checkDeploymentsRunning(String ns, def deploymentsInput) { - println('Starting deployment monitoring...') +void checkDeploymentsRunning(String ns, FolioModule deploymentModule) { + checkDeploymentsRunning(ns, [deploymentModule]) +} - // Check the input parameter and convert it to a list - List deploymentsList - if (deploymentsInput instanceof List) { - deploymentsList = deploymentsInput - } else if (deploymentsInput instanceof FolioModule) { - deploymentsList = [deploymentsInput] - } +void checkDeploymentsRunning(String ns, List deploymentsList) { + println('Starting deployment monitoring...') boolean allDeploymentsUpdated = false int timer = 0 From 3d9e3d13a48c93c11aaa0acdb16dfb14a25e48e1 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Thu, 19 Dec 2024 16:10:08 +0200 Subject: [PATCH 19/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- .../createNamespaceFromBranch/Jenkinsfile | 2 +- vars/folioDeployFlow.groovy | 4 +- vars/folioHelm.groovy | 69 ++++++++++++++----- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile index 7c3cb55a8..b67c867c8 100644 --- a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile @@ -5,7 +5,7 @@ import org.folio.models.RancherNamespace import org.folio.models.parameters.CreateNamespaceParameters import org.folio.models.parameters.CypressTestsParameters -@Library('pipelines-shared-library') _ +@Library('pipelines-shared-library@RANCHER-1970') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index 204441abb..8a8bd375b 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -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.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules) } - pauseBetweenStages(10) + //pauseBetweenStages(10) } postStages() diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 1a42cfc70..57ad5e8be 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -128,26 +128,63 @@ void checkPodRunning(String ns, String podName) { } } -void checkAllPodsRunning(String ns) { - timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { - boolean notAllRunning = true - while (notAllRunning) { - sleep(time: 30, unit: 'SECONDS') +//void checkAllPodsRunning(String ns) { +// timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { +// boolean notAllRunning = true +// while (notAllRunning) { +// sleep(time: 30, unit: 'SECONDS') +// +// def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() +// +// notAllRunning = result.split('\n').any { status -> status != 'Running' } +// +// if (notAllRunning) { +// def evictedPodsList +// println('Not all pods are running. Retrying...') +// try { +// evictedPodsList = sh(script: "kubectl delete pod -n ${ns} --field-selector=\"status.phase==Failed\"", returnStdout: true) +// } catch (Error err) { +// new Logger(this, "managePods").warning("Error: " + err.getMessage() + "\nList of evicted pods: ${evictedPodsList}") +// } +// } else { +// println('All pods are running.') +// } +// } +// } +//} - def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() +void checkAllDeploymentsRunning(String ns, List deploymentNames) { + timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { + println('Checking deployment statuses...') + boolean allDeploymentsUpdated = false - notAllRunning = result.split('\n').any { status -> status != 'Running' } + while (!allDeploymentsUpdated) { + sleep(time: 30, unit: 'SECONDS') + try { + def unfinishedDeployments = [] + deploymentNames.each { name -> + def output = sh( + script: """ + kubectl get deployment ${name} -n ${ns} -o jsonpath='{.metadata.name}' --field-selector=status.updatedReplicas Date: Thu, 19 Dec 2024 17:26:29 +0200 Subject: [PATCH 20/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioNamespaceCreate.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/folioNamespaceCreate.groovy b/vars/folioNamespaceCreate.groovy index 3909c598f..c81517891 100644 --- a/vars/folioNamespaceCreate.groovy +++ b/vars/folioNamespaceCreate.groovy @@ -136,6 +136,7 @@ void call(CreateNamespaceParameters args) { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) // folioHelm.checkAllPodsRunning(namespace.getNamespaceName()) + folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } } From 9ccf23f2de60d89bf96d650965d411862639cf0f Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 00:40:54 +0200 Subject: [PATCH 21/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- .../moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile | 2 +- vars/folioHelm.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile index 5bf8a2b6c..70d4bef7d 100644 --- a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile @@ -9,7 +9,7 @@ import org.folio.rest_v2.Main import org.folio.utilities.GitHubClient import org.folio.utilities.Logger -@Library('pipelines-shared-library') _ +@Library('pipelines-shared-library@RANCHER-1970') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 57ad5e8be..9d5815b0e 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,7 +153,7 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, List deploymentNames) { +void checkAllDeploymentsRunning(String ns, List deploymentNames) { timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { println('Checking deployment statuses...') boolean allDeploymentsUpdated = false From 9acf44ac98e74e8183de82e98fa51e16cecf2be3 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 01:37:36 +0200 Subject: [PATCH 22/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 9d5815b0e..57ad5e8be 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,7 +153,7 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, List deploymentNames) { +void checkAllDeploymentsRunning(String ns, List deploymentNames) { timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { println('Checking deployment statuses...') boolean allDeploymentsUpdated = false From d0a7bb9c06fc0be4dcb8251a09124ff181b1f437 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 10:58:59 +0200 Subject: [PATCH 23/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 57ad5e8be..971fc5a90 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -165,7 +165,7 @@ void checkAllDeploymentsRunning(String ns, List deploymentNames) { deploymentNames.each { name -> def output = sh( script: """ - kubectl get deployment ${name} -n ${ns} -o jsonpath='{.metadata.name}' --field-selector=status.updatedReplicas Date: Fri, 20 Dec 2024 15:01:52 +0200 Subject: [PATCH 24/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 70 +++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 971fc5a90..2fc7c0bec 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,43 +153,55 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, List deploymentNames) { - timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { - println('Checking deployment statuses...') - boolean allDeploymentsUpdated = false +void checkAllDeploymentsRunning(String namespace, List deploymentNames) { + println('Starting deployment monitoring...') + boolean allDeploymentsUpdated = false - while (!allDeploymentsUpdated) { - sleep(time: 30, unit: 'SECONDS') - try { - def unfinishedDeployments = [] - deploymentNames.each { name -> - def output = sh( - script: """ - kubectl get deployment ${name} -n ${ns} -o jsonpath='{.metadata.name}' --field-selector=status.updatedReplicas=0 - """, - returnStdout: true - ).trim() - - if (output) { - unfinishedDeployments << output - } - } + while (!allDeploymentsUpdated) { + def deploymentJsonList = [] + def unfinishedDeployments = [] - if (unfinishedDeployments) { - println("Deployments not fully updated: ${unfinishedDeployments}") - println("Rechecking in 30 seconds...") - } else { - println("All deployments are updated successfully!") - allDeploymentsUpdated = true + // Сбор JSON-объектов для каждого деплоймента + deploymentNames.each { name -> + try { + def output = sh( + script: """ + kubectl get deployment ${name} -n ${namespace} -o json + """, + returnStdout: true + ).trim() + + if (output) { + def deploymentJson = new JsonSlurper().parseText(output) + deploymentJsonList << deploymentJson } - } catch (Exception err) { - println("Error occurred: ${err.getMessage()}") - break + } catch (Exception e) { + println("Error fetching deployment '${name}': ${e.message}") } } + println("Collected JSON objects: ${deploymentJsonList}") + // Проверка условий для каждого деплоймента + deploymentJsonList.each { deployment -> + def replicas = deployment?.status?.replicas ?: 0 + def updatedReplicas = deployment?.status?.updatedReplicas ?: 0 + + if (updatedReplicas < replicas) { + unfinishedDeployments << deployment.metadata.name + } + } + + if (unfinishedDeployments) { + println("Unfinished deployments: ${unfinishedDeployments}") + println("Rechecking in 30 seconds...") + sleep(time: 30, unit: 'SECONDS') + } else { + println("All deployments are successfully updated!") + allDeploymentsUpdated = true + } } } + static String valuesPathOption(String path) { return path.trim() ? "-f ${path}" : '' } From 3c230319292b87e4d2ec0cd88abe16c91a9f92de Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Fri, 20 Dec 2024 15:16:30 +0200 Subject: [PATCH 25/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 2fc7c0bec..2eca3e498 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -172,7 +172,7 @@ void checkAllDeploymentsRunning(String namespace, List deploymentNames) ).trim() if (output) { - def deploymentJson = new JsonSlurper().parseText(output) + def deploymentJson = readJSON(text: output) deploymentJsonList << deploymentJson } } catch (Exception e) { From 7933a107ca02e9405dd53d7487a7b83b9aea17ae Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 10:24:52 +0200 Subject: [PATCH 26/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 98 ++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 2eca3e498..5a5b43f71 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -1,6 +1,7 @@ import org.folio.Constants import org.folio.models.RancherNamespace import org.folio.models.module.FolioModule +import org.folio.models.module.ModuleType import org.folio.utilities.Logger import java.time.LocalDateTime @@ -153,55 +154,86 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String namespace, List deploymentNames) { +void checkAllDeploymentsRunning(String ns, def deploymentsInput) { println('Starting deployment monitoring...') - boolean allDeploymentsUpdated = false - while (!allDeploymentsUpdated) { - def deploymentJsonList = [] - def unfinishedDeployments = [] + // Check the input parameter and convert it to a list + List deploymentsList + if (deploymentsInput instanceof List) { + deploymentsList = deploymentsInput + } else if (deploymentsInput instanceof FolioModule) { + deploymentsList = [deploymentsInput] + } + + boolean allDeploymentsUpdated = false + int timer = 0 + int maxTime = 10 * 60 // 10 minutes in seconds - // Сбор JSON-объектов для каждого деплоймента - deploymentNames.each { name -> + try { + while (!allDeploymentsUpdated) { + def jsonOutput try { - def output = sh( - script: """ - kubectl get deployment ${name} -n ${namespace} -o json - """, + // 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}") + } - if (output) { - def deploymentJson = readJSON(text: output) - deploymentJsonList << deploymentJson - } + def deploymentsJson + try { + // Parse the JSON output + deploymentsJson = readJSON text: jsonOutput } catch (Exception e) { - println("Error fetching deployment '${name}': ${e.message}") + error("Failed to parse JSON output: ${e.message}") } - } - println("Collected JSON objects: ${deploymentJsonList}") - // Проверка условий для каждого деплоймента - deploymentJsonList.each { deployment -> - def replicas = deployment?.status?.replicas ?: 0 - def updatedReplicas = deployment?.status?.updatedReplicas ?: 0 - - if (updatedReplicas < replicas) { - unfinishedDeployments << deployment.metadata.name + + // 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.") } - } - if (unfinishedDeployments) { - println("Unfinished deployments: ${unfinishedDeployments}") - println("Rechecking in 30 seconds...") - sleep(time: 30, unit: 'SECONDS') - } else { - println("All deployments are successfully updated!") - allDeploymentsUpdated = true + def unfinishedDeployments = [] + + // Check each deployment from the list + deploymentsList.each { folioModule -> + def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } + if (deployment) { + if (deployment.status.updatedReplicas != deployment.spec.replicas) { + 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}" : '' } From 3c80fbc357d57d3821e2f36cf5765a6245b3ccb6 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 12:18:15 +0200 Subject: [PATCH 27/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioDeployFlow.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index 8a8bd375b..c59b352d1 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -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.checkAllDeploymentsRunning(namespace.getNamespaceName(), edgeModules) } pauseBetweenStages() } From 13508d2bc107094d62069c8b34e9d9a85b5b4db8 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 13:24:24 +0200 Subject: [PATCH 28/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioDeployFlow.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index c59b352d1..63b193f62 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -41,7 +41,7 @@ void backend(RancherNamespace namespace, Closure preStages = { -> }, Closure pos stage('[Helm] Deploy backend') { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) - folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules) + folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } //pauseBetweenStages(10) } From a54853542c905f0af62837fbbca12b8fd2752c8a Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:06:12 +0200 Subject: [PATCH 29/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- resources/helm/development.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/helm/development.yaml b/resources/helm/development.yaml index a1dbe7c0f..a3183a199 100644 --- a/resources/helm/development.yaml +++ b/resources/helm/development.yaml @@ -1566,6 +1566,15 @@ mod-inventory: memory: 1609Mi extraJavaOpts: - -XX:MaxRAMPercentage=85.0 + readinessProbe: + httpGet: + path: /admin/health + port: 9402 + initialDelaySeconds: 60 + periodSeconds: 20 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 30 startupProbe: httpGet: path: /admin/health From 5bd13e99410e8736e1ec1618d37e2a264b67df8f Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:38:53 +0200 Subject: [PATCH 30/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 5a5b43f71..36386cd76 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -201,7 +201,10 @@ void checkAllDeploymentsRunning(String ns, def deploymentsInput) { deploymentsList.each { folioModule -> def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } if (deployment) { - if (deployment.status.updatedReplicas != deployment.spec.replicas) { + if (if (deployment.status.updatedReplicas != deployment.spec.replicas || + deployment.status.readyReplicas != deployment.spec.replicas || + deployment.status.unavailableReplicas > 0 || + deployment.status.conditions.any { it.type == "Available" && it.status == "False" })) { unfinishedDeployments << folioModule.name } } else { From 54cb2fdea0d367afe27cababc7da125e5b2eec67 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:42:20 +0200 Subject: [PATCH 31/37] RANCHER-1970: add checkAllDeploymentsRunning status method --- vars/folioHelm.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 36386cd76..5cb2b907e 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -201,10 +201,10 @@ void checkAllDeploymentsRunning(String ns, def deploymentsInput) { deploymentsList.each { folioModule -> def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } if (deployment) { - if (if (deployment.status.updatedReplicas != deployment.spec.replicas || + if (deployment.status.updatedReplicas != deployment.spec.replicas || deployment.status.readyReplicas != deployment.spec.replicas || deployment.status.unavailableReplicas > 0 || - deployment.status.conditions.any { it.type == "Available" && it.status == "False" })) { + deployment.status.conditions.any { it.type == "Available" && it.status == "False" }) { unfinishedDeployments << folioModule.name } } else { From 3cf844719468bd2d1247078baaa5c5396f2c06c0 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:54:41 +0200 Subject: [PATCH 32/37] RANCHER-1970: revert temp changes --- resources/helm/development.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/resources/helm/development.yaml b/resources/helm/development.yaml index a3183a199..a1dbe7c0f 100644 --- a/resources/helm/development.yaml +++ b/resources/helm/development.yaml @@ -1566,15 +1566,6 @@ mod-inventory: memory: 1609Mi extraJavaOpts: - -XX:MaxRAMPercentage=85.0 - readinessProbe: - httpGet: - path: /admin/health - port: 9402 - initialDelaySeconds: 60 - periodSeconds: 20 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 30 startupProbe: httpGet: path: /admin/health From a844161fc7c6922a00600ef58f229883fba7958f Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 14:59:21 +0200 Subject: [PATCH 33/37] RANCHER-1970: revert temp changes --- .../moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile | 2 +- .../manageNamespace/createNamespaceFromBranch/Jenkinsfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile index 70d4bef7d..5bf8a2b6c 100644 --- a/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioDevTools/moduleDeployment/deployModuleFromFeatureBranch/Jenkinsfile @@ -9,7 +9,7 @@ import org.folio.rest_v2.Main import org.folio.utilities.GitHubClient import org.folio.utilities.Logger -@Library('pipelines-shared-library@RANCHER-1970') _ +@Library('pipelines-shared-library') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), diff --git a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile index b67c867c8..7c3cb55a8 100644 --- a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile +++ b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createNamespaceFromBranch/Jenkinsfile @@ -5,7 +5,7 @@ import org.folio.models.RancherNamespace import org.folio.models.parameters.CreateNamespaceParameters import org.folio.models.parameters.CypressTestsParameters -@Library('pipelines-shared-library@RANCHER-1970') _ +@Library('pipelines-shared-library') _ properties([ buildDiscarder(logRotator(numToKeepStr: '30')), From 4342a73f39735bd9164bc6528f980ffd40746119 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 17:10:08 +0200 Subject: [PATCH 34/37] RANCHER-1970: rename method --- vars/folioDeployFlow.groovy | 4 ++-- vars/folioHelm.groovy | 12 +++++++----- vars/folioNamespaceCreate.groovy | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vars/folioDeployFlow.groovy b/vars/folioDeployFlow.groovy index 63b193f62..f9dfd6fbd 100644 --- a/vars/folioDeployFlow.groovy +++ b/vars/folioDeployFlow.groovy @@ -41,7 +41,7 @@ void backend(RancherNamespace namespace, Closure preStages = { -> }, Closure pos stage('[Helm] Deploy backend') { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) - folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } //pauseBetweenStages(10) } @@ -76,7 +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.checkAllDeploymentsRunning(namespace.getNamespaceName(), edgeModules) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), edgeModules) } pauseBetweenStages() } diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 5cb2b907e..57e9308d0 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -154,7 +154,7 @@ void checkPodRunning(String ns, String podName) { // } //} -void checkAllDeploymentsRunning(String ns, def deploymentsInput) { +void checkDeploymentsRunning(String ns, def deploymentsInput) { println('Starting deployment monitoring...') // Check the input parameter and convert it to a list @@ -201,10 +201,12 @@ void checkAllDeploymentsRunning(String ns, def deploymentsInput) { deploymentsList.each { folioModule -> def deployment = deploymentsJson.items.find { it.metadata.name == folioModule.name } if (deployment) { - if (deployment.status.updatedReplicas != deployment.spec.replicas || - deployment.status.readyReplicas != deployment.spec.replicas || - deployment.status.unavailableReplicas > 0 || - deployment.status.conditions.any { it.type == "Available" && it.status == "False" }) { + 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 { diff --git a/vars/folioNamespaceCreate.groovy b/vars/folioNamespaceCreate.groovy index c81517891..141c6cb3e 100644 --- a/vars/folioNamespaceCreate.groovy +++ b/vars/folioNamespaceCreate.groovy @@ -136,7 +136,7 @@ void call(CreateNamespaceParameters args) { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) // folioHelm.checkAllPodsRunning(namespace.getNamespaceName()) - folioHelm.checkAllDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) } } From 4a0df75552ae72a5d0543e44a8ac3c45d361cfd4 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 17:16:59 +0200 Subject: [PATCH 35/37] RANCHER-1970: rename method --- vars/folioHelm.groovy | 49 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index 57e9308d0..ce7f7d2c4 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -1,7 +1,6 @@ import org.folio.Constants import org.folio.models.RancherNamespace import org.folio.models.module.FolioModule -import org.folio.models.module.ModuleType import org.folio.utilities.Logger import java.time.LocalDateTime @@ -129,30 +128,30 @@ void checkPodRunning(String ns, String podName) { } } -//void checkAllPodsRunning(String ns) { -// timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { -// boolean notAllRunning = true -// while (notAllRunning) { -// sleep(time: 30, unit: 'SECONDS') -// -// def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() -// -// notAllRunning = result.split('\n').any { status -> status != 'Running' } -// -// if (notAllRunning) { -// def evictedPodsList -// println('Not all pods are running. Retrying...') -// try { -// evictedPodsList = sh(script: "kubectl delete pod -n ${ns} --field-selector=\"status.phase==Failed\"", returnStdout: true) -// } catch (Error err) { -// new Logger(this, "managePods").warning("Error: " + err.getMessage() + "\nList of evicted pods: ${evictedPodsList}") -// } -// } else { -// println('All pods are running.') -// } -// } -// } -//} +void checkAllPodsRunning(String ns) { + timeout(time: ns == 'ecs-snapshot' ? 20 : 10, unit: 'MINUTES') { + boolean notAllRunning = true + while (notAllRunning) { + sleep(time: 30, unit: 'SECONDS') + + def result = sh(script: "kubectl get pods -n ${ns} --no-headers | awk '{print \$3}'", returnStdout: true).trim() + + notAllRunning = result.split('\n').any { status -> status != 'Running' } + + if (notAllRunning) { + def evictedPodsList + println('Not all pods are running. Retrying...') + try { + evictedPodsList = sh(script: "kubectl delete pod -n ${ns} --field-selector=\"status.phase==Failed\"", returnStdout: true) + } catch (Error err) { + new Logger(this, "managePods").warning("Error: " + err.getMessage() + "\nList of evicted pods: ${evictedPodsList}") + } + } else { + println('All pods are running.') + } + } + } +} void checkDeploymentsRunning(String ns, def deploymentsInput) { println('Starting deployment monitoring...') From ca1d8c81f8318cb7de115d5fbd9a0677dac91af0 Mon Sep 17 00:00:00 2001 From: Oleksandr Haimanov Date: Mon, 23 Dec 2024 18:36:27 +0200 Subject: [PATCH 36/37] Update logic for input parameters --- vars/folioHelm.groovy | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/vars/folioHelm.groovy b/vars/folioHelm.groovy index ce7f7d2c4..d605e7529 100644 --- a/vars/folioHelm.groovy +++ b/vars/folioHelm.groovy @@ -153,16 +153,12 @@ void checkAllPodsRunning(String ns) { } } -void checkDeploymentsRunning(String ns, def deploymentsInput) { - println('Starting deployment monitoring...') +void checkDeploymentsRunning(String ns, FolioModule deploymentModule) { + checkDeploymentsRunning(ns, [deploymentModule]) +} - // Check the input parameter and convert it to a list - List deploymentsList - if (deploymentsInput instanceof List) { - deploymentsList = deploymentsInput - } else if (deploymentsInput instanceof FolioModule) { - deploymentsList = [deploymentsInput] - } +void checkDeploymentsRunning(String ns, List deploymentsList) { + println('Starting deployment monitoring...') boolean allDeploymentsUpdated = false int timer = 0 From 17def9f9c2a4365f41f3d79860ad960251b65565 Mon Sep 17 00:00:00 2001 From: Sergii Masiuk Date: Mon, 23 Dec 2024 19:03:48 +0200 Subject: [PATCH 37/37] RANCHER-1970: replace pod method to new one --- .../folioDevTools/tenantManagement/createConsortia/Jenkinsfile | 3 +-- .../manageNamespace/createDailySnapshotECS/Jenkinsfile | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pipelines/folioRancher/folioDevTools/tenantManagement/createConsortia/Jenkinsfile b/pipelines/folioRancher/folioDevTools/tenantManagement/createConsortia/Jenkinsfile index 371a78d29..8e09d9924 100644 --- a/pipelines/folioRancher/folioDevTools/tenantManagement/createConsortia/Jenkinsfile +++ b/pipelines/folioRancher/folioDevTools/tenantManagement/createConsortia/Jenkinsfile @@ -70,9 +70,8 @@ ansiColor('xterm') { 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()) } - sleep time: 3, unit: 'MINUTES' } stage('[Rest] Create tenants') { diff --git a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createDailySnapshotECS/Jenkinsfile b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createDailySnapshotECS/Jenkinsfile index ca6a35f63..bc26db40d 100644 --- a/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createDailySnapshotECS/Jenkinsfile +++ b/pipelines/folioRancher/folioNamespaceTools/manageNamespace/createDailySnapshotECS/Jenkinsfile @@ -185,6 +185,7 @@ ansiColor('xterm') { stage('Update') { folioHelm.withKubeConfig(namespace.getClusterName()) { folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getBackendModules()) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getBackendModules()) folioEdge.renderEphemeralProperties(namespace) namespace.getModules().getEdgeModules().each { module -> @@ -193,7 +194,7 @@ ansiColor('xterm') { } folioHelm.deployFolioModulesParallel(namespace, namespace.getModules().getEdgeModules()) - folioHelm.checkAllPodsRunning(namespace.getNamespaceName()) + folioHelm.checkDeploymentsRunning(namespace.getNamespaceName(), namespace.getModules().getEdgeModules()) } }