Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

OpenShift Operator to apply Environment Variables from ConfigMaps

Notifications You must be signed in to change notification settings

rh-event-flow/EnvironmentVariableOperator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Environment Variable Operator

Operator that keeps Environment Variables synchronised with ConfigMaps. Watches for updates to ConfigMaps and when one is created, modified or deleted this operator will create Environment Variables in the relevant DeploymentConfig. Also watches for updates to DeploymentConfigs and will add any Environment Variables found in associated ConfigMaps.

It is not safe to have multiple ConfigMaps that target the same Deployment and Environment Variable names. Doing so will lead to race conditions and unpredictability.

If ConfigMaps are modified the Operator is not able to remove Environment Variables from the Deployments. However, if ConfigMaps are deleted the Environment Variables they contain will be removed from the Deployments.

Deployment

The Operator can run inside or outside OpenShift. To start it run either

$ mvn clean package
$ java -jar target/EnvironmentVariableOperator.jar

Or for an OpenShift deployment

$ mvn clean pacakge fabric8:deploy -Popenshift

Depending on your permissions you may need to run the followinf command to allow your OpenShift user to access the ConfigMaps.

$ oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:myproject:default

Deployment using ABP

The Operator can be deployed using an Ansible Playbook Bundle from the OCP Broker. Once the OCP Broker is installed the Environment Variable Operator will appear in the Service Catalog.

TODO: Investigate permissions more

Usage

A full example is in the Examples directory where vanilla Kafka producer and consumer are configured using Environment Variables. They will not connect to a Topic if the Environment Variables are not present. To activate the Operator you need to create a ConfigMap with three labels:

streamzi.io/kind=ev
streamzi.io/target=Consumer

The first label indicates that this ConfigMap cotains a data payload of Environment Variables. The second and third labels identify the selector of the application (Deployment) that will receve the enviroment variables. e.g. selector-list includes app=Consumer. The full ConfigMap should look similar to the following snippet.

apiVersion: v1
data:
  bootstrap.servers: 'my-cluster-kafka:9092'
  topic: topic-71
kind: ConfigMap
metadata:
  creationTimestamp: '2018-07-03T10:03:53Z'
  labels:
    streamzi.io/kind: ev
    streamzi.io/target: Consumer
  name: consumer.cm
  namespace: myproject
  resourceVersion: '285304'
  selfLink: /api/v1/namespaces/myproject/configmaps/consumer.cm
  uid: 64279a1a-7ea8-11e8-bd15-7a9aad351283

About

OpenShift Operator to apply Environment Variables from ConfigMaps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages