| |
@@ -6,39 +6,35 @@
|
| |
import java.text.*
|
| |
|
| |
def run(models) {
|
| |
- openshift.withCluster() {
|
| |
- def objects = openshift.apply(models)
|
| |
- def dcs = objects.narrow('dc')
|
| |
- def rm = dcs.rollout()
|
| |
- def replicas = 0
|
| |
- dcs.withEach {
|
| |
- replicas += it.object().spec.replicas
|
| |
- }
|
| |
- return replicas
|
| |
+ def objects = openshift.apply(models)
|
| |
+ def dcs = objects.narrow('dc')
|
| |
+ def rm = dcs.rollout()
|
| |
+ def replicas = 0
|
| |
+ dcs.withEach {
|
| |
+ replicas += it.object().spec.replicas
|
| |
}
|
| |
+ return replicas
|
| |
}
|
| |
|
| |
def wait(num, selector) {
|
| |
echo "Waiting for ${num} test pods matching ${selector} to become Ready"
|
| |
- openshift.withCluster() {
|
| |
- def pods = openshift.selector('pods', selector)
|
| |
- timeout(10) {
|
| |
- pods.untilEach(num) {
|
| |
- def pod = it.object()
|
| |
- if (pod.status.phase in ["New", "Pending", "Unknown"]) {
|
| |
- return false
|
| |
- }
|
| |
- if (pod.status.phase == "Running") {
|
| |
- for (cond in pod.status.conditions) {
|
| |
- if (cond.type == 'Ready' && cond.status == 'True') {
|
| |
- echo "Pod ${pod.metadata.name} is ready"
|
| |
- return true
|
| |
- }
|
| |
+ def pods = openshift.selector('pods', selector)
|
| |
+ timeout(10) {
|
| |
+ pods.untilEach(num) {
|
| |
+ def pod = it.object()
|
| |
+ if (pod.status.phase in ["New", "Pending", "Unknown"]) {
|
| |
+ return false
|
| |
+ }
|
| |
+ if (pod.status.phase == "Running") {
|
| |
+ for (cond in pod.status.conditions) {
|
| |
+ if (cond.type == 'Ready' && cond.status == 'True') {
|
| |
+ echo "Pod ${pod.metadata.name} is ready"
|
| |
+ return true
|
| |
}
|
| |
- return false
|
| |
}
|
| |
- error("Test pod ${pod.metadata.name} is not running. Current phase is ${pod.status.phase}.")
|
| |
+ return false
|
| |
}
|
| |
+ error("Test pod ${pod.metadata.name} is not running. Current phase is ${pod.status.phase}.")
|
| |
}
|
| |
}
|
| |
}
|
| |
@@ -50,25 +46,23 @@
|
| |
|
| |
def cleanup(int age=60, String... apps) {
|
| |
// age is specified in minutes
|
| |
- openshift.withCluster() {
|
| |
- def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
| |
- df.setTimeZone(TimeZone.getTimeZone("UTC"))
|
| |
- def oldobjs = []
|
| |
- for (app in apps) {
|
| |
- def selected = openshift.selector("all,pvc,configmap,secret", ["app": app])
|
| |
- oldobjs.addAll(selected.objects())
|
| |
+ def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
| |
+ df.setTimeZone(TimeZone.getTimeZone("UTC"))
|
| |
+ def oldobjs = []
|
| |
+ for (app in apps) {
|
| |
+ def selected = openshift.selector("all,pvc,configmap,secret", ["app": app])
|
| |
+ oldobjs.addAll(selected.objects())
|
| |
+ }
|
| |
+ def now = new Date()
|
| |
+ // Delete all objects that are older than 1 hour
|
| |
+ for (obj in oldobjs) {
|
| |
+ if (!obj.metadata.creationTimestamp) {
|
| |
+ continue
|
| |
}
|
| |
- def now = new Date()
|
| |
- // Delete all objects that are older than 1 hour
|
| |
- for (obj in oldobjs) {
|
| |
- if (!obj.metadata.creationTimestamp) {
|
| |
- continue
|
| |
- }
|
| |
- def creationTime = df.parse(obj.metadata.creationTimestamp)
|
| |
- if (now.getTime() - creationTime.getTime() > (1000 * 60 * age)) {
|
| |
- echo "Deleting ${obj.kind} ${obj.metadata.name}..."
|
| |
- openshift.delete(obj.kind, obj.metadata.name, "--ignore-not-found=true")
|
| |
- }
|
| |
+ def creationTime = df.parse(obj.metadata.creationTimestamp)
|
| |
+ if (now.getTime() - creationTime.getTime() > (1000 * 60 * age)) {
|
| |
+ echo "Deleting ${obj.kind} ${obj.metadata.name}..."
|
| |
+ openshift.delete(obj.kind, obj.metadata.name, "--ignore-not-found=true")
|
| |
}
|
| |
}
|
| |
}
|
| |
This will allow users to customize the OpenShift cluster and project
that they want to interact with.
Users are expected to call
c3i.foo()
functions within aopenshift.withCluster()
closure. We need to ensure our Jenkinsfile are doing this way before merging this.