Giter VIP home page Giter VIP logo

Comments (12)

 avatar commented on July 1, 2024 9

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.

gabemontero avatar gabemontero commented on July 1, 2024 2

@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.

 avatar commented on July 1, 2024 1

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.

gabemontero avatar gabemontero commented on July 1, 2024

@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.

coreydaley avatar coreydaley commented on July 1, 2024

@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.

gabemontero avatar gabemontero commented on July 1, 2024

from jenkins-client-plugin.

arnaud-deprez avatar arnaud-deprez commented on July 1, 2024

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.

gabemontero avatar gabemontero commented on July 1, 2024

from jenkins-client-plugin.

arnaud-deprez avatar arnaud-deprez commented on July 1, 2024

@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.

sherl0cks avatar sherl0cks commented on July 1, 2024

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.

gabemontero avatar gabemontero commented on July 1, 2024

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.

igorfraa avatar igorfraa commented on July 1, 2024

@tomcooperca

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.