Shakeer Hussain
Shakeer Hussain

Reputation: 2546

How to reload open shift config.yaml file automatically?

How to reload open shift config yaml file automatically when config value was updated?

Current I am redeploying to reload open shift config yaml. I don't want to redeploy application one more time for a config value change?

Below is my config.yaml file. How to write a syntax to Trigger pod and redepoy pod automatically and config value got change automatically?

apiVersion: template.openshift.io/v1
kind: Template
metadata:
  name: config
parameters:
- name: APPLICATION
  required: true
- name: BLUE_GREEN_VERSION
  required: true
- name: SQL_CONNECTION
  required: true
- name: API_URL
  required: true 
objects:
- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: ${APPLICATION}-${BLUE_GREEN_VERSION}
  data:
    appsettings.json: |-
      {
        "ConnectionStrings": {
          "SQLDB": "${SQL_CONNECTION}"
        },
        "URL":"${API_URL}",
        "AllowedHosts": "*"
      }

Upvotes: 1

Views: 483

Answers (1)

George
George

Reputation: 2512

I was checking the watch command, and it did not behave as expected.

So I made a simple script and tested it.

#!/bin/bash

# Set initial time of the last file update
INTIAL_LAST_MODIFICATION_TIME=`stat -c %Z $1`

while true
do
# Check time of the last time update
   LAST_MODIFICATIO_TIME=`stat -c %Z $1`

# Execute command, If file has changed
   if [[ "$LAST_MODIFICATIO_TIME" != "$INTIAL_LAST_MODIFICATION_TIME" ]]
   then
       $2
       INTIAL_LAST_MODIFICATION_TIME=$LAST_MODIFICATIO_TIME
   fi
   sleep ${3:-5}
done

Example usage will be,

./name_of_the_script 

{file_to_watch} 

{command_to_execute_if_file_have_changed} 

{time_to_wait_before_checking_again_in_seconds_default_is_5}

In your case, would be something like the following ./watch config.yaml "oc apply -f config.yaml" 2

Hope this will be helpful. And there are few 3rd party libraries that will provide more options. like entr, inotify-tools and watch exec

Upvotes: 2

Related Questions