ZROK_CTRL_CONFIG_VERSION override (#648)

This commit is contained in:
Michael Quigley 2024-06-12 13:21:45 -04:00
parent 53f5efb17c
commit 6f35c75203
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -1,6 +1,8 @@
package config
import (
"os"
"strconv"
"time"
"github.com/openziti/zrok/controller/emailUi"
@ -14,7 +16,7 @@ import (
"github.com/pkg/errors"
)
const ConfigVersion = 3
const ConfigVersion = 4
type Config struct {
V int
@ -119,8 +121,22 @@ func LoadConfig(path string) (*Config, error) {
if err := cf.BindYaml(cfg, path, env.GetCfOptions()); err != nil {
return nil, errors.Wrapf(err, "error loading controller config '%v'", path)
}
if cfg.V != ConfigVersion {
if !envVersionOk() && cfg.V != ConfigVersion {
return nil, errors.Errorf("expecting configuration version '%v', your configuration is version '%v'; please see zrok.io for changelog and configuration documentation", ConfigVersion, cfg.V)
}
return cfg, nil
}
func envVersionOk() bool {
vStr := os.Getenv("ZROK_CTRL_CONFIG_VERSION")
if vStr != "" {
envV, err := strconv.Atoi(vStr)
if err != nil {
return false
}
if envV == ConfigVersion {
return true
}
}
return false
}