Comments (12)
For a new deployment of a single-container pod, we use the following selectors & fields on the pod to verify deployments:
def module = 'app-a'
def dcObj = openshift.selector('dc', module).object()
def podSelector = openshift.selector('pod', [deployment: "${module}-${dcObj.status.latestVersion}"])
podSelector.untilEach {
echo "pod: ${it.name()}"
return it.object().status.containerStatuses[0].ready
}
Obviously, this won't work if your DeploymentConfig contains multiple containers.
Edit: Here's an example when using more than 1 replica in a dc:
timeout(5) {
def dcSelector = openshift.selector('dc', 'myapp')
def deployment = "myapp-${dcSelector.object().status.latestVersion}"
echo "Checking ${deployment}"
def pods = openshift.selector('pods', [deployment: "${deployment}"])
pods.objects().untilEach(1) { //make sure at least one pod is ready
return it.status.containerStatuses.every { //containerStatuses are an array of statuses for multi-container dc; check if all of them are ready
it.ready
}
}
}
from jenkins-client-plugin.
@coreydaley - per my comment at #84 (comment) let's use this bug to minimally document some of the best flavors for this.
As a follow on, this notion I think would make the perfect guinea pig for this plugin crafter a pipeline "global library" of common combination of various primitives of this plugin to achieve results that most users would find useful.
I need to get a card opened for the gloabl lib piece ... I know I've discussed with @csrwng and @bparees in the past.
from jenkins-client-plugin.
I do it this way:
try {
openshift.withCluster(crp) {
openshift.withProject(ocstage) {
timeout(10) {
echo 'Execute oc.yaml'
def list = openshift.process(readFile(file:'oc.yaml'), params)
echo 'Process oc Template'
def dc = openshift.apply(list).narrow("dc")
echo 'Start deployment'
def rm = dc.rollout()
rm.latest()
echo 'Getting Status'
// Wait and print status
rm.status()
}
}
}
} catch (Exception e) {
echo 'Rollout failed.'
error e.getMessage()
}
from jenkins-client-plugin.
@arnaud-deprez - you should be able to create a watch (i.e. https://github.com/openshift/jenkins-client-plugin#watching-and-waiting-of-course) on the replication controller to determine the status, where you determine the correct RC from the DC. That is what the old plugin does.
If you are able to infer the right scriptlet from the doc, great, let us know. Otherwise, @coreydaley can help with constructing a precise example (and perhaps updating our watch example)
@bparees fyi
from jenkins-client-plugin.
@arnaud-deprez Here is an example of checking to make sure that the deployment is completed, you will need to check that status.phase == "Running"
https://github.com/openshift/origin/blob/master/examples/jenkins/pipeline/nodejs-sample-pipeline.yaml#L55-L65
from jenkins-client-plugin.
from jenkins-client-plugin.
Hi,
Thanks for the example but it does not really work.
When you perform a rolling update, at the time you check the dc/pod status, it will match 99% time the old pods because it is not yet stopped.
I could use a combination of watch to wait the deployment is complete and then check the dc/pods status. But what if I plan to scale 10 pods but I want to be sure there is at least one new running instance without waiting the whole deployment to complete ?
from jenkins-client-plugin.
from jenkins-client-plugin.
@gabemontero that's exactly what I liked in the deprecated openshift client plugin. However, the cons of the old plugin is that it was hard to perform more fine grained tasks and that's why most of the time we end up using oc ...
command.
So definetely, having a higher level library on top of this for common use case and best practices would provide more power :-)
from jenkins-client-plugin.
I went spelunking around in the code of the old plugin, here is the equivalent procedure from the old plugin with this new one. It doesn't have all the switches, but it gets the job done. I will open a docs PR shortly.
I'd be very keen to contribute to a https://jenkins.io/doc/book/pipeline/shared-libraries/ if we set one up. There is https://github.com/fabric8io/fabric8-pipeline-library, but it does a ton of stuff. I'd be a fan of a smaller, more focused library, but that prob warrants a discussion with the fabric8 folks.
def latestDeploymentVersion = openshift.selector('dc',"${APP_NAME}").object().status.latestVersion
def rc = openshift.selector('rc', "${APP_NAME}-${latestDeploymentVersion}")
rc.untilEach(1){
def rcMap = it.object()
return (rcMap.status.replicas.equals(rcMap.status.readyReplicas))
}
from jenkins-client-plugin.
Thanks @sherl0cks ! ... such a foray was exactly what I was referring to in #84 (comment)
And agreed on your shared libs perspective. Just a question on how it gets prioritized for my team...though I was looking for the trello card I was sure we had opened for this, and now I can't find it.
In the interim I've created https://trello.com/c/iQr3XsF8/1543-start-up-a-set-of-pipeline-global-libraries-for-common-client-plugin-patterns-pipelineintegration
we can close it as a dup if needed.
from jenkins-client-plugin.
For the second example, .objects().untilEach() didn't worked for me. It said "No signature of method: ArrayList.untilEach() is applicable for argument types org.jenkinsci.<...>.CpsClosure2
".
I have modified it as follows:
timeout(5) {
def numPods = 1
def dcSelector = openshift.selector('dc', 'myapp')
def deployment = "myapp-${dcSelector.object().status.latestVersion}"
def podSelector = openshift.selector('pods', [deployment: "${deployment}"])
podSelector.untilEach(numPods) { // at least <numPods> is ready
return it.object().status.containerStatuses.every { //containerStatuses are an array of statuses for multi-container dc; check if all of them are ready
it.ready
}
}
}
from jenkins-client-plugin.
Related Issues (20)
- Question: What extra steps should i follow if my OCP4 cluster is using a proxy ? HOT 4
- exportable did not work on newer openshift clusters HOT 4
- Stream stdout to console for passthrough operations HOT 5
- Plugin incompatible with new-style clouds configuration. HOT 5
- Error after Warning HOT 7
- Can't get api token from com.openshift.jenkins.plugnis.OpenShiftTokenCredentials in pipeline HOT 5
- List of DSL methods required HOT 3
- Error to parse POM's HOT 4
- 'restart' subcommand is missing for rollout()
- Support current version of oc tool HOT 4
- Plugin installation broke credentials used by other plugins HOT 12
- Argument was classified as an image, image~source, or loaded template reference but should be git repo HOT 7
- Leftover oc processes after wait() calls HOT 7
- Plugin doesn't detect capabilities (--ignore-not-found) from recent OC versions HOT 8
- No credentials shown in cluster configuration dropdown HOT 6
- Job fails if there are spaces in the project name, using raw command HOT 9
- Error flags cannot be placed before plugin name on external Jenkins declarative pipeline HOT 2
- Unable to retrieve object names using kubernetes-plugin sidecar container HOT 5
- java.nio.file.NoSuchFileException after upgrade to 1.0.37 HOT 5
- Certificate options not escaped HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jenkins-client-plugin.