func()

in pkg/fsnotify/fsnotify.go [58:81]


func (fs *fsWatchProvider) watchConfig() error {
	fs.viper.SetConfigFile(fs.configFilePath)
	fs.viper.SetConfigType("json") // required when filename doesn't have any extension.

	// perform sync during container restart
	if err := wait.ExponentialBackoff(backoff, fs.SyncSecrets); err != nil {
		return errors.Wrap(err, "could not sync K8s secrets when initializing fs watcher")
	}

	fs.viper.WatchConfig()
	fs.viper.OnConfigChange(func(event fsnotify.Event) {
		klog.Infof("Changes received for config file %s. Operation: %s.", fs.configFilePath, event.Op)
		if err := wait.ExponentialBackoff(backoff, fs.SyncSecrets); err != nil {
			// TODO: Should kill process here?
			// If k8s secret is not updated then subsequent new ssm-agent containers will not be able to authenticate
			// with ssm backend service. Other option is to add pod event but failure here could be most probably
			// because of connectivity issue with APIServer.
			klog.Errorf("Failed to process updates for %s: %v", fs.configFilePath, err)
			return
		}
		klog.V(2).Infof("successfully updated K8s secret")
	})
	return nil
}