OPENSHIFT

OpenShift Web Console Extensions

#sync , #Red Hat , #container , #webconsole , #extensions

OpenShift Web Console Extensions

Testing Environment: OpenShift 3.11
Applicable Environment: OpenShift 3.9+

As of OpenShift 3.9, the web console requires URL references rather than static content directories.[1]

In OpenShift 3.7 and lower, you could mount static files from your masters through the master-config.yaml file.[2] Since this no longer applies, we have to provide our own webserver with the content, to be referenced by the web console pod remotely. I checked for ways to mount static files to the web console pod; however, in the new design there is no static directory location within the pod itself from which it could reference such files. The web console application running within the pod is a standalone executable.

The openshift-ansible project does contain a variable to make settings for this, so it is aware of these URL references. You should adjust your inventory file so that subsequent updates do not remove your custom extensions.[3]

openshift_web_console_extension_script_urls=['https://webconsole-extensions.apps.example.com/disable-catalog.js']

You can do this with any webserver of your choice. Here I chose apache httpd.

  1. Create a new project.

    $ oc new-project webconsole-extensions
    Now using project "webconsole-extensions" on server "https://openshift.example.com:8443".
    
    You can add applications to this project with the 'new-app' command. For example, try:
    
        oc new-app centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git
    
    to build a new example application in Ruby.
  2. Create a new app from httpd imagestream (which on my cluster points to registry.redhat.io/rhscl/httpd-24-rhel7). Check out the docs for details on building for this image, if you want to use Passthrough or ReEncrypt you’ll need to add your own certs. [4]

    $ oc new-app httpd~https://github.com/briantward/webconsole-extensions
    --> Found image 9477422 (8 days old) in image stream "openshift/httpd" under tag "2.4" for "httpd"
    
        Apache httpd 2.4
        ----------------
        Apache httpd 2.4 available as container, is a powerful, efficient, and extensible web server. Apache supports a variety of features, many implemented as compiled modules which extend the core functionality. These can range from server-side programming language support to authentication schemes. Virtual hosting allows one Apache installation to serve many different Web sites.
    
        Tags: builder, httpd, httpd24
    
        * A source build using source code from https://github.com/briantward/webconsole-extensions will be created
          * The resulting image will be pushed to image stream tag "webconsole-extensions:latest"
          * Use 'start-build' to trigger a new build
        * This image will be deployed in deployment config "webconsole-extensions"
        * Ports 8080/tcp, 8443/tcp will be load balanced by service "webconsole-extensions"
          * Other containers can access this service through the hostname "webconsole-extensions"
    
    --> Creating resources ...
        imagestream.image.openshift.io "webconsole-extensions" created
        buildconfig.build.openshift.io "webconsole-extensions" created
        deploymentconfig.apps.openshift.io "webconsole-extensions" created
        service "webconsole-extensions" created
    --> Success
        Build scheduled, use 'oc logs -f bc/webconsole-extensions' to track its progress.
        Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
         'oc expose svc/webconsole-extensions'
        Run 'oc status' to view your app.
  3. Create a route, I chose Edge SSL termination but you may want to build it differently:

    $ oc create route edge --service=webconsole-extensions --hostname=webconsole-extensions.example.com --port=8080-tcp
    route.route.openshift.io/webconsole-extensions created
  4. Validate the resource is served:

    $ curl https://webconsole-extensions.apps.example.com/disable-catalog.js
    window.OPENSHIFT_CONSTANTS.DISABLE_SERVICE_CATALOG_LANDING_PAGE = true
  5. Edit the webconsole config to add this extension script:

    $ oc edit cm webconsole-config -n openshift-web-console

    Modify and save as needed:

    ...
        extensions:
          properties: null
          scriptURLs: ['https://webconsole-extensions.apps.example.com/disable-catalog.js']
          stylesheetURLs: []
    ...

    You should see the web console pods pick up the change within 2 minutes or so.