Skip to content

Commit

Permalink
BUGFIX: ods-deployments file repeats image in mono repository setup (#…
Browse files Browse the repository at this point in the history
…1023)

Co-authored-by: Martin Marcher <[email protected]>
  • Loading branch information
serverhorror and serverhorror authored Apr 30, 2024
1 parent 2d95afb commit 61da8e2
Show file tree
Hide file tree
Showing 21 changed files with 3,840 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
* Fix ods-deployments file repeats image in mono repository setup ([#1011](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1011))
* Preload images into the cluster before initiating the rollout process using Helm ([#1026](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1026)).
* Given that Helm performs an atomic rollout, it's necessary to import all images into the mono repository prior to initiating the rollout process with Helm.

Expand Down Expand Up @@ -29,6 +30,9 @@
## [4.3.4] - 2024-02-20

* Fix documentation refers to qs with prefix infra- however there are only inf- quickstarters ([#1060](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1060))
* Fix ods-deployments file repeats image in mono repository setup ([#1011](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1011))
* Fix parameter count warning in ([86e1d](https://github.com/opendevstack/ods-jenkins-shared-library/commit/86e1d583b271446ef1489339da0912f78406e40d))
* Remove `jvmArgs "-XX:MaxPermSize=256m"` from build.gradle as it is no longer supported (See https://docs.oracle.com/javase/9/migrate/#GUID-1F270BDA-50B0-49C8-807E-0B727CCC5169)
* Aqua scanner and Helm deployment conflict fix for jenkins shared library ([#1067](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1067))
* Fix ods-infra components require OpenShift projects in Deploy stage ([#1047](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1047))

Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ test {
systemProperty 'com.athaydes.spockframework.report.projectName', 'ods-jenkins-shared-library'
systemProperty 'com.athaydes.spockframework.report.projectVersion', version
maxHeapSize = "2048m"
jvmArgs "-XX:MaxPermSize=256m"
systemProperty "testRecordMode", project.findProperty('testRecordMode')?: false
systemProperty "generateExpectedPdfFiles", project.findProperty('generateExpectedPdfFiles')?: false
systemProperty "nexusURL", project.findProperty('nexusURL')?: "http://nexus.odsbox.lan:7990"
Expand All @@ -137,7 +136,7 @@ test {
}

codenarc {
toolVersion = '1.5'
toolVersion = '1.6'
configFile = file('codenarc.groovy')
maxPriority1Violations = 0
maxPriority2Violations = 1
Expand Down
1 change: 1 addition & 0 deletions src/org/ods/component/AbstractDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ abstract class AbstractDeploymentStrategy implements IDeploymentStrategy {
!it.startsWith("imported-")
}
}

}
1 change: 1 addition & 0 deletions src/org/ods/component/CopyImageOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ class CopyImageOptions extends Options {
private String image
@SuppressWarnings('UnusedPrivateField')
private String imageTag

}
1 change: 1 addition & 0 deletions src/org/ods/component/CopyImageStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ class CopyImageStage extends Stage {
"(${context.componentId}) " +
"${this.options.registry}/${this.options.repo}/${this.options.image}'"
}

}
2 changes: 1 addition & 1 deletion src/org/ods/component/HelmDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy {
resourceNames.each { resourceName ->
def podData = []
for (def i = 0; i < options.deployTimeoutRetries; i++) {
podData = openShift.checkForPodData(context.targetProject, options.selector)
podData = openShift.checkForPodData(context.targetProject, options.selector, resourceName)
if (!podData.isEmpty()) {
break
}
Expand Down
1 change: 1 addition & 0 deletions src/org/ods/component/IContext.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ interface IContext {

// get the internal cluster registry address
String getClusterRegistryAddress ()

}
2 changes: 2 additions & 0 deletions src/org/ods/component/IDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import org.ods.util.PodData

@SuppressWarnings('MethodCount')
interface IDeploymentStrategy {

Map<String, List<PodData>> deploy()

}
7 changes: 2 additions & 5 deletions src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import groovy.transform.TypeCheckingMode
import org.ods.services.OpenShiftService
import org.ods.services.JenkinsService
import org.ods.util.ILogger
//import org.ods.openshift.OpenShiftResourceMetadata
//import org.ods.util.PodData

@SuppressWarnings('ParameterCount')
@TypeChecked
Expand All @@ -19,7 +17,6 @@ class RolloutOpenShiftDeploymentStage extends Stage {
private IDeploymentStrategy deploymentStrategy
private Map<String, Object> config


@SuppressWarnings(['AbcMetric', 'CyclomaticComplexity'])
@TypeChecked(TypeCheckingMode.SKIP)
RolloutOpenShiftDeploymentStage(
Expand Down Expand Up @@ -101,7 +98,6 @@ class RolloutOpenShiftDeploymentStage extends Stage {
this.options = new RolloutOpenShiftDeploymentOptions(config)
this.openShift = openShift
this.jenkins = jenkins

}

// This is called from Stage#execute if the branch being built is eligible.
Expand All @@ -119,7 +115,7 @@ class RolloutOpenShiftDeploymentStage extends Stage {
def isTailorDeployment = steps.fileExists(options.openshiftDir)
logger.info("isTailorDeployment: ${isTailorDeployment}")

if (isTailorDeployment && isHelmDeployment){
if (isTailorDeployment && isHelmDeployment) {
steps.error("Must be either a Tailor based deployment or a Helm based deployment")
throw new IllegalStateException("Must be either a Tailor based deployment or a Helm based deployment")
}
Expand All @@ -143,4 +139,5 @@ class RolloutOpenShiftDeploymentStage extends Stage {
}
STAGE_NAME
}

}
1 change: 1 addition & 0 deletions src/org/ods/component/ScanWithAquaOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class ScanWithAquaOptions extends Options {
/**
* Timeout of scan (defaults to 5 minutes - 300 seconds). */
Integer scanTimeoutSeconds

}
2 changes: 1 addition & 1 deletion src/org/ods/component/ScanWithAquaStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ScanWithAquaStage extends Stage {
])
}
if (messages) {
data.put("messages",[
data.put("messages", [
[ title: "Messages", value: prepareMessageToBitbucket(messages), ]
])
}
Expand Down
1 change: 1 addition & 0 deletions src/org/ods/component/ScanWithSonarOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ class ScanWithSonarOptions extends Options {
* In order to be able to receive the imageRef for scanning, the `resourceName` needs
* to be the same as in BuildOpenShiftImageStage. */
String resourceName

}
1 change: 1 addition & 0 deletions src/org/ods/component/ScanWithTrivyOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ class ScanWithTrivyOptions extends Options {
* possible value.
* Example: `['--debug', '--timeout=10m']` */
List<String> additionalFlags

}
4 changes: 2 additions & 2 deletions src/org/ods/component/ScanWithTrivyStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ScanWithTrivyStage extends Stage {
default:
logger.info "An unknown return code was returned: ${returnCode}"
}
logger.infoClocked(options.resourceName,"Trivy scan (via CLI)")
logger.infoClocked(options.resourceName, "Trivy scan (via CLI)")
return returnCode
}

Expand All @@ -123,7 +123,7 @@ class ScanWithTrivyStage extends Stage {
]

if (messages) {
data.put("messages",[
data.put("messages", [
[ title: "Messages", value: prepareMessageToBitbucket(messages), ]
])
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/ods/component/TailorDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class TailorDeploymentStrategy extends AbstractDeploymentStrategy {
'tailorParamFile': options.tailorParamFile,
'tailorParams': options.tailorParams,
'tailorPreserve': options.tailorPreserve,
'tailorVerify': options.tailorVerify
'tailorVerify': options.tailorVerify,
])
rolloutData["${resourceKind}/${resourceName}"] = podData
// TODO: Once the orchestration pipeline can deal with multiple replicas,
Expand Down
23 changes: 17 additions & 6 deletions src/org/ods/services/OpenShiftService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1016,21 +1016,32 @@ class OpenShiftService {
}

@TypeChecked(TypeCheckingMode.SKIP)
// checkForPodData returns a subset of information from every pod, once
// all pods matching the label are "running". If this is not the case,
// it returns an empty list.
List<PodData> checkForPodData(String project, String label) {
List<PodData> pods = []
// checkForPodData returns a subset of information from every pod.
// It only considers the pods matching a label and are in a state of "running".
// If this is not the case, it returns an empty list.
List<PodData> checkForPodData(String project, String label, String resourceName = null) {
def stdout = steps.sh(
script: "oc -n ${project} get pod -l ${label} -o json",
returnStdout: true,
label: "Getting OpenShift pod data for pods labelled with ${label}"
).toString().trim()
def podJson = new JsonSlurperClassic().parseText(stdout)
return parsePodJson(podJson, resourceName)
}

@TypeChecked(TypeCheckingMode.SKIP)
List<PodData> parsePodJson(podJson, String resourceName = null) {
List<PodData> pods = []
if (podJson && podJson.items.collect { it.status?.phase?.toLowerCase() }.every { it == 'running' }) {
// If we got passed a resourceName we need to collect all the pod data from each pod
pods = extractPodData(podJson)
}
pods
// if we have a resourceName only return the items matching that
if (resourceName != null) {
def filteredPods= pods.findAll { it.podName.startsWith(resourceName) }
return filteredPods
}
return pods
}

private String getPodManagerName(String project, String kind, String name, int revision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class HelmDeploymentStrategySpec extends PipelineSpockTestBase {
def ctxData = contextData + [environment: 'dev', targetProject: 'foo-dev', openshiftRolloutTimeoutRetries: 5, chartDir: 'chart']
IContext context = new Context(null, ctxData, logger)
OpenShiftService openShiftService = Mock(OpenShiftService.class)
openShiftService.checkForPodData('foo-dev', 'app=foo-bar') >> [new PodData([deploymentId: "${contextData.componentId}-124"])]
openShiftService.checkForPodData(*_) >> [new PodData([deploymentId: "${contextData.componentId}-124"])]
ServiceRegistry.instance.add(OpenShiftService, openShiftService)

JenkinsService jenkinsService = Stub(JenkinsService.class)
Expand Down
Loading

0 comments on commit 61da8e2

Please sign in to comment.