4

What I want to do is to make a web app that lists in one single view the version of every application deployed in our Openshift (a fast view of versions). At this moment, the only way I have seen to locate the version of an app deployed in a pod is the ARTIFACT_URL parameter in the envirorment view, that's why I ask for that parameter, but if there's another way to get a pod and the version of its current app deployed, I'm also open to that option as long as I can get it through an API. Maybe I'd eventually also need an endpoint that retrieves the list of the current pods.

I've looked into the Openshift API and the only thing I've found that may help me is this GET but if the parameter :id is what I think, it changes with every deploy, so I would need to be modifying it constantly and that's not practical. Obviously, I'd also need an endpoint to get the list of IDs or whatever that let me identify the pod when I ask for the ARTIFACT_URL

Thanks!

mirekphd
  • 4,799
  • 3
  • 38
  • 59
Drumnbass
  • 867
  • 1
  • 14
  • 35
  • Surely you don't indend to re-write oc Client Tools where you can simply call it from a bash script or a python API ([openshift](https://pypi.org/project/openshift/)) and pass the output to the user...? – mirekphd Dec 14 '19 at 09:30

3 Answers3

1

There is a way to do that. See https://docs.openshift.com/enterprise/3.0/dev_guide/environment_variables.html

List Environment Variables

To list environment variables in pods or pod templates:

$ oc env <object-selection> --list [<common-options>]

This example lists all environment variables for pod p1:

$ oc env pod/p1 --list

ZF007
  • 3,708
  • 8
  • 29
  • 48
0

I suggest redesigning builds and deployments if you don't have persistent app versioning information outside of Openshift.

If app versions need to be obtained from running pods (e.g. with oc rsh or oc env as suggested elsewhere), then you have a serious reproducibility problem. Git should be used for app versioning, and all app builds and deployments, even in dev and test environments should be fully automated.

Within Openshift you can achieve full automation with Webhook Triggers in your Build Configs and Image Change Triggers in your Deployment Configs.

Outside of Openshift, this can be done at no extra cost using Jenkins (which can even be run in a container if you have persistent storage available to preserve its settings).

mirekphd
  • 4,799
  • 3
  • 38
  • 59
0

As a quick workaround you may also consider:

oc describe pods | grep ARTIFACT_URL

to get the list of values of your environment variable (here: ARTIFACT_URL) from all pods.

The corresponding list of pod names can be obtained either simply using 'oc get pods' or a second call to oc describe:

oc describe pods | grep "Name: "

(notice the 8 spaces needed to filter out other Names:)

mirekphd
  • 4,799
  • 3
  • 38
  • 59