Edit Config
In this step, you will experience how configuration is edited in ConfigHub. Config data is fully versioned and can be modified in a variety of ways. As you might expect, you can retrieve, modify and re-upload the data. But more interestingly, you can modify the data in place using a range of mutation functions.
Edit locally
Config data can easily be retrieved from ConfigHub, modified and re-uploaded. You can retrieve with:
cub unit get chatapp-dev --data-only > chatapp-dev.data.yaml
Then you edit with your favorite editor and re-upload with:
cub unit update chatapp-dev chatapp-dev.data.yaml
This automatically creates a new revision of the config unit. The update uses optimistic concurrency, so if the config data has changed in ConfigHub since you retrieved it, the update will fail. You can see the revision list with:
cub revision list chatapp-dev
and you can see the change you just made with:
cub unit diff -u chatapp-dev --from=-1
which means "see difference between the head revision and the revision just before head". The -u flag will make it only print the sections of the unit that has differences.
There is also a convenient edit command in the CLI that combines the get and update:
cub unit edit chatapp-dev
This will open chatapp-dev config data in your default editor. When you save and exit, the changes will be updated in ConfigHub.
Use Functions
The real power of ConfigHub lies in editing with functions. Config data is structured data and functions are used to edit exactly the parts you want. Even better, functions will let you make exactly the same edit to many different config resources in one command. This is why you don't have to worry about repetitive config data: you can still change a single config field in all your environments in one go.
For our chat app, let's edit the title environment variable:
cub run set-env-var \
--unit chatapp-dev \
--container-name backend \
--env-var CHAT_TITLE \
--env-value "My own AI Chat"
This runs the set-env-var function which can set and change environment variables in Kubernetes containers. To see what happened, run this:
cub unit diff -u chatapp-dev --from=-1
and you will see something like this:
--- tumble-cub/chatapp-dev/1
+++ tumble-cub/chatapp-dev/2
@@ -1,4 +0,0 @@
----
# PostgreSQL Database
apiVersion: apps/v1
kind: StatefulSet
@@ -85,7 +87,1 @@
- name: DATABASE_URL
value: "postgres://admin:password@postgres:5432/chatdb"
- name: CHAT_TITLE
- value: "Cubby Chat"
+ value: "My own AI Chat"
- name: PORT
value: "8080"
- name: REGION
Every time you make a change to config data in a unit, a new revision will automatically be created. You can restore a previous revision with:
cub unit update chatapp-dev --restore 1
Summary
- The config data in Config Units can be edited like any other data file
- Config data is fully versioned. Every time you make a change, a new revision is automatically created. Kind of like Google Docs.
- Config data can be manipulated as a data structure. You use functions to make changes to specific fields in the data structure.