From e1b726b5e73ec656d8c91da45b39ef2ae5efb2f9 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 08:36:52 +0200 Subject: [PATCH 01/38] image stream not supported by EKS --- src/org/ods/component/HelmDeploymentStrategy.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 7b0fb2e1c7..db5bb538fd 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -85,9 +85,10 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { logger.warn 'Skipping because of empty (target) environment ...' return [:] } - + + // TODO s2o: import image // Tag images which have been built in this pipeline from cd project into target project - retagImages(context.targetProject, getBuiltImages()) + // retagImages(context.targetProject, getBuiltImages()) logger.info("Rolling out ${context.componentId} with HELM, selector: ${options.selector}") helmUpgrade(context.targetProject) From 94f048f5aba9bdb547d74c1923f8559e71b4c4a5 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 09:23:44 +0200 Subject: [PATCH 02/38] EKSLoginStage --- src/org/ods/component/EKSLoginStage.groovy | 27 +++++++++++ ...sComponentStageRolloutEKSDeployment.groovy | 45 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/org/ods/component/EKSLoginStage.groovy create mode 100644 vars/odsComponentStageRolloutEKSDeployment.groovy diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy new file mode 100644 index 0000000000..2d481c3a88 --- /dev/null +++ b/src/org/ods/component/EKSLoginStage.groovy @@ -0,0 +1,27 @@ +package org.ods.component + +import groovy.transform.TypeChecked +import groovy.transform.TypeCheckingMode +import org.ods.services.OpenShiftService +import org.ods.util.ILogger + +@SuppressWarnings('ParameterCount') +@TypeChecked +class EKSLoginStage extends Stage { + + public final String STAGE_NAME = 'EKS Login' + + // This is called from Stage#execute + @SuppressWarnings(['AbcMetric']) + @TypeChecked(TypeCheckingMode.SKIP) + protected run() { + int status = steps.sh( + script: "aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME", + returnStatus: true, + label: "Login to -region $AWS_REGION --name $EKS_CLUSTER_NAME" + ) as int + if (status != 0) { + script.error("Could not Login to -region $AWS_REGION --name $EKS_CLUSTER_NAME, status ${status}") + } + } +} diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy new file mode 100644 index 0000000000..582091cb01 --- /dev/null +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -0,0 +1,45 @@ +import org.ods.component.RolloutOpenShiftDeploymentStage +import org.ods.component.IContext +import org.ods.component.EKSLoginStage + +import org.ods.services.OpenShiftService +import org.ods.services.JenkinsService +import org.ods.services.ServiceRegistry +import org.ods.util.Logger +import org.ods.util.ILogger + +def call(IContext context, Map config = [:]) { + ILogger logger = ServiceRegistry.instance.get(Logger) + // this is only for testing, because we need access to the script context :( + if (!logger) { + logger = new Logger (this, !!env.DEBUG) + } + + def stage = new EKSLoginStage( + this, + context, + logger + ) + stage.execute() + + // ODS 3.x allowed to specify resourceName, which is no longer possible. + // Fail if the option is still given to inform about this breaking change. + if (config.resourceName) { + error( + "The config option 'resourceName' has been removed from odsComponentStageRolloutOpenShiftDeployment. " + + "Instead, all resources with a common label are rolled out together. " + + "If you need separate rollouts, consider specifying additional labels " + + "and target those via the 'selector' config option." + ) + return + } + return new RolloutOpenShiftDeploymentStage( + this, + context, + config, + ServiceRegistry.instance.get(OpenShiftService), + ServiceRegistry.instance.get(JenkinsService), + logger + ).execute() +} +return this From 4dad41c20e107bb21731f34b4aa6ee0793260a38 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 09:30:55 +0200 Subject: [PATCH 03/38] EKSLoginStage --- src/org/ods/component/EKSLoginStage.groovy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy index 2d481c3a88..a7ccd83cfa 100644 --- a/src/org/ods/component/EKSLoginStage.groovy +++ b/src/org/ods/component/EKSLoginStage.groovy @@ -11,6 +11,14 @@ class EKSLoginStage extends Stage { public final String STAGE_NAME = 'EKS Login' + @TypeChecked(TypeCheckingMode.SKIP) + EKSLoginStage( + def script, + IContext context, + ILogger logger) { + super(script, context, logger) + } + // This is called from Stage#execute @SuppressWarnings(['AbcMetric']) @TypeChecked(TypeCheckingMode.SKIP) From 428ed42a93a62766ead7ae00ee0d65f1dbab3f1a Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 09:59:08 +0200 Subject: [PATCH 04/38] config Options --- src/org/ods/component/EKSLoginStage.groovy | 8 +++++--- vars/odsComponentStageRolloutEKSDeployment.groovy | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy index a7ccd83cfa..d5befa9fa1 100644 --- a/src/org/ods/component/EKSLoginStage.groovy +++ b/src/org/ods/component/EKSLoginStage.groovy @@ -2,7 +2,6 @@ package org.ods.component import groovy.transform.TypeChecked import groovy.transform.TypeCheckingMode -import org.ods.services.OpenShiftService import org.ods.util.ILogger @SuppressWarnings('ParameterCount') @@ -10,13 +9,16 @@ import org.ods.util.ILogger class EKSLoginStage extends Stage { public final String STAGE_NAME = 'EKS Login' + private final Options options @TypeChecked(TypeCheckingMode.SKIP) EKSLoginStage( def script, - IContext context, + IContext context, + Map config, ILogger logger) { - super(script, context, logger) + super(script, context, logger) + this.options = new Options(config) } // This is called from Stage#execute diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy index 582091cb01..615c36e4b9 100644 --- a/vars/odsComponentStageRolloutEKSDeployment.groovy +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -17,7 +17,8 @@ def call(IContext context, Map config = [:]) { def stage = new EKSLoginStage( this, - context, + context, + config, logger ) stage.execute() From 78282f8c714c2a0b33d6404e660a66fbd9f5bfec Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 10:03:42 +0200 Subject: [PATCH 05/38] RolloutOpenShiftDeploymentOptions --- src/org/ods/component/EKSLoginStage.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy index d5befa9fa1..07405a7f17 100644 --- a/src/org/ods/component/EKSLoginStage.groovy +++ b/src/org/ods/component/EKSLoginStage.groovy @@ -9,7 +9,7 @@ import org.ods.util.ILogger class EKSLoginStage extends Stage { public final String STAGE_NAME = 'EKS Login' - private final Options options + private final RolloutOpenShiftDeploymentOptions options @TypeChecked(TypeCheckingMode.SKIP) EKSLoginStage( @@ -18,7 +18,7 @@ class EKSLoginStage extends Stage { Map config, ILogger logger) { super(script, context, logger) - this.options = new Options(config) + this.options = new RolloutOpenShiftDeploymentOptions(config) } // This is called from Stage#execute From 0aea4b1ef5dd4fa23716834f1b29358be4bfe6a4 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 17:19:08 +0200 Subject: [PATCH 06/38] prepare for imageCopy --- src/org/ods/component/EKSLoginStage.groovy | 17 +++++++---- .../component/HelmDeploymentStrategy.groovy | 2 ++ ...sComponentStageRolloutEKSDeployment.groovy | 28 ++++++++++--------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy index 07405a7f17..44f3dc7ecf 100644 --- a/src/org/ods/component/EKSLoginStage.groovy +++ b/src/org/ods/component/EKSLoginStage.groovy @@ -24,14 +24,21 @@ class EKSLoginStage extends Stage { // This is called from Stage#execute @SuppressWarnings(['AbcMetric']) @TypeChecked(TypeCheckingMode.SKIP) - protected run() { - int status = steps.sh( - script: "aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME", + protected run() { + executeCommand("aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default") + executeCommand("aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default") + executeCommand("aws configure set region $AWS_REGION --profile default") + executeCommand("aws eks update-kubeconfig --region $AWS_REGION --name ${context.getProjectId()}-${context.getEnvironment()}") + } + + private void executeCommand(String command) { + return steps.sh( + script: command, returnStatus: true, - label: "Login to -region $AWS_REGION --name $EKS_CLUSTER_NAME" + label: "Executing command: ${command}" ) as int if (status != 0) { script.error("Could not Login to -region $AWS_REGION --name $EKS_CLUSTER_NAME, status ${status}") - } + } } } diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index db5bb538fd..10e03db6ac 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -87,6 +87,8 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { } // TODO s2o: import image + // In EKS we don't import images, we use the ECR repository directly. + // This is different from OpenShift, where we import images into the ImageStream. // Tag images which have been built in this pipeline from cd project into target project // retagImages(context.targetProject, getBuiltImages()) diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy index 615c36e4b9..0e40c6d83a 100644 --- a/vars/odsComponentStageRolloutEKSDeployment.groovy +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -15,25 +15,27 @@ def call(IContext context, Map config = [:]) { logger = new Logger (this, !!env.DEBUG) } - def stage = new EKSLoginStage( + // Get the current token of OC, as later we login to EKS and we need the token to copy the images + def currentOCToken = sh(script: "oc whoami -t >& /dev/null", label: "Get OpenShift Token", returnStdout: true) + // This step should be executed before the EKSLoginStage, so that the OpenShift token is available + def stageLogin = new EKSLoginStage( this, context, config, logger ) - stage.execute() - - // ODS 3.x allowed to specify resourceName, which is no longer possible. - // Fail if the option is still given to inform about this breaking change. - if (config.resourceName) { - error( - "The config option 'resourceName' has been removed from odsComponentStageRolloutOpenShiftDeployment. " + - "Instead, all resources with a common label are rolled out together. " + - "If you need separate rollouts, consider specifying additional labels " + - "and target those via the 'selector' config option." - ) - return + this.withCredentials([ + string(credentialsId: "${context.cdProject}-aws-region", variable: 'AWS_REGION') + string(credentialsId: "${context.cdProject}-aws-account-id", variable: 'AWS_ACCOUNT_ID'), + string(credentialsId: "${context.cdProject}-aws-access-key-id-dev", variable: 'AWS_ACCESS_KEY_ID'), + string(credentialsId: "${context.cdProject}-aws-secret-access-key-dev", variable: 'AWS_SECRET_ACCESS_KEY')]) { + stageLogin.execute() } + + // TODO: + // sent currentOCToken to RolloutOpenShiftDeploymentStage + // and copy the images from OpenShift to EKS + // change retagImages for something compatible with EKS return new RolloutOpenShiftDeploymentStage( this, context, From af1926c24a48650d566af063a79c480099332912 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 17:24:46 +0200 Subject: [PATCH 07/38] this. --- vars/odsComponentStageRolloutEKSDeployment.groovy | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy index 0e40c6d83a..97dd6eeecc 100644 --- a/vars/odsComponentStageRolloutEKSDeployment.groovy +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -25,10 +25,11 @@ def call(IContext context, Map config = [:]) { logger ) this.withCredentials([ - string(credentialsId: "${context.cdProject}-aws-region", variable: 'AWS_REGION') - string(credentialsId: "${context.cdProject}-aws-account-id", variable: 'AWS_ACCOUNT_ID'), - string(credentialsId: "${context.cdProject}-aws-access-key-id-dev", variable: 'AWS_ACCESS_KEY_ID'), - string(credentialsId: "${context.cdProject}-aws-secret-access-key-dev", variable: 'AWS_SECRET_ACCESS_KEY')]) { + this.string(credentialsId: "${context.cdProject}-aws-region", variable: 'AWS_REGION'), + this.string(credentialsId: "${context.cdProject}-aws-account-id", variable: 'AWS_ACCOUNT_ID'), + this.string(credentialsId: "${context.cdProject}-aws-access-key-id-dev", variable: 'AWS_ACCESS_KEY_ID'), + this.string(credentialsId: "${context.cdProject}-aws-secret-access-key-dev", variable: 'AWS_SECRET_ACCESS_KEY') + ]) { stageLogin.execute() } From e46695e853e7e0a43064b9a8955b893700ac984e Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 31 Jul 2025 17:28:38 +0200 Subject: [PATCH 08/38] AWS_ACCESS_KEY_ID --- src/org/ods/component/EKSLoginStage.groovy | 10 +++++----- vars/odsComponentStageRolloutEKSDeployment.groovy | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy index 44f3dc7ecf..5dfcde934a 100644 --- a/src/org/ods/component/EKSLoginStage.groovy +++ b/src/org/ods/component/EKSLoginStage.groovy @@ -24,11 +24,11 @@ class EKSLoginStage extends Stage { // This is called from Stage#execute @SuppressWarnings(['AbcMetric']) @TypeChecked(TypeCheckingMode.SKIP) - protected run() { - executeCommand("aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default") - executeCommand("aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default") - executeCommand("aws configure set region $AWS_REGION --profile default") - executeCommand("aws eks update-kubeconfig --region $AWS_REGION --name ${context.getProjectId()}-${context.getEnvironment()}") + protected run() { + executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') + executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') + executeCommand('aws configure set region $AWS_REGION --profile default') + executeCommand('aws eks update-kubeconfig --region $AWS_REGION --name' + "${context.getProjectId()}-${context.getEnvironment()}") } private void executeCommand(String command) { diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy index 97dd6eeecc..eb81387298 100644 --- a/vars/odsComponentStageRolloutEKSDeployment.groovy +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -15,9 +15,10 @@ def call(IContext context, Map config = [:]) { logger = new Logger (this, !!env.DEBUG) } - // Get the current token of OC, as later we login to EKS and we need the token to copy the images - def currentOCToken = sh(script: "oc whoami -t >& /dev/null", label: "Get OpenShift Token", returnStdout: true) // This step should be executed before the EKSLoginStage, so that the OpenShift token is available + // as later we need the token to copy the images + def currentOCToken = sh(script: "oc whoami -t >& /dev/null", label: "Get OpenShift Token", returnStdout: true) + def stageLogin = new EKSLoginStage( this, context, From 487ce86d86646c2768759be2cc918ae171967029 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 15:27:10 +0200 Subject: [PATCH 09/38] eks deployment --- .../AbstractDeploymentStrategy.groovy | 17 ---- src/org/ods/component/DeploymentConfig.groovy | 77 ++++++++++++++++ src/org/ods/component/EKSService.groovy | 87 +++++++++++++++++++ .../component/HelmDeploymentStrategy.groovy | 61 +++---------- src/org/ods/component/IImageRepository.groovy | 7 ++ .../ods/component/ImageRepositoryEKS.groovy | 76 ++++++++++++++++ .../component/ImageRepositoryOpenshift.groovy | 40 +++++++++ .../RolloutEKSDeploymentStage.groovy | 65 ++++++++++++++ .../RolloutOpenShiftDeploymentStage.groovy | 76 ++-------------- .../component/TailorDeploymentStrategy.groovy | 45 ++-------- ...sComponentStageRolloutEKSDeployment.groovy | 36 +++----- 11 files changed, 388 insertions(+), 199 deletions(-) create mode 100644 src/org/ods/component/DeploymentConfig.groovy create mode 100644 src/org/ods/component/EKSService.groovy create mode 100644 src/org/ods/component/IImageRepository.groovy create mode 100644 src/org/ods/component/ImageRepositoryEKS.groovy create mode 100644 src/org/ods/component/ImageRepositoryOpenshift.groovy create mode 100644 src/org/ods/component/RolloutEKSDeploymentStage.groovy diff --git a/src/org/ods/component/AbstractDeploymentStrategy.groovy b/src/org/ods/component/AbstractDeploymentStrategy.groovy index 32213c70b0..bcb6cfe936 100644 --- a/src/org/ods/component/AbstractDeploymentStrategy.groovy +++ b/src/org/ods/component/AbstractDeploymentStrategy.groovy @@ -32,23 +32,6 @@ abstract class AbstractDeploymentStrategy implements IDeploymentStrategy { originalVersions } - protected findOrCreateImageStream(String targetProject, String image) { - try { - openShift.findOrCreateImageStream(targetProject, image) - } catch (Exception ex) { - steps.error "Could not find/create ImageStream ${image} in ${targetProject}. Error was: ${ex}" - } - } - - protected void retagImages(String targetProject, Set images) { - images.each { image -> - findOrCreateImageStream(targetProject, image) - openShift.importImageTagFromProject( - targetProject, image, context.cdProject, options.imageTag, options.imageTag - ) - } - } - @TypeChecked(TypeCheckingMode.SKIP) protected Set getBuiltImages() { context.buildArtifactURIs.builds.keySet().findAll { it -> diff --git a/src/org/ods/component/DeploymentConfig.groovy b/src/org/ods/component/DeploymentConfig.groovy new file mode 100644 index 0000000000..6fdbc088fa --- /dev/null +++ b/src/org/ods/component/DeploymentConfig.groovy @@ -0,0 +1,77 @@ + +package org.ods.component + +class DeploymentConfig { + + public static void updateCommonConfig(IContext context, Map config) { + if (!config.selector) { + config.selector = context.selector + } + if (!config.imageTag) { + config.imageTag = context.shortGitCommit + } + if (!config.deployTimeoutMinutes) { + config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 + } + if (!config.deployTimeoutRetries) { + config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 + } + } + + public static void updateHelmConfig(IContext context, Map config){ + if (!config.chartDir) { + config.chartDir = 'chart' + } + if (!config.containsKey('helmReleaseName')) { + config.helmReleaseName = context.componentId + } + if (!config.containsKey('helmValues')) { + config.helmValues = [:] + } + if (!config.containsKey('helmValuesFiles')) { + config.helmValuesFiles = [ 'values.yaml' ] + } + if (!config.containsKey('helmEnvBasedValuesFiles')) { + config.helmEnvBasedValuesFiles = [] + } + if (!config.containsKey('helmDefaultFlags')) { + config.helmDefaultFlags = ['--install', '--atomic'] + } + if (!config.containsKey('helmAdditionalFlags')) { + config.helmAdditionalFlags = [] + } + if (!config.containsKey('helmDiff')) { + config.helmDiff = true + } + if (!config.helmPrivateKeyCredentialsId) { + config.helmPrivateKeyCredentialsId = "${context.cdProject}-helm-private-key" + } + } + + public static void updateTailorConfig(IContext context, Map config) { + if (!config.openshiftDir) { + config.openshiftDir = 'openshift' + } + if (!config.tailorPrivateKeyCredentialsId) { + config.tailorPrivateKeyCredentialsId = "${context.cdProject}-tailor-private-key" + } + if (!config.tailorSelector) { + config.tailorSelector = config.selector + } + if (!config.containsKey('tailorVerify')) { + config.tailorVerify = true + } + if (!config.containsKey('tailorExclude')) { + config.tailorExclude = 'bc,is' + } + if (!config.containsKey('tailorParamFile')) { + config.tailorParamFile = '' // none apart the automatic param file + } + if (!config.containsKey('tailorPreserve')) { + config.tailorPreserve = [] // do not preserve any paths in live config + } + if (!config.containsKey('tailorParams')) { + config.tailorParams = [] + } + } +} \ No newline at end of file diff --git a/src/org/ods/component/EKSService.groovy b/src/org/ods/component/EKSService.groovy new file mode 100644 index 0000000000..b5d6d29895 --- /dev/null +++ b/src/org/ods/component/EKSService.groovy @@ -0,0 +1,87 @@ +package org.ods.component + +class EKSService { + // Constructor arguments + private final IPipelineSteps steps + private final IContext context + private final Map awsEnvironmentVars + private final ILogger logger + + @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity', 'ParameterCount']) + EKSService( + IPipelineSteps steps, + IContext context, + Map awsEnvironmentVars, + ILogger logger + ) { + this.steps = steps + this.context = context + this.awsEnvironmentVars = awsEnvironmentVars + this.logger = logger + } + + + protected String getOCTOken() { + return steps.sh( + script: "oc whoami -t", + returnStdout: true + ).trim() + } + + protected setEKSCluster() { + withCredentials((environmentVars.credentials.key as String).toLowerCase(), + (environmentVars.credentials.secret as String).toLowerCase()) { + executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') + executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') + executeCommand("aws configure set region ${environmentVars.region} --profile default") + executeCommand("aws eks update-kubeconfig --region ${environmentVars.region} --name" + "${context.getProjectId()}-${context.getEnvironment()}") + } + } + + protected String getLoginPassword() { + return steps.sh( + script: "aws ecr get-login-password --region ${environmentVars.region}", + returnStdout: true + ).trim() + } + + protected String getECRRegistry() { + return "${environmentVars.accountId}.dkr.ecr.${environmentVars.region}.amazonaws.com" + } + + protected boolean existRepository(String repositoryName) { + try { + steps.sh( + script: "aws ecr describe-repositories --repository-names ${repositoryName} --region ${environmentVars.region}", + returnStatus: true + ) + return true + } catch (Exception e) { + return false + } + } + + protected void createRepository(String repositoryName) { + executeCommand("aws ecr create-repository --repository-name ${repositoryName} --region ${environmentVars.region}") + } + + private void executeCommand(String command) { + return steps.sh( + script: command, + returnStatus: true, + label: "Executing command: ${command}" + ) as int + if (status != 0) { + script.error("Error executing ${command}, status ${status}") + } + } + + private withCredentials(String awsAccessKeyId, String awsSecretAccessKey, Closure block) { + steps.withCredentials([ + steps.string(credentialsId: awsAccessKeyId, variable: 'AWS_ACCESS_KEY_ID'), + steps.string(credentialsId: awsSecretAccessKey, variable: 'AWS_SECRET_ACCESS_KEY') + ]) { + block(steps.env.AWS_ACCESS_KEY_ID, steps.env.AWS_SECRET_ACCESS_KEY) + } + } +} \ No newline at end of file diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 10e03db6ac..ef58e45576 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -18,6 +18,8 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { private final JenkinsService jenkins private final ILogger logger private final IPipelineSteps steps + private final IImageRepository imageRepository + // assigned in constructor private final RolloutOpenShiftDeploymentOptions options @@ -28,48 +30,12 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { Map config, OpenShiftService openShift, JenkinsService jenkins, + IImageRepository imageRepository, ILogger logger ) { - if (!config.selector) { - config.selector = context.selector - } - if (!config.imageTag) { - config.imageTag = context.shortGitCommit - } - if (!config.deployTimeoutMinutes) { - config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 - } - if (!config.deployTimeoutRetries) { - config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 - } - // Helm options - if (!config.chartDir) { - config.chartDir = 'chart' - } - if (!config.containsKey('helmReleaseName')) { - config.helmReleaseName = context.componentId - } - if (!config.containsKey('helmValues')) { - config.helmValues = [:] - } - if (!config.containsKey('helmValuesFiles')) { - config.helmValuesFiles = ['values.yaml'] - } - if (!config.containsKey('helmEnvBasedValuesFiles')) { - config.helmEnvBasedValuesFiles = [] - } - if (!config.containsKey('helmDefaultFlags')) { - config.helmDefaultFlags = ['--install', '--atomic'] - } - if (!config.containsKey('helmAdditionalFlags')) { - config.helmAdditionalFlags = [] - } - if (!config.containsKey('helmDiff')) { - config.helmDiff = true - } - if (!config.helmPrivateKeyCredentialsId) { - config.helmPrivateKeyCredentialsId = "${context.cdProject}-helm-private-key" - } + DeploymentConfig.updateCommonConfig(context, config) + DeploymentConfig.updateHelmConfig(context, config) + this.context = context this.logger = logger this.steps = steps @@ -77,20 +43,13 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { this.options = new RolloutOpenShiftDeploymentOptions(config) this.openShift = openShift this.jenkins = jenkins + this.imageRepository = imageRepository } @Override - Map> deploy() { - if (!context.environment) { - logger.warn 'Skipping because of empty (target) environment ...' - return [:] - } - - // TODO s2o: import image - // In EKS we don't import images, we use the ECR repository directly. - // This is different from OpenShift, where we import images into the ImageStream. - // Tag images which have been built in this pipeline from cd project into target project - // retagImages(context.targetProject, getBuiltImages()) + Map> deploy() { + logger.info("Retagging images for ${context.targetProject} ") + imageRepository.retagImages(context.targetProject, getBuiltImages()) logger.info("Rolling out ${context.componentId} with HELM, selector: ${options.selector}") helmUpgrade(context.targetProject) diff --git a/src/org/ods/component/IImageRepository.groovy b/src/org/ods/component/IImageRepository.groovy new file mode 100644 index 0000000000..45eefdc29f --- /dev/null +++ b/src/org/ods/component/IImageRepository.groovy @@ -0,0 +1,7 @@ +package org.ods.component + +interface IImageRepository { + + void retagImages(String targetProject, Set images) + +} diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy new file mode 100644 index 0000000000..85b4ae9f60 --- /dev/null +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -0,0 +1,76 @@ +package org.ods.component + +import org.ods.services.EKSService +import org.ods.util.IPipelineSteps + +class ImageRepositoryEKS implements IImageRepository { + + // Constructor arguments + private final IPipelineSteps steps + private final IContext context + private final EKSService eks + + private final String ocToken + private final String awsPassword + + @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity', 'ParameterCount']) + ImageRepositoryEKS( + IPipelineSteps steps, + IContext context, + EKSService eks, + String ocToken, + String awsPassword + ) { + this.steps = steps + this.context = context + this.eks = eks + this.ocToken = ocToken + this.awsPassword = awsPassword + } + + protected void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { + images.each { image -> + findOrCreateRepository(targetProject, image) + copyImageToECR( + targetProject, image, context.cdProject, sourceTag, targetTag + ) + } + } + + private findOrCreateRepository(String targetProject, String image) { + if (!eks.existRepository(image)) { + eks.createRepository(image) + } else { + steps.echo "Repository ${image} already exists in ${targetProject}." + } + } + + void copyImageToECR( + String project, + String name, + String sourceProject, + String sourceTag, + String targetTag) { + + } + + private int copyImage(targetProject, image, context.cdProject, sourceTag, targetTag) { + ocCredentials="jenkins:$ocToken" + awsCredentials="AWS:$awsPassword" + dockerSource="docker://${context.config.dockerRegistry}/${context.cdProject}/${image}:${sourceTag}" + awsTarget="docker://${eks.getECRRegistry()}/${image}:${targetTag}" + + int status = steps.sh( + script: """ + skopeo copy \ + --src-tls-verify=false --src-creds "${ocCredentials}"\ + --dest-tls-verify=false--dest-creds "${awsCredentials}"\ + $dockerSource $awsTarget + """, + returnStatus: true, + label: "Copy image to awsTarget ${awsTarget}" + ) as int + + return status + } +} diff --git a/src/org/ods/component/ImageRepositoryOpenshift.groovy b/src/org/ods/component/ImageRepositoryOpenshift.groovy new file mode 100644 index 0000000000..50f71a10b7 --- /dev/null +++ b/src/org/ods/component/ImageRepositoryOpenshift.groovy @@ -0,0 +1,40 @@ +package org.ods.component + +import org.ods.services.OpenShiftService +import org.ods.util.IPipelineSteps + +class ImageRepositoryOpenshift implements IImageRepository { + + // Constructor arguments + private final IPipelineSteps steps + private final IContext context + private final OpenShiftService openShift + + @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity', 'ParameterCount']) + ImageRepositoryOpenshift( + IPipelineSteps steps, + IContext context, + OpenShiftService openShift + ) { + this.steps = steps + this.context = context + this.openShift = openShift + } + + protected void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { + images.each { image -> + findOrCreateImageStream(targetProject, image) + openShift.importImageTagFromProject( + targetProject, image, context.cdProject, sourceTag, targetTag + ) + } + } + + private findOrCreateImageStream(String targetProject, String image) { + try { + openShift.findOrCreateImageStream(targetProject, image) + } catch (Exception ex) { + steps.error "Could not find/create ImageStream ${image} in ${targetProject}. Error was: ${ex}" + } + } +} diff --git a/src/org/ods/component/RolloutEKSDeploymentStage.groovy b/src/org/ods/component/RolloutEKSDeploymentStage.groovy new file mode 100644 index 0000000000..ea7092a8a4 --- /dev/null +++ b/src/org/ods/component/RolloutEKSDeploymentStage.groovy @@ -0,0 +1,65 @@ +package org.ods.component + +import groovy.transform.TypeChecked +import groovy.transform.TypeCheckingMode +import org.ods.services.JenkinsService +import org.ods.services.OpenShiftService +import org.ods.util.ILogger +import org.ods.util.PipelineSteps +import org.ods.util.IPipelineSteps + +@SuppressWarnings('ParameterCount') +@TypeChecked +class RolloutEKSDeploymentStage extends Stage { + + public final String STAGE_NAME = 'Deploy to OpenShift' + private final OpenShiftService openShift + private final JenkinsService jenkins + private final RolloutOpenShiftDeploymentOptions options + private IDeploymentStrategy deploymentStrategy + private Map config + private Map awsEnvironmentVars + + @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity']) + @TypeChecked(TypeCheckingMode.SKIP) + RolloutEKSDeploymentStage( + def script, + IContext context, + Map config, + OpenShiftService openShift, + JenkinsService jenkins, + Map awsEnvironmentVars, + ILogger logger) { + super(script, context, logger) + + DeploymentConfig.updateCommonConfig(context, config) + DeploymentConfig.updateHelmConfig(context, config) + + this.config = config + this.options = new RolloutOpenShiftDeploymentOptions(config) + this.openShift = openShift + this.jenkins = jenkins + this.awsEnvironmentVars = awsEnvironmentVars + } + + // This is called from Stage#execute if the branch being built is eligible. + protected run() { + EKSService eks = new EKSService(steps, context, awsEnvironmentVars, logger) + String ocToken = eks.getOCTOken() + eks.setEKSCluster() // This should be set after getOCTOken!!! + String awsPassword = eks.getLoginPassword() + imageRepository = new ImageRepositoryEKS(steps, context, eks, ocToken, awsPassword) + deploymentStrategy = new HelmDeploymentStrategy(steps, context, config, openShift, jenkins, imageRepository, logger) + + logger.info("deploymentStrategy: ${deploymentStrategy} -- ${deploymentStrategy.class.name}") + return deploymentStrategy.deploy() + } + + protected String stageLabel() { + if (options.selector != context.selector) { + return "${STAGE_NAME} (${options.selector})" + } + STAGE_NAME + } + +} diff --git a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy index 323a0f0c6b..0d712d407a 100644 --- a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy +++ b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy @@ -30,71 +30,9 @@ class RolloutOpenShiftDeploymentStage extends Stage { ILogger logger) { super(script, context, logger) - if (!config.selector) { - config.selector = context.selector - } - if (!config.imageTag) { - config.imageTag = context.shortGitCommit - } - if (!config.deployTimeoutMinutes) { - config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 - } - if (!config.deployTimeoutRetries) { - config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 - } - // Helm options - if (!config.chartDir) { - config.chartDir = 'chart' - } - if (!config.containsKey('helmReleaseName')) { - config.helmReleaseName = context.componentId - } - if (!config.containsKey('helmValues')) { - config.helmValues = [:] - } - if (!config.containsKey('helmValuesFiles')) { - config.helmValuesFiles = [ 'values.yaml' ] - } - if (!config.containsKey('helmEnvBasedValuesFiles')) { - config.helmEnvBasedValuesFiles = [] - } - if (!config.containsKey('helmDefaultFlags')) { - config.helmDefaultFlags = ['--install', '--atomic'] - } - if (!config.containsKey('helmAdditionalFlags')) { - config.helmAdditionalFlags = [] - } - if (!config.containsKey('helmDiff')) { - config.helmDiff = true - } - if (!config.helmPrivateKeyCredentialsId) { - config.helmPrivateKeyCredentialsId = "${context.cdProject}-helm-private-key" - } - // Tailor options - if (!config.openshiftDir) { - config.openshiftDir = 'openshift' - } - if (!config.tailorPrivateKeyCredentialsId) { - config.tailorPrivateKeyCredentialsId = "${context.cdProject}-tailor-private-key" - } - if (!config.tailorSelector) { - config.tailorSelector = config.selector - } - if (!config.containsKey('tailorVerify')) { - config.tailorVerify = true - } - if (!config.containsKey('tailorExclude')) { - config.tailorExclude = 'bc,is' - } - if (!config.containsKey('tailorParamFile')) { - config.tailorParamFile = '' // none apart the automatic param file - } - if (!config.containsKey('tailorPreserve')) { - config.tailorPreserve = [] // do not preserve any paths in live config - } - if (!config.containsKey('tailorParams')) { - config.tailorParams = [] - } + DeploymentConfig.updateCommonConfig(context, config) + DeploymentConfig.updateHelmConfig(context, config) + DeploymentConfig.updateTailorConfig(config) this.config = config this.options = new RolloutOpenShiftDeploymentOptions(config) @@ -121,18 +59,20 @@ class RolloutOpenShiftDeploymentStage extends Stage { throw new IllegalStateException("Must be either a Tailor based deployment or a Helm based deployment") } + IPipelineSteps steps = new PipelineSteps(script) + IImageRepository imageRepository = new ImageRepositoryOpenShift(steps, context, openShift) + // Use tailorDeployment in the following cases: // (1) We have an openshiftDir // (2) We do not have an openshiftDir but neither do we have an indication that it is Helm - IPipelineSteps steps = new PipelineSteps(script) if (isTailorDeployment || (!isHelmDeployment && !isTailorDeployment)) { - deploymentStrategy = new TailorDeploymentStrategy(steps, context, config, openShift, jenkins, logger) + deploymentStrategy = new TailorDeploymentStrategy(steps, context, config, openShift, jenkins, imageRepository, logger) String resourcePath = 'org/ods/component/RolloutOpenShiftDeploymentStage.deprecate-tailor.GString.txt' def msg = this.steps.libraryResource(resourcePath) logger.warn(msg) } if (isHelmDeployment) { - deploymentStrategy = new HelmDeploymentStrategy(steps, context, config, openShift, jenkins, logger) + deploymentStrategy = new HelmDeploymentStrategy(steps, context, config, openShift, jenkins, imageRepository, logger) } logger.info("deploymentStrategy: ${deploymentStrategy} -- ${deploymentStrategy.class.name}") return deploymentStrategy.deploy() diff --git a/src/org/ods/component/TailorDeploymentStrategy.groovy b/src/org/ods/component/TailorDeploymentStrategy.groovy index cfe1d45e84..bfda0e59a5 100644 --- a/src/org/ods/component/TailorDeploymentStrategy.groovy +++ b/src/org/ods/component/TailorDeploymentStrategy.groovy @@ -19,6 +19,7 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy { // assigned in constructor private final RolloutOpenShiftDeploymentOptions options + private final IImageRepository imageRepository @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity', 'ParameterCount']) TailorDeploymentStrategy( @@ -27,45 +28,12 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy { Map config, OpenShiftService openShift, JenkinsService jenkins, + IImageRepository imageRepository, ILogger logger ) { - if (!config.selector) { - config.selector = context.selector - } - if (!config.imageTag) { - config.imageTag = context.shortGitCommit - } - if (!config.deployTimeoutMinutes) { - config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 - } - if (!config.deployTimeoutRetries) { - config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 - } - // Tailor options - if (!config.openshiftDir) { - config.openshiftDir = 'openshift' - } - if (!config.tailorPrivateKeyCredentialsId) { - config.tailorPrivateKeyCredentialsId = "${context.cdProject}-tailor-private-key" - } - if (!config.tailorSelector) { - config.tailorSelector = config.selector - } - if (!config.containsKey('tailorVerify')) { - config.tailorVerify = true - } - if (!config.containsKey('tailorExclude')) { - config.tailorExclude = 'bc,is' - } - if (!config.containsKey('tailorParamFile')) { - config.tailorParamFile = '' // none apart the automatic param file - } - if (!config.containsKey('tailorPreserve')) { - config.tailorPreserve = [] // do not preserve any paths in live config - } - if (!config.containsKey('tailorParams')) { - config.tailorParams = [] - } + DeploymentConfig.updateCommonConfig(context, config) + DeploymentConfig.updateTailorConfig(context, config) + this.context = context this.logger = logger this.steps = steps @@ -73,6 +41,7 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy { this.options = new RolloutOpenShiftDeploymentOptions(config) this.openShift = openShift this.jenkins = jenkins + this.imageRepository = imageRepository } @Override @@ -96,7 +65,7 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy { def refreshResources = false // Tag images which have been built in this pipeline from cd project into target project - retagImages(context.targetProject, getBuiltImages()) + imageRepository.retagImages(context.targetProject, getBuiltImages()) if (steps.fileExists(options.openshiftDir)) { refreshResources = true diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy index eb81387298..9b24719cbb 100644 --- a/vars/odsComponentStageRolloutEKSDeployment.groovy +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -1,4 +1,4 @@ -import org.ods.component.RolloutOpenShiftDeploymentStage +import org.ods.component.RolloutEKSDeploymentStage import org.ods.component.IContext import org.ods.component.EKSLoginStage @@ -14,37 +14,23 @@ def call(IContext context, Map config = [:]) { if (!logger) { logger = new Logger (this, !!env.DEBUG) } - - // This step should be executed before the EKSLoginStage, so that the OpenShift token is available - // as later we need the token to copy the images - def currentOCToken = sh(script: "oc whoami -t >& /dev/null", label: "Get OpenShift Token", returnStdout: true) - - def stageLogin = new EKSLoginStage( - this, - context, - config, - logger - ) - this.withCredentials([ - this.string(credentialsId: "${context.cdProject}-aws-region", variable: 'AWS_REGION'), - this.string(credentialsId: "${context.cdProject}-aws-account-id", variable: 'AWS_ACCOUNT_ID'), - this.string(credentialsId: "${context.cdProject}-aws-access-key-id-dev", variable: 'AWS_ACCESS_KEY_ID'), - this.string(credentialsId: "${context.cdProject}-aws-secret-access-key-dev", variable: 'AWS_SECRET_ACCESS_KEY') - ]) { - stageLogin.execute() + if (!context.environment) { + logger.warn 'Skipping because of empty (target) environment ...' + return + } + if (!config.envPath) { + config.envPath = "./environments" } - // TODO: - // sent currentOCToken to RolloutOpenShiftDeploymentStage - // and copy the images from OpenShift to EKS - // change retagImages for something compatible with EKS - return new RolloutOpenShiftDeploymentStage( + Map awsEnvironmentVars = readYaml(file: "${config.envPath}/${context.environment}.yml") + return new RolloutEKSDeploymentStage( this, context, config, ServiceRegistry.instance.get(OpenShiftService), ServiceRegistry.instance.get(JenkinsService), + awsEnvironmentVars, logger - ).execute() + ).execute() } return this From 693f2ea5d035ea03aa80ef8a43f761664f5bc2c6 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 15:57:58 +0200 Subject: [PATCH 10/38] ImageRepositoryEKS --- src/org/ods/component/EKSLoginStage.groovy | 44 ------------------- .../ods/component/ImageRepositoryEKS.groovy | 15 +------ 2 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 src/org/ods/component/EKSLoginStage.groovy diff --git a/src/org/ods/component/EKSLoginStage.groovy b/src/org/ods/component/EKSLoginStage.groovy deleted file mode 100644 index 5dfcde934a..0000000000 --- a/src/org/ods/component/EKSLoginStage.groovy +++ /dev/null @@ -1,44 +0,0 @@ -package org.ods.component - -import groovy.transform.TypeChecked -import groovy.transform.TypeCheckingMode -import org.ods.util.ILogger - -@SuppressWarnings('ParameterCount') -@TypeChecked -class EKSLoginStage extends Stage { - - public final String STAGE_NAME = 'EKS Login' - private final RolloutOpenShiftDeploymentOptions options - - @TypeChecked(TypeCheckingMode.SKIP) - EKSLoginStage( - def script, - IContext context, - Map config, - ILogger logger) { - super(script, context, logger) - this.options = new RolloutOpenShiftDeploymentOptions(config) - } - - // This is called from Stage#execute - @SuppressWarnings(['AbcMetric']) - @TypeChecked(TypeCheckingMode.SKIP) - protected run() { - executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') - executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') - executeCommand('aws configure set region $AWS_REGION --profile default') - executeCommand('aws eks update-kubeconfig --region $AWS_REGION --name' + "${context.getProjectId()}-${context.getEnvironment()}") - } - - private void executeCommand(String command) { - return steps.sh( - script: command, - returnStatus: true, - label: "Executing command: ${command}" - ) as int - if (status != 0) { - script.error("Could not Login to -region $AWS_REGION --name $EKS_CLUSTER_NAME, status ${status}") - } - } -} diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 85b4ae9f60..30e002fab3 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -31,9 +31,7 @@ class ImageRepositoryEKS implements IImageRepository { protected void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { images.each { image -> findOrCreateRepository(targetProject, image) - copyImageToECR( - targetProject, image, context.cdProject, sourceTag, targetTag - ) + copyImage(image, context, sourceTag, targetTag) } } @@ -45,16 +43,7 @@ class ImageRepositoryEKS implements IImageRepository { } } - void copyImageToECR( - String project, - String name, - String sourceProject, - String sourceTag, - String targetTag) { - - } - - private int copyImage(targetProject, image, context.cdProject, sourceTag, targetTag) { + private int copyImage(image, context, sourceTag, targetTag) { ocCredentials="jenkins:$ocToken" awsCredentials="AWS:$awsPassword" dockerSource="docker://${context.config.dockerRegistry}/${context.cdProject}/${image}:${sourceTag}" From f3b3745c9f62fd1e08c22e8c139763a65619d164 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:01:26 +0200 Subject: [PATCH 11/38] EKSLoginStage --- vars/odsComponentStageRolloutEKSDeployment.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/vars/odsComponentStageRolloutEKSDeployment.groovy b/vars/odsComponentStageRolloutEKSDeployment.groovy index 9b24719cbb..738da78242 100644 --- a/vars/odsComponentStageRolloutEKSDeployment.groovy +++ b/vars/odsComponentStageRolloutEKSDeployment.groovy @@ -1,6 +1,5 @@ import org.ods.component.RolloutEKSDeploymentStage import org.ods.component.IContext -import org.ods.component.EKSLoginStage import org.ods.services.OpenShiftService import org.ods.services.JenkinsService From ba3f33897a815238c713c575ebc4a673915cd9e6 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:24:36 +0200 Subject: [PATCH 12/38] EKSService --- src/org/ods/component/EKSService.groovy | 4 ++++ src/org/ods/component/ImageRepositoryEKS.groovy | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/org/ods/component/EKSService.groovy b/src/org/ods/component/EKSService.groovy index b5d6d29895..31bf6822c2 100644 --- a/src/org/ods/component/EKSService.groovy +++ b/src/org/ods/component/EKSService.groovy @@ -1,5 +1,9 @@ package org.ods.component +import org.ods.util.IPipelineSteps +import org.ods.component.IContext +import org.ods.util.ILogger + class EKSService { // Constructor arguments private final IPipelineSteps steps diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 30e002fab3..61a2a829f4 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -2,6 +2,7 @@ package org.ods.component import org.ods.services.EKSService import org.ods.util.IPipelineSteps +import org.ods.component.IContext class ImageRepositoryEKS implements IImageRepository { @@ -49,7 +50,7 @@ class ImageRepositoryEKS implements IImageRepository { dockerSource="docker://${context.config.dockerRegistry}/${context.cdProject}/${image}:${sourceTag}" awsTarget="docker://${eks.getECRRegistry()}/${image}:${targetTag}" - int status = steps.sh( + return = steps.sh( script: """ skopeo copy \ --src-tls-verify=false --src-creds "${ocCredentials}"\ @@ -59,7 +60,5 @@ class ImageRepositoryEKS implements IImageRepository { returnStatus: true, label: "Copy image to awsTarget ${awsTarget}" ) as int - - return status } } From 7a71a93e4888d2b8a43da7a9f856b40e9eca4481 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:29:02 +0200 Subject: [PATCH 13/38] copyImage --- src/org/ods/component/ImageRepositoryEKS.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 61a2a829f4..3892b9b6e4 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -50,7 +50,7 @@ class ImageRepositoryEKS implements IImageRepository { dockerSource="docker://${context.config.dockerRegistry}/${context.cdProject}/${image}:${sourceTag}" awsTarget="docker://${eks.getECRRegistry()}/${image}:${targetTag}" - return = steps.sh( + return steps.sh( script: """ skopeo copy \ --src-tls-verify=false --src-creds "${ocCredentials}"\ From 65df22904bde8f9f131acbf765fc430e94114b69 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:34:34 +0200 Subject: [PATCH 14/38] org.ods.services.EKSService --- src/org/ods/component/RolloutEKSDeploymentStage.groovy | 1 + src/org/ods/{component => services}/EKSService.groovy | 0 2 files changed, 1 insertion(+) rename src/org/ods/{component => services}/EKSService.groovy (100%) diff --git a/src/org/ods/component/RolloutEKSDeploymentStage.groovy b/src/org/ods/component/RolloutEKSDeploymentStage.groovy index ea7092a8a4..1fb58dd573 100644 --- a/src/org/ods/component/RolloutEKSDeploymentStage.groovy +++ b/src/org/ods/component/RolloutEKSDeploymentStage.groovy @@ -7,6 +7,7 @@ import org.ods.services.OpenShiftService import org.ods.util.ILogger import org.ods.util.PipelineSteps import org.ods.util.IPipelineSteps +import org.ods.services.EKSService @SuppressWarnings('ParameterCount') @TypeChecked diff --git a/src/org/ods/component/EKSService.groovy b/src/org/ods/services/EKSService.groovy similarity index 100% rename from src/org/ods/component/EKSService.groovy rename to src/org/ods/services/EKSService.groovy From bd8aeb75c9f021c45e0e3fb25f497420c3a6e694 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:38:57 +0200 Subject: [PATCH 15/38] services --- src/org/ods/services/EKSService.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index 31bf6822c2..fdda9d2492 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -1,4 +1,4 @@ -package org.ods.component +package org.ods.services import org.ods.util.IPipelineSteps import org.ods.component.IContext From 57703af709d4f6d9a23787612779d05b1cec9bff Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:46:53 +0200 Subject: [PATCH 16/38] retagImages --- src/org/ods/component/HelmDeploymentStrategy.groovy | 2 +- src/org/ods/component/IImageRepository.groovy | 2 +- src/org/ods/component/TailorDeploymentStrategy.groovy | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index ef58e45576..8daa64e8f0 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -49,7 +49,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { @Override Map> deploy() { logger.info("Retagging images for ${context.targetProject} ") - imageRepository.retagImages(context.targetProject, getBuiltImages()) + imageRepository.retagImages(context.targetProject, getBuiltImages(), options.imageTag, options.imageTag) logger.info("Rolling out ${context.componentId} with HELM, selector: ${options.selector}") helmUpgrade(context.targetProject) diff --git a/src/org/ods/component/IImageRepository.groovy b/src/org/ods/component/IImageRepository.groovy index 45eefdc29f..a9992c9b4d 100644 --- a/src/org/ods/component/IImageRepository.groovy +++ b/src/org/ods/component/IImageRepository.groovy @@ -2,6 +2,6 @@ package org.ods.component interface IImageRepository { - void retagImages(String targetProject, Set images) + void retagImages(String targetProject, Set images, String sourceTag, String targetTag) } diff --git a/src/org/ods/component/TailorDeploymentStrategy.groovy b/src/org/ods/component/TailorDeploymentStrategy.groovy index bfda0e59a5..949af563e8 100644 --- a/src/org/ods/component/TailorDeploymentStrategy.groovy +++ b/src/org/ods/component/TailorDeploymentStrategy.groovy @@ -65,7 +65,7 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy { def refreshResources = false // Tag images which have been built in this pipeline from cd project into target project - imageRepository.retagImages(context.targetProject, getBuiltImages()) + imageRepository.retagImages(context.targetProject, getBuiltImages(), options.imageTag, options.imageTag) if (steps.fileExists(options.openshiftDir)) { refreshResources = true From 1dbcf05aa0d477e2f9693caa2a533eee249c7be5 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:48:58 +0200 Subject: [PATCH 17/38] public --- src/org/ods/component/ImageRepositoryEKS.groovy | 2 +- src/org/ods/component/ImageRepositoryOpenshift.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 3892b9b6e4..247eb1d981 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -29,7 +29,7 @@ class ImageRepositoryEKS implements IImageRepository { this.awsPassword = awsPassword } - protected void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { + public void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { images.each { image -> findOrCreateRepository(targetProject, image) copyImage(image, context, sourceTag, targetTag) diff --git a/src/org/ods/component/ImageRepositoryOpenshift.groovy b/src/org/ods/component/ImageRepositoryOpenshift.groovy index 50f71a10b7..bc63fedf27 100644 --- a/src/org/ods/component/ImageRepositoryOpenshift.groovy +++ b/src/org/ods/component/ImageRepositoryOpenshift.groovy @@ -21,7 +21,7 @@ class ImageRepositoryOpenshift implements IImageRepository { this.openShift = openShift } - protected void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { + public void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { images.each { image -> findOrCreateImageStream(targetProject, image) openShift.importImageTagFromProject( From 6fbad4bf24149c574f219f7a029ddb98f8ba89ca Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 16:55:03 +0200 Subject: [PATCH 18/38] NonCPS --- src/org/ods/component/DeploymentConfig.groovy | 5 +++++ src/org/ods/component/RolloutEKSDeploymentStage.groovy | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/org/ods/component/DeploymentConfig.groovy b/src/org/ods/component/DeploymentConfig.groovy index 6fdbc088fa..47ab271678 100644 --- a/src/org/ods/component/DeploymentConfig.groovy +++ b/src/org/ods/component/DeploymentConfig.groovy @@ -1,8 +1,11 @@ package org.ods.component +import com.cloudbees.groovy.cps.NonCPS + class DeploymentConfig { + @NonCPS public static void updateCommonConfig(IContext context, Map config) { if (!config.selector) { config.selector = context.selector @@ -18,6 +21,7 @@ class DeploymentConfig { } } + @NonCPS public static void updateHelmConfig(IContext context, Map config){ if (!config.chartDir) { config.chartDir = 'chart' @@ -48,6 +52,7 @@ class DeploymentConfig { } } + @NonCPS public static void updateTailorConfig(IContext context, Map config) { if (!config.openshiftDir) { config.openshiftDir = 'openshift' diff --git a/src/org/ods/component/RolloutEKSDeploymentStage.groovy b/src/org/ods/component/RolloutEKSDeploymentStage.groovy index 1fb58dd573..710458e943 100644 --- a/src/org/ods/component/RolloutEKSDeploymentStage.groovy +++ b/src/org/ods/component/RolloutEKSDeploymentStage.groovy @@ -8,6 +8,7 @@ import org.ods.util.ILogger import org.ods.util.PipelineSteps import org.ods.util.IPipelineSteps import org.ods.services.EKSService +import com.cloudbees.groovy.cps.NonCPS @SuppressWarnings('ParameterCount') @TypeChecked @@ -21,6 +22,7 @@ class RolloutEKSDeploymentStage extends Stage { private Map config private Map awsEnvironmentVars + @NonCPS @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity']) @TypeChecked(TypeCheckingMode.SKIP) RolloutEKSDeploymentStage( From ddd5a17146f26446ee7cd2ce6da09689f9e8e1cb Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:02:50 +0200 Subject: [PATCH 19/38] DeploymentConfig --- src/org/ods/component/DeploymentConfig.groovy | 8 ++------ src/org/ods/component/HelmDeploymentStrategy.groovy | 5 +++-- src/org/ods/component/RolloutEKSDeploymentStage.groovy | 7 +++---- .../ods/component/RolloutOpenShiftDeploymentStage.groovy | 9 +++++---- src/org/ods/component/TailorDeploymentStrategy.groovy | 7 ++++--- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/org/ods/component/DeploymentConfig.groovy b/src/org/ods/component/DeploymentConfig.groovy index 47ab271678..feb847d6ab 100644 --- a/src/org/ods/component/DeploymentConfig.groovy +++ b/src/org/ods/component/DeploymentConfig.groovy @@ -1,12 +1,9 @@ package org.ods.component -import com.cloudbees.groovy.cps.NonCPS - class DeploymentConfig { - @NonCPS - public static void updateCommonConfig(IContext context, Map config) { + public void updateCommonConfig(IContext context, Map config) { if (!config.selector) { config.selector = context.selector } @@ -21,8 +18,7 @@ class DeploymentConfig { } } - @NonCPS - public static void updateHelmConfig(IContext context, Map config){ + public void updateHelmConfig(IContext context, Map config){ if (!config.chartDir) { config.chartDir = 'chart' } diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 8daa64e8f0..454014f0f5 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -33,8 +33,9 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { IImageRepository imageRepository, ILogger logger ) { - DeploymentConfig.updateCommonConfig(context, config) - DeploymentConfig.updateHelmConfig(context, config) + DeploymentConfig deploymentConfig = new DeploymentConfig() + deploymentConfig.updateCommonConfig(context, config) + deploymentConfig.updateHelmConfig(context, config) this.context = context this.logger = logger diff --git a/src/org/ods/component/RolloutEKSDeploymentStage.groovy b/src/org/ods/component/RolloutEKSDeploymentStage.groovy index 710458e943..63f2e8c461 100644 --- a/src/org/ods/component/RolloutEKSDeploymentStage.groovy +++ b/src/org/ods/component/RolloutEKSDeploymentStage.groovy @@ -22,7 +22,6 @@ class RolloutEKSDeploymentStage extends Stage { private Map config private Map awsEnvironmentVars - @NonCPS @SuppressWarnings(['AbcMetric', 'CyclomaticComplexity']) @TypeChecked(TypeCheckingMode.SKIP) RolloutEKSDeploymentStage( @@ -34,9 +33,9 @@ class RolloutEKSDeploymentStage extends Stage { Map awsEnvironmentVars, ILogger logger) { super(script, context, logger) - - DeploymentConfig.updateCommonConfig(context, config) - DeploymentConfig.updateHelmConfig(context, config) + DeploymentConfig deploymentConfig = new DeploymentConfig() + deploymentConfig.updateCommonConfig(context, config) + deploymentConfig.updateHelmConfig(context, config) this.config = config this.options = new RolloutOpenShiftDeploymentOptions(config) diff --git a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy index 0d712d407a..c992d8527c 100644 --- a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy +++ b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy @@ -29,10 +29,11 @@ class RolloutOpenShiftDeploymentStage extends Stage { JenkinsService jenkins, ILogger logger) { super(script, context, logger) - - DeploymentConfig.updateCommonConfig(context, config) - DeploymentConfig.updateHelmConfig(context, config) - DeploymentConfig.updateTailorConfig(config) + + DeploymentConfig deploymentConfig = new DeploymentConfig() + deploymentConfig.updateCommonConfig(context, config) + deploymentConfig.updateHelmConfig(context, config) + deploymentConfig.updateTailorConfig(config) this.config = config this.options = new RolloutOpenShiftDeploymentOptions(config) diff --git a/src/org/ods/component/TailorDeploymentStrategy.groovy b/src/org/ods/component/TailorDeploymentStrategy.groovy index 949af563e8..42c4f432f5 100644 --- a/src/org/ods/component/TailorDeploymentStrategy.groovy +++ b/src/org/ods/component/TailorDeploymentStrategy.groovy @@ -31,9 +31,10 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy { IImageRepository imageRepository, ILogger logger ) { - DeploymentConfig.updateCommonConfig(context, config) - DeploymentConfig.updateTailorConfig(context, config) - + DeploymentConfig deploymentConfig = new DeploymentConfig() + deploymentConfig.updateCommonConfig(context, config) + deploymentConfig.updateTailorConfig(context, config) + this.context = context this.logger = logger this.steps = steps From bbe904d3a30786d1454c378dd16e6cd3ed992ede Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:07:22 +0200 Subject: [PATCH 20/38] deploymentConfig --- .../RolloutEKSDeploymentStage.groovy | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/org/ods/component/RolloutEKSDeploymentStage.groovy b/src/org/ods/component/RolloutEKSDeploymentStage.groovy index 63f2e8c461..7ab4c5c409 100644 --- a/src/org/ods/component/RolloutEKSDeploymentStage.groovy +++ b/src/org/ods/component/RolloutEKSDeploymentStage.groovy @@ -33,10 +33,50 @@ class RolloutEKSDeploymentStage extends Stage { Map awsEnvironmentVars, ILogger logger) { super(script, context, logger) - DeploymentConfig deploymentConfig = new DeploymentConfig() - deploymentConfig.updateCommonConfig(context, config) - deploymentConfig.updateHelmConfig(context, config) - + + // TODO + // DeploymentConfig deploymentConfig = new DeploymentConfig() + // deploymentConfig.updateCommonConfig(context, config) + // deploymentConfig.updateHelmConfig(context, config) + if (!config.selector) { + config.selector = context.selector + } + if (!config.imageTag) { + config.imageTag = context.shortGitCommit + } + if (!config.deployTimeoutMinutes) { + config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 + } + if (!config.deployTimeoutRetries) { + config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 + } + if (!config.chartDir) { + config.chartDir = 'chart' + } + if (!config.containsKey('helmReleaseName')) { + config.helmReleaseName = context.componentId + } + if (!config.containsKey('helmValues')) { + config.helmValues = [:] + } + if (!config.containsKey('helmValuesFiles')) { + config.helmValuesFiles = [ 'values.yaml' ] + } + if (!config.containsKey('helmEnvBasedValuesFiles')) { + config.helmEnvBasedValuesFiles = [] + } + if (!config.containsKey('helmDefaultFlags')) { + config.helmDefaultFlags = ['--install', '--atomic'] + } + if (!config.containsKey('helmAdditionalFlags')) { + config.helmAdditionalFlags = [] + } + if (!config.containsKey('helmDiff')) { + config.helmDiff = true + } + if (!config.helmPrivateKeyCredentialsId) { + config.helmPrivateKeyCredentialsId = "${context.cdProject}-helm-private-key" + } this.config = config this.options = new RolloutOpenShiftDeploymentOptions(config) this.openShift = openShift From f5cc7788c2f294182dfb329fe8afac686e7d38d3 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:09:55 +0200 Subject: [PATCH 21/38] DeploymentConfig --- .../component/HelmDeploymentStrategy.groovy | 48 +++++++++++-- .../RolloutOpenShiftDeploymentStage.groovy | 71 +++++++++++++++++-- 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 454014f0f5..6ded86d301 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -33,10 +33,50 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { IImageRepository imageRepository, ILogger logger ) { - DeploymentConfig deploymentConfig = new DeploymentConfig() - deploymentConfig.updateCommonConfig(context, config) - deploymentConfig.updateHelmConfig(context, config) - + // TODO + // DeploymentConfig deploymentConfig = new DeploymentConfig() + // deploymentConfig.updateCommonConfig(context, config) + // deploymentConfig.updateHelmConfig(context, config) + if (!config.selector) { + config.selector = context.selector + } + if (!config.imageTag) { + config.imageTag = context.shortGitCommit + } + if (!config.deployTimeoutMinutes) { + config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 + } + if (!config.deployTimeoutRetries) { + config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 + } + if (!config.chartDir) { + config.chartDir = 'chart' + } + if (!config.containsKey('helmReleaseName')) { + config.helmReleaseName = context.componentId + } + if (!config.containsKey('helmValues')) { + config.helmValues = [:] + } + if (!config.containsKey('helmValuesFiles')) { + config.helmValuesFiles = [ 'values.yaml' ] + } + if (!config.containsKey('helmEnvBasedValuesFiles')) { + config.helmEnvBasedValuesFiles = [] + } + if (!config.containsKey('helmDefaultFlags')) { + config.helmDefaultFlags = ['--install', '--atomic'] + } + if (!config.containsKey('helmAdditionalFlags')) { + config.helmAdditionalFlags = [] + } + if (!config.containsKey('helmDiff')) { + config.helmDiff = true + } + if (!config.helmPrivateKeyCredentialsId) { + config.helmPrivateKeyCredentialsId = "${context.cdProject}-helm-private-key" + } + this.context = context this.logger = logger this.steps = steps diff --git a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy index c992d8527c..e428be27ee 100644 --- a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy +++ b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy @@ -30,10 +30,73 @@ class RolloutOpenShiftDeploymentStage extends Stage { ILogger logger) { super(script, context, logger) - DeploymentConfig deploymentConfig = new DeploymentConfig() - deploymentConfig.updateCommonConfig(context, config) - deploymentConfig.updateHelmConfig(context, config) - deploymentConfig.updateTailorConfig(config) + // TODO + // DeploymentConfig deploymentConfig = new DeploymentConfig() + // deploymentConfig.updateCommonConfig(context, config) + // deploymentConfig.updateHelmConfig(context, config) + if (!config.selector) { + config.selector = context.selector + } + if (!config.imageTag) { + config.imageTag = context.shortGitCommit + } + if (!config.deployTimeoutMinutes) { + config.deployTimeoutMinutes = context.openshiftRolloutTimeout ?: 15 + } + if (!config.deployTimeoutRetries) { + config.deployTimeoutRetries = context.openshiftRolloutTimeoutRetries ?: 5 + } + if (!config.chartDir) { + config.chartDir = 'chart' + } + if (!config.containsKey('helmReleaseName')) { + config.helmReleaseName = context.componentId + } + if (!config.containsKey('helmValues')) { + config.helmValues = [:] + } + if (!config.containsKey('helmValuesFiles')) { + config.helmValuesFiles = [ 'values.yaml' ] + } + if (!config.containsKey('helmEnvBasedValuesFiles')) { + config.helmEnvBasedValuesFiles = [] + } + if (!config.containsKey('helmDefaultFlags')) { + config.helmDefaultFlags = ['--install', '--atomic'] + } + if (!config.containsKey('helmAdditionalFlags')) { + config.helmAdditionalFlags = [] + } + if (!config.containsKey('helmDiff')) { + config.helmDiff = true + } + if (!config.helmPrivateKeyCredentialsId) { + config.helmPrivateKeyCredentialsId = "${context.cdProject}-helm-private-key" + } + if (!config.openshiftDir) { + config.openshiftDir = 'openshift' + } + if (!config.tailorPrivateKeyCredentialsId) { + config.tailorPrivateKeyCredentialsId = "${context.cdProject}-tailor-private-key" + } + if (!config.tailorSelector) { + config.tailorSelector = config.selector + } + if (!config.containsKey('tailorVerify')) { + config.tailorVerify = true + } + if (!config.containsKey('tailorExclude')) { + config.tailorExclude = 'bc,is' + } + if (!config.containsKey('tailorParamFile')) { + config.tailorParamFile = '' // none apart the automatic param file + } + if (!config.containsKey('tailorPreserve')) { + config.tailorPreserve = [] // do not preserve any paths in live config + } + if (!config.containsKey('tailorParams')) { + config.tailorParams = [] + } this.config = config this.options = new RolloutOpenShiftDeploymentOptions(config) From 49dad0c226c3c185855110b358e696f9448f78c6 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:12:46 +0200 Subject: [PATCH 22/38] envPath --- src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy b/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy index 3fe467406b..22e69ec361 100644 --- a/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy +++ b/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy @@ -5,6 +5,8 @@ import groovy.transform.TypeChecked @TypeChecked class RolloutOpenShiftDeploymentOptions extends Options { + String envPath + /** * Selector scope used to determine which resources are part of a component * (defaults to `context.selector`). */ From ef89a36ff64fc499e6e4f0c8387bca4782d4ddbe Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:17:05 +0200 Subject: [PATCH 23/38] awsEnvironmentVars --- src/org/ods/services/EKSService.groovy | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index fdda9d2492..dc1eb77121 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -33,30 +33,30 @@ class EKSService { } protected setEKSCluster() { - withCredentials((environmentVars.credentials.key as String).toLowerCase(), - (environmentVars.credentials.secret as String).toLowerCase()) { + withCredentials((awsEnvironmentVars.credentials.key as String).toLowerCase(), + (awsEnvironmentVars.credentials.secret as String).toLowerCase()) { executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') - executeCommand("aws configure set region ${environmentVars.region} --profile default") - executeCommand("aws eks update-kubeconfig --region ${environmentVars.region} --name" + "${context.getProjectId()}-${context.getEnvironment()}") + executeCommand("aws configure set region ${awsEnvironmentVars.region} --profile default") + executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name" + "${context.getProjectId()}-${context.getEnvironment()}") } } protected String getLoginPassword() { return steps.sh( - script: "aws ecr get-login-password --region ${environmentVars.region}", + script: "aws ecr get-login-password --region ${awsEnvironmentVars.region}", returnStdout: true ).trim() } protected String getECRRegistry() { - return "${environmentVars.accountId}.dkr.ecr.${environmentVars.region}.amazonaws.com" - } + return "${awsEnvironmentVars.accountId}.dkr.ecr.${awsEnvironmentVars.region}.amazonaws.com" + } protected boolean existRepository(String repositoryName) { try { steps.sh( - script: "aws ecr describe-repositories --repository-names ${repositoryName} --region ${environmentVars.region}", + script: "aws ecr describe-repositories --repository-names ${repositoryName} --region ${awsEnvironmentVars.region}", returnStatus: true ) return true @@ -66,7 +66,7 @@ class EKSService { } protected void createRepository(String repositoryName) { - executeCommand("aws ecr create-repository --repository-name ${repositoryName} --region ${environmentVars.region}") + executeCommand("aws ecr create-repository --repository-name ${repositoryName} --region ${awsEnvironmentVars.region}") } private void executeCommand(String command) { From 1e211d5a0b2f73fb350bfaf218153a76dcaf1ac2 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:19:47 +0200 Subject: [PATCH 24/38] ImageRepositoryEKS --- src/org/ods/component/RolloutEKSDeploymentStage.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/component/RolloutEKSDeploymentStage.groovy b/src/org/ods/component/RolloutEKSDeploymentStage.groovy index 7ab4c5c409..48184907de 100644 --- a/src/org/ods/component/RolloutEKSDeploymentStage.groovy +++ b/src/org/ods/component/RolloutEKSDeploymentStage.groovy @@ -90,7 +90,7 @@ class RolloutEKSDeploymentStage extends Stage { String ocToken = eks.getOCTOken() eks.setEKSCluster() // This should be set after getOCTOken!!! String awsPassword = eks.getLoginPassword() - imageRepository = new ImageRepositoryEKS(steps, context, eks, ocToken, awsPassword) + ImageRepositoryEKS imageRepository = new ImageRepositoryEKS(steps, context, eks, ocToken, awsPassword) deploymentStrategy = new HelmDeploymentStrategy(steps, context, config, openShift, jenkins, imageRepository, logger) logger.info("deploymentStrategy: ${deploymentStrategy} -- ${deploymentStrategy.class.name}") From b726eac91420c91e71fd5a3f79f5788a0e801873 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:22:22 +0200 Subject: [PATCH 25/38] copyImage --- src/org/ods/component/ImageRepositoryEKS.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 247eb1d981..79ad2f03c0 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -45,10 +45,10 @@ class ImageRepositoryEKS implements IImageRepository { } private int copyImage(image, context, sourceTag, targetTag) { - ocCredentials="jenkins:$ocToken" - awsCredentials="AWS:$awsPassword" - dockerSource="docker://${context.config.dockerRegistry}/${context.cdProject}/${image}:${sourceTag}" - awsTarget="docker://${eks.getECRRegistry()}/${image}:${targetTag}" + String ocCredentials="jenkins:$ocToken" + String awsCredentials="AWS:$awsPassword" + String dockerSource="docker://${context.config.dockerRegistry}/${context.cdProject}/${image}:${sourceTag}" + String awsTarget="docker://${eks.getECRRegistry()}/${image}:${targetTag}" return steps.sh( script: """ From 6c17c472ab16d6a614080a93b48adfdb371268b2 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:25:03 +0200 Subject: [PATCH 26/38] skopeo copy --- src/org/ods/component/ImageRepositoryEKS.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 79ad2f03c0..c6f8209c2b 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -54,7 +54,7 @@ class ImageRepositoryEKS implements IImageRepository { script: """ skopeo copy \ --src-tls-verify=false --src-creds "${ocCredentials}"\ - --dest-tls-verify=false--dest-creds "${awsCredentials}"\ + --dest-tls-verify=false --dest-creds "${awsCredentials}"\ $dockerSource $awsTarget """, returnStatus: true, From 82e0e61f832070b08c1514c06e970195a0ac8ef1 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 4 Aug 2025 17:30:31 +0200 Subject: [PATCH 27/38] account --- src/org/ods/services/EKSService.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index dc1eb77121..ee6c57d594 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -50,7 +50,7 @@ class EKSService { } protected String getECRRegistry() { - return "${awsEnvironmentVars.accountId}.dkr.ecr.${awsEnvironmentVars.region}.amazonaws.com" + return "${awsEnvironmentVars.account}.dkr.ecr.${awsEnvironmentVars.region}.amazonaws.com" } protected boolean existRepository(String repositoryName) { From b7587ee04b8a537745659989749e95158afe7948 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 28 Aug 2025 15:58:45 +0200 Subject: [PATCH 28/38] aws eks update-kubeconfig --- src/org/ods/services/EKSService.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index ee6c57d594..1bc6977ffe 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -38,7 +38,7 @@ class EKSService { executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') executeCommand("aws configure set region ${awsEnvironmentVars.region} --profile default") - executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name" + "${context.getProjectId()}-${context.getEnvironment()}") + executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name " + "${context.getProjectId()}-${context.getEnvironment()}") } } From 65a4a0e1e07aa45cfe8768c92a3770268d6c9062 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 28 Aug 2025 17:57:38 +0200 Subject: [PATCH 29/38] gaia-newdev --- src/org/ods/services/EKSService.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index 1bc6977ffe..22cd3ff7ed 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -38,7 +38,8 @@ class EKSService { executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') executeCommand("aws configure set region ${awsEnvironmentVars.region} --profile default") - executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name " + "${context.getProjectId()}-${context.getEnvironment()}") + executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name gaia-newdev") +// executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name gaia-newdev" + "${context.getProjectId()}-${context.getEnvironment()}") } } From 0d14312982cebc394e5f23bbc724eb564cca9265 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 28 Aug 2025 19:14:59 +0200 Subject: [PATCH 30/38] show eks --- src/org/ods/services/EKSService.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index 22cd3ff7ed..c48f17e151 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -38,6 +38,7 @@ class EKSService { executeCommand('aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default') executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') executeCommand("aws configure set region ${awsEnvironmentVars.region} --profile default") + executeCommand("aws eks list-clusters") executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name gaia-newdev") // executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name gaia-newdev" + "${context.getProjectId()}-${context.getEnvironment()}") } From ed3093d1202e71e9106444a5065aff6564bf8355 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Thu, 28 Aug 2025 19:28:00 +0200 Subject: [PATCH 31/38] retagImages --- src/org/ods/component/ImageRepositoryEKS.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index c6f8209c2b..32b53bd22f 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -30,6 +30,7 @@ class ImageRepositoryEKS implements IImageRepository { } public void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { + steps.echo "retagImages ${images.size()} images." images.each { image -> findOrCreateRepository(targetProject, image) copyImage(image, context, sourceTag, targetTag) From 815c165a3e9652e47281cb77a308ea39edbaab36 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Fri, 29 Aug 2025 12:36:03 +0200 Subject: [PATCH 32/38] createRepository and namespace --- .../ods/component/ImageRepositoryEKS.groovy | 10 +------- src/org/ods/services/EKSService.groovy | 24 +++++-------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index 32b53bd22f..b2bf8f2a51 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -32,19 +32,11 @@ class ImageRepositoryEKS implements IImageRepository { public void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { steps.echo "retagImages ${images.size()} images." images.each { image -> - findOrCreateRepository(targetProject, image) + eks.createRepository(image) copyImage(image, context, sourceTag, targetTag) } } - private findOrCreateRepository(String targetProject, String image) { - if (!eks.existRepository(image)) { - eks.createRepository(image) - } else { - steps.echo "Repository ${image} already exists in ${targetProject}." - } - } - private int copyImage(image, context, sourceTag, targetTag) { String ocCredentials="jenkins:$ocToken" String awsCredentials="AWS:$awsPassword" diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index c48f17e151..88192dcb83 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -39,8 +39,8 @@ class EKSService { executeCommand('aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default') executeCommand("aws configure set region ${awsEnvironmentVars.region} --profile default") executeCommand("aws eks list-clusters") - executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name gaia-newdev") -// executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name gaia-newdev" + "${context.getProjectId()}-${context.getEnvironment()}") + executeCommand("aws eks update-kubeconfig --region ${awsEnvironmentVars.region} --name ${awsEnvironmentVars.eksCluster}") + executeCommand("kubectl create namespace ${context.getProjectId()}-${context.getEnvironment()}", false) } } @@ -55,29 +55,17 @@ class EKSService { return "${awsEnvironmentVars.account}.dkr.ecr.${awsEnvironmentVars.region}.amazonaws.com" } - protected boolean existRepository(String repositoryName) { - try { - steps.sh( - script: "aws ecr describe-repositories --repository-names ${repositoryName} --region ${awsEnvironmentVars.region}", - returnStatus: true - ) - return true - } catch (Exception e) { - return false - } - } - protected void createRepository(String repositoryName) { - executeCommand("aws ecr create-repository --repository-name ${repositoryName} --region ${awsEnvironmentVars.region}") + executeCommand("aws ecr create-repository --repository-name ${repositoryName} --region ${awsEnvironmentVars.region}", false) } - private void executeCommand(String command) { - return steps.sh( + private void executeCommand(String command, boolean showError = true) { + def status = steps.sh( script: command, returnStatus: true, label: "Executing command: ${command}" ) as int - if (status != 0) { + if (status != 0 && showError) { script.error("Error executing ${command}, status ${status}") } } From 9c746591dd69adc1a0f3690f24c16332491f9f17 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Sat, 30 Aug 2025 13:13:47 +0200 Subject: [PATCH 33/38] retagImages --- src/org/ods/component/ImageRepositoryEKS.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/ods/component/ImageRepositoryEKS.groovy b/src/org/ods/component/ImageRepositoryEKS.groovy index b2bf8f2a51..ae8a69a2e5 100644 --- a/src/org/ods/component/ImageRepositoryEKS.groovy +++ b/src/org/ods/component/ImageRepositoryEKS.groovy @@ -30,7 +30,6 @@ class ImageRepositoryEKS implements IImageRepository { } public void retagImages(String targetProject, Set images, String sourceTag, String targetTag) { - steps.echo "retagImages ${images.size()} images." images.each { image -> eks.createRepository(image) copyImage(image, context, sourceTag, targetTag) From 82cbc506656acc3353720f5c26a6dd6670277e33 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Sat, 30 Aug 2025 14:43:14 +0200 Subject: [PATCH 34/38] executeCommand --- src/org/ods/services/EKSService.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/services/EKSService.groovy b/src/org/ods/services/EKSService.groovy index 88192dcb83..2952544692 100644 --- a/src/org/ods/services/EKSService.groovy +++ b/src/org/ods/services/EKSService.groovy @@ -66,7 +66,7 @@ class EKSService { label: "Executing command: ${command}" ) as int if (status != 0 && showError) { - script.error("Error executing ${command}, status ${status}") + steps.error("Error executing ${command}, status ${status}") } } From 345e8a3bec4bcd1fc8c7ac127bf66d6f362faf38 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Fri, 31 Oct 2025 09:31:07 +0100 Subject: [PATCH 35/38] Add namespace override support in helmUpgrade method --- src/org/ods/component/HelmDeploymentStrategy.groovy | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 6ded86d301..27709c9f6e 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -108,13 +108,16 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { return rolloutData } - private void helmUpgrade(String targetProject) { + private void helmUpgrade(String targetProject) { steps.dir(options.chartDir) { jenkins.maybeWithPrivateKeyCredentials(options.helmPrivateKeyCredentialsId) { String pkeyFile -> if (pkeyFile) { steps.sh(script: "gpg --import ${pkeyFile}", label: 'Import private key into keyring') } - + // Maybe we need to deploy to another namespace (ie we want to deploy a monitoring stack into a specific namespace) + if (options.helmValues['namespaceOverride']) { + targetProject = options.helmValues['namespaceOverride'] + } // we add two things persistent - as these NEVER change (and are env independent) options.helmValues['registry'] = context.clusterRegistryAddress options.helmValues['componentId'] = context.componentId From 1891a25612ddd9a346db8d00950055a37ea22d84 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 3 Nov 2025 09:59:06 +0100 Subject: [PATCH 36/38] Enhance deploy method to support namespace override for image retagging and helm upgrade --- .../component/HelmDeploymentStrategy.groovy | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 27709c9f6e..8b23197cf9 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -89,12 +89,18 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { @Override Map> deploy() { - logger.info("Retagging images for ${context.targetProject} ") - imageRepository.retagImages(context.targetProject, getBuiltImages(), options.imageTag, options.imageTag) + // Maybe we need to deploy to another namespace (ie we want to deploy a monitoring stack into a specific namespace) + def targetProject = context.targetProject + if (options.helmValues['namespaceOverride']) { + targetProject = options.helmValues['namespaceOverride'] + logger.info("Override namespace deployment to ${targetProject} ") + } + logger.info("Retagging images for ${targetProject} ") + imageRepository.retagImages(targetProject, getBuiltImages(), options.imageTag, options.imageTag) logger.info("Rolling out ${context.componentId} with HELM, selector: ${options.selector}") - helmUpgrade(context.targetProject) - HelmStatus helmStatus = openShift.helmStatus(context.targetProject, options.helmReleaseName) + helmUpgrade(targetProject) + HelmStatus helmStatus = openShift.helmStatus(targetProject, options.helmReleaseName) if (logger.debugMode) { def helmStatusMap = helmStatus.toMap() logger.debug("${this.class.name} -- HELM STATUS: ${helmStatusMap}") @@ -113,11 +119,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { jenkins.maybeWithPrivateKeyCredentials(options.helmPrivateKeyCredentialsId) { String pkeyFile -> if (pkeyFile) { steps.sh(script: "gpg --import ${pkeyFile}", label: 'Import private key into keyring') - } - // Maybe we need to deploy to another namespace (ie we want to deploy a monitoring stack into a specific namespace) - if (options.helmValues['namespaceOverride']) { - targetProject = options.helmValues['namespaceOverride'] - } + } // we add two things persistent - as these NEVER change (and are env independent) options.helmValues['registry'] = context.clusterRegistryAddress options.helmValues['componentId'] = context.componentId From 305af1d67d3554dc88b3609fba3a606382c66976 Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Mon, 3 Nov 2025 10:15:57 +0100 Subject: [PATCH 37/38] Refactor getRolloutData method to accept targetProject parameter for improved namespace handling --- src/org/ods/component/HelmDeploymentStrategy.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 8b23197cf9..87e61c7de6 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -110,7 +110,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { // // we assume that Helm does "Deployment" that should work for most // // cases since they don't have triggers. // metadataSvc.updateMetadata(false, deploymentResources) - def rolloutData = getRolloutData(helmStatus) + def rolloutData = getRolloutData(helmStatus, targetProject) return rolloutData } @@ -170,7 +170,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { // ] @TypeChecked(TypeCheckingMode.SKIP) private Map> getRolloutData( - HelmStatus helmStatus + HelmStatus helmStatus, String targetProject ) { Map> rolloutData = [:] @@ -183,7 +183,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { [ type: 'helm', selector: options.selector, - namespace: context.targetProject, + namespace: targetProject, chartDir: options.chartDir, helmReleaseName: options.helmReleaseName, helmEnvBasedValuesFiles: options.helmEnvBasedValuesFiles, @@ -195,14 +195,14 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { ] ) def podDataContext = [ - "targetProject=${context.targetProject}", + "targetProject=${targetProject}", "selector=${options.selector}", "name=${name}", ] def msgPodsNotFound = "Could not find 'running' pod(s) for '${podDataContext.join(', ')}'" List podData = null for (def i = 0; i < options.deployTimeoutRetries; i++) { - podData = openShift.checkForPodData(context.targetProject, options.selector, name) + podData = openShift.checkForPodData(targetProject, options.selector, name) if (podData) { break } From d3b913d905ffbb467150650c1086c6475eaea48c Mon Sep 17 00:00:00 2001 From: s2oBCN Date: Fri, 5 Dec 2025 16:16:07 +0100 Subject: [PATCH 38/38] Fix parsePodJson method to handle 'Running' status in addition to 'running' --- src/org/ods/services/OpenShiftService.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/ods/services/OpenShiftService.groovy b/src/org/ods/services/OpenShiftService.groovy index e9f4b21401..e76a317c51 100644 --- a/src/org/ods/services/OpenShiftService.groovy +++ b/src/org/ods/services/OpenShiftService.groovy @@ -1052,7 +1052,7 @@ class OpenShiftService { @TypeChecked(TypeCheckingMode.SKIP) List parsePodJson(podJson, String resourceName = null) { List pods = [] - if (podJson && podJson.items.collect { it.status?.phase?.toLowerCase() }.every { it == 'running' }) { + if (podJson && podJson.items.collect { it.status?.phase?.toLowerCase() }.every { it == 'running' || it == 'Running' }) { // If we got passed a resourceName we need to collect all the pod data from each pod pods = extractPodData(podJson) }