Howto return the deployment status of k8s/Openshift to your CI



  • Hi, we're currently implementing our deployment process to rollout new releases of our Java service onto Openshift. We intend to upgrade the service as soon as a new image gets pushed to the Docker Registry (or to update it manually via "oc rollout --latest")

    We currently have two related problems:

    • How to get the revision of our current deployment
    • How to get the status of that deployment

    Our only desparate approach to the second problem:
    oc rollout history dc/myapp
    REVISION STATUS CAUSE
    187 Complete caused by an image change
    217 Failed caused by a config change

    Does anybody know how we could accomplish this?


  • APPUiO Staff

    If you are using Jenkins then the easiest way to implement this is by using the OpenShift Jenkins plugin which has explicit support for triggering builds on ImageStream changes, i.e. an image is pushed into the internal or an external registry: https://wiki.jenkins-ci.org/display/JENKINS/OpenShift+Pipeline+Plugin, https://github.com/openshift/jenkins-plugin.

    Otherwise you can get the status of your deployment with something like this:

    #!/bin/bash
    
    shopt -s nocasematch
    
    DC="$1"
    
    # Get latest replication controller version
    LATEST_VERSION=`oc get dc/${DC} -o jsonpath='{.status.latestVersion}'`
    
    # Skip cancelled deployments
    while [[ `oc get rc/${DC}-${LATEST_VERSION} -o go-template=$'{{index .metadata.annotations "openshift.io/deployment.cancelled"}}\n'` == 'true' ]]; do
      ((LATEST_VERSION--))
    done
    
    # Get deployment status from latest replication controller
    oc get rc/${DC}-${LATEST_VERSION} -o go-template=$'{{index .metadata.annotations "openshift.io/deployment.phase"}}\n'
    

    This will return Complete for successful deployments.

    Note: We can't use JSONPath to retrieve the annotations because of K8S#31984. Should be fixed in OCP 3.5.


Log in to reply
 

Looks like your connection to APPUiO Discussion and Help Forum was lost, please wait while we try to reconnect.