Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get project's route/service/configmaps? #87

Closed
MrNocTV opened this issue Dec 8, 2020 · 2 comments
Closed

How to get project's route/service/configmaps? #87

MrNocTV opened this issue Dec 8, 2020 · 2 comments

Comments

@MrNocTV
Copy link

MrNocTV commented Dec 8, 2020

Please help, I don't see in your documentation mentioning these common resources.

@bradmwilliams
Copy link
Contributor

The easiest way is via selectors...

  with oc.tracking() as t, oc.timeout(30 * 60):
      try:
          with oc.project('my-project'):
              apiobjects = oc.selector(['routes', 'services', 'configmaps']).objects()

              for apiobject in apiobjects:
                  print(json.dumps(apiobject.model, indent=4, default=str))

      except (ValueError, OpenShiftPythonException, Exception) as e:
          traceback.print_exc()
          logger.error("Tracking:\n{}\n\n".format(t.get_result().as_json(redact_streams=False)))
          raise e

@MrNocTV
Copy link
Author

MrNocTV commented Dec 8, 2020

Thanks, I've come up with my own solution, a little ugly but it works.

Maybe adding more example, categorized by resources type will make the library more attrative to lazy dev (it's also the reason why I choose to use Python instead of making a bash script) :D

import openshift as oc

if __name__ == '__main__':
    project_selector = oc.selector('projects')
    projects = project_selector.objects()
    number_of_projects = len(projects)

    for i in range(number_of_projects):
        project = projects[i]
        oc.invoke('project', [project.name()])
        tokens = oc.invoke('get', ['routes']).actions()[0].as_dict()['out'].replace('\n', ' ').split(' ')
        route = [x for x in tokens if len(x) > 0 and not x.isupper()]
        try:
            if 'soba-ivy-poc' in route[1]:
                print(oc.get_project_name() + ', route: ' + route[1])
        except:
            # ¯\_(ツ)_/¯

@MrNocTV MrNocTV closed this as completed Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants