From 7aab67dad73298b1388eca3517a1a2ea856a2b8e Mon Sep 17 00:00:00 2001 From: serverhorror <36151+serverhorror@users.noreply.github.com> Date: Tue, 21 Mar 2023 14:05:04 +0100 Subject: [PATCH] Bug/981 component fails to deploy more than one deploymentconfig (#982) --- CHANGELOG.md | 1 + .../phases/FinalizeOdsComponent.groovy | 56 +++++++++---------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0644e3f15..24889762c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Fix Component fails to deploy with more than one DeploymentConfig([#981](https://github.com/opendevstack/ods-jenkins-shared-library/issues/981)) ### Fixed - Change default registry to match Openshift 4 ([#983] (https://github.com/opendevstack/ods-jenkins-shared-library/issues/983)) diff --git a/src/org/ods/orchestration/phases/FinalizeOdsComponent.groovy b/src/org/ods/orchestration/phases/FinalizeOdsComponent.groovy index cc72d1cbf..36a3f8ca8 100644 --- a/src/org/ods/orchestration/phases/FinalizeOdsComponent.groovy +++ b/src/org/ods/orchestration/phases/FinalizeOdsComponent.groovy @@ -137,41 +137,39 @@ class FinalizeOdsComponent { throw new RuntimeException ("Deploymentmeans for repo ${repo.id}" + " are not found. These means are automatically generated!\n" + " Likely you upgraded and tried to deploy to Q instead of rebuilding on dev") - } else if (deploymentMeans.size() > 1) { - throw new RuntimeException ("Found more than 1 Deploymentmeans ${deploymentMeans.size()} " + - "for repo ${repo.id}. This is not supported!") } - Map deploymentMean = deploymentMeans.values().get(0) + deploymentMeans.values().each{deploymentMean-> + String componentSelector = deploymentMean.selector - String componentSelector = deploymentMean.selector + def allComponentDeploymentsByKind = os.getResourcesForComponent( + project.targetProject, + [OpenShiftService.DEPLOYMENTCONFIG_KIND, OpenShiftService.DEPLOYMENT_KIND], + componentSelector + ) + def allComponentDeployments = allComponentDeploymentsByKind[OpenShiftService.DEPLOYMENTCONFIG_KIND] ?: [] + if (allComponentDeploymentsByKind[OpenShiftService.DEPLOYMENT_KIND]) { + allComponentDeployments.addAll(allComponentDeploymentsByKind[OpenShiftService.DEPLOYMENT_KIND]) + } + logger.debug( + "ODS created deployments for ${repo.id}: " + + "${odsBuiltDeployments}, all deployments: ${allComponentDeployments}" + ) - def allComponentDeploymentsByKind = os.getResourcesForComponent( - project.targetProject, - [OpenShiftService.DEPLOYMENTCONFIG_KIND, OpenShiftService.DEPLOYMENT_KIND], - componentSelector - ) - def allComponentDeployments = allComponentDeploymentsByKind[OpenShiftService.DEPLOYMENTCONFIG_KIND] ?: [] - if (allComponentDeploymentsByKind[OpenShiftService.DEPLOYMENT_KIND]) { - allComponentDeployments.addAll(allComponentDeploymentsByKind[OpenShiftService.DEPLOYMENT_KIND]) - } - logger.debug( - "ODS created deployments for ${repo.id}: " + - "${odsBuiltDeployments}, all deployments: ${allComponentDeployments}" - ) + odsBuiltDeployments.each { odsBuiltDeploymentName -> + allComponentDeployments.remove(odsBuiltDeploymentName) + } - odsBuiltDeployments.each { odsBuiltDeploymentName -> - allComponentDeployments.remove(odsBuiltDeploymentName) - } - if (allComponentDeployments != null && allComponentDeployments.size() > 0 ) { - def message = "DeploymentConfigs (component: '${repo.id}') found that are not ODS managed: " + - "'${allComponentDeployments}'!\r" + - "Please fix by rolling them out through 'odsComponentStageRolloutOpenShiftDeployment()'!" - if (project.isWorkInProgress) { - util.warnBuild(message) - } else { - throw new RuntimeException(message) + if (allComponentDeployments != null && allComponentDeployments.size() > 0 ) { + def message = "DeploymentConfigs (component: '${repo.id}') found that are not ODS managed: " + + "'${allComponentDeployments}'!\r" + + "Please fix by rolling them out through 'odsComponentStageRolloutOpenShiftDeployment()'!" + if (project.isWorkInProgress) { + util.warnBuild(message) + } else { + throw new RuntimeException(message) + } } }