Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable StatefulSet #1108

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/org/ods/component/AbstractDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.ods.util.PodData

abstract class AbstractDeploymentStrategy implements IDeploymentStrategy {

protected final List<String> DEPLOYMENT_KINDS = [
protected List<String> DEPLOYMENT_KINDS = [
OpenShiftService.DEPLOYMENT_KIND, OpenShiftService.DEPLOYMENTCONFIG_KIND,
]

Expand Down
15 changes: 15 additions & 0 deletions src/org/ods/component/HelmDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions src/org/ods/orchestration/phases/DeployOdsComponent.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
serverhorror marked this conversation as resolved.
Show resolved Hide resolved
// update this to deal with multiple pods.
def pod = podData[0].toMap()
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions src/org/ods/services/OpenShiftService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ])]
Expand Down