diff --git a/CHANGELOG.md b/CHANGELOG.md index ed328a455a..3421e1a8fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +* Support StatefulSet in Helm charts ([#1108](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1108)) * Support deployment with only selected components ([#1081](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1081)) * The Document History indicates clearly when an SLC document has not changed ([#1099](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1099)) * Fix using repo variable before declaration ([#1117](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1117)) diff --git a/src/org/ods/component/AbstractDeploymentStrategy.groovy b/src/org/ods/component/AbstractDeploymentStrategy.groovy index 359541c9a6..fe5afc4119 100644 --- a/src/org/ods/component/AbstractDeploymentStrategy.groovy +++ b/src/org/ods/component/AbstractDeploymentStrategy.groovy @@ -7,7 +7,7 @@ import org.ods.util.PodData abstract class AbstractDeploymentStrategy implements IDeploymentStrategy { - protected final List DEPLOYMENT_KINDS = [ + protected List DEPLOYMENT_KINDS = [ OpenShiftService.DEPLOYMENT_KIND, OpenShiftService.DEPLOYMENTCONFIG_KIND, ] diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 0bd9360c91..67fe624a65 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -80,6 +80,14 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { this.options = new RolloutOpenShiftDeploymentOptions(config) this.openShift = openShift this.jenkins = jenkins + + // Why? In Groovy protected fields are implicitly final. + // As per Google: This seems to be the idiomatic way to override protected fields + DEPLOYMENT_KINDS.clear() + DEPLOYMENT_KINDS.addAll( + OpenShiftService.DEPLOYMENT_KIND, OpenShiftService.DEPLOYMENTCONFIG_KIND, + OpenShiftService.STATEFULSET_KIND, + ) } @Override @@ -173,6 +181,13 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { def rolloutData = [:] deploymentResources.each { resourceKind, resourceNames -> resourceNames.each { resourceName -> + + logger.info( + "Fetching resource for resourcekind: " + + "${resourceKind}/${resourceName}" + + "(selector: ${options.selector})" + ) + def podData = [] for (def i = 0; i < options.deployTimeoutRetries; i++) { podData = openShift.checkForPodData(context.targetProject, options.selector, resourceName) diff --git a/src/org/ods/orchestration/phases/DeployOdsComponent.groovy b/src/org/ods/orchestration/phases/DeployOdsComponent.groovy index 95b3cb852f..f192b1a5c3 100644 --- a/src/org/ods/orchestration/phases/DeployOdsComponent.groovy +++ b/src/org/ods/orchestration/phases/DeployOdsComponent.groovy @@ -58,15 +58,23 @@ class DeployOdsComponent { applyTemplates(openShiftDir, deploymentMean) def retries = project.environmentConfig?.openshiftRolloutTimeoutRetries ?: 10 + def podData = null for (def i = 0; i < retries; i++) { - def podData = os.checkForPodData(project.targetProject, deploymentMean.selector) + podData = os.checkForPodData(project.targetProject, deploymentMean.selector) if (podData) { - return podData + break } steps.echo("Could not find 'running' pod(s) with label '${deploymentMean.selector}' - waiting") steps.sleep(12) } + if (!podData) { + throw new DeployOdsComponentException( + "Error: Could not find 'running' pod(s) with label" + + "'${deploymentMean.selector}'" + ) + } + // TODO: Once the orchestration pipeline can deal with multiple replicas, // update this to deal with multiple pods. def pod = podData[0].toMap() @@ -75,6 +83,7 @@ class DeployOdsComponent { repo.data.openshift.deployments << [(deploymentName): pod] def deploymentMeanKey = deploymentName + '-deploymentMean' repo.data.openshift.deployments << [(deploymentMeanKey): deploymentMean] + return podData } } else { def originalDeploymentVersions = diff --git a/src/org/ods/orchestration/phases/DeployOdsComponentException.groovy b/src/org/ods/orchestration/phases/DeployOdsComponentException.groovy new file mode 100644 index 0000000000..9f5512e7b0 --- /dev/null +++ b/src/org/ods/orchestration/phases/DeployOdsComponentException.groovy @@ -0,0 +1,19 @@ +package org.ods.orchestration.phases + +class DeployOdsComponentException extends RuntimeException { + + DeployOdsComponentException() { + } + + DeployOdsComponentException(String message) { + super(message) + } + + DeployOdsComponentException(String message, Throwable cause) { + super(message, cause) + } + + DeployOdsComponentException(Throwable cause) { + super(cause) + } +} diff --git a/src/org/ods/services/OpenShiftService.groovy b/src/org/ods/services/OpenShiftService.groovy index cf0cf7f39c..308c245c00 100644 --- a/src/org/ods/services/OpenShiftService.groovy +++ b/src/org/ods/services/OpenShiftService.groovy @@ -18,6 +18,7 @@ class OpenShiftService { static final String ROLLOUT_WAITING = 'waiting' static final String DEPLOYMENTCONFIG_KIND = 'DeploymentConfig' static final String DEPLOYMENT_KIND = 'Deployment' + static final String STATEFULSET_KIND = 'StatefulSet' private final IPipelineSteps steps private final ILogger logger diff --git a/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy b/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy index 9bffdc955b..ecd675c40a 100644 --- a/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy +++ b/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy @@ -152,7 +152,7 @@ class OdsComponentStageRolloutOpenShiftDeploymentSpec extends PipelineSpockTestB def c = config + [environment: 'dev',targetProject: 'foo-dev',openshiftRolloutTimeoutRetries: 5,chartDir: 'chart'] IContext context = new Context(null, c, logger) OpenShiftService openShiftService = Mock(OpenShiftService.class) - openShiftService.getResourcesForComponent('foo-dev', ['Deployment', 'DeploymentConfig'], 'app=foo-bar') >> [Deployment: ['bar']] + openShiftService.getResourcesForComponent('foo-dev', ['Deployment', 'DeploymentConfig', 'StatefulSet'], 'app=foo-bar') >> [Deployment: ['bar']] openShiftService.getRevision(*_) >> 123 openShiftService.rollout(*_) >> "${config.componentId}-124" openShiftService.getPodDataForDeployment(*_) >> [new PodData([ deploymentId: "${config.componentId}-124" ])]