Add env var to allow spegel mirroring of latest tag

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
Brad Davidson 2024-02-29 22:46:16 +00:00 committed by Brad Davidson
parent 26feb25c40
commit 84a071a81e

View File

@ -54,6 +54,9 @@ var (
P2pAddressAnnotation = "p2p." + version.Program + ".cattle.io/node-address" P2pAddressAnnotation = "p2p." + version.Program + ".cattle.io/node-address"
P2pEnabledLabel = "p2p." + version.Program + ".cattle.io/enabled" P2pEnabledLabel = "p2p." + version.Program + ".cattle.io/enabled"
P2pPortEnv = version.ProgramUpper + "_P2P_PORT" P2pPortEnv = version.ProgramUpper + "_P2P_PORT"
P2pEnableLatestEnv = version.ProgramUpper + "_P2P_ENABLE_LATEST"
resolveLatestTag = false
) )
type authFunc func() authenticator.Request type authFunc func() authenticator.Request
@ -93,7 +96,6 @@ type Config struct {
// These values are not currently configurable // These values are not currently configurable
const ( const (
resolveLatestTag = false
resolveRetries = 0 resolveRetries = 0
resolveTimeout = time.Second * 5 resolveTimeout = time.Second * 5
registryNamespace = "k8s.io" registryNamespace = "k8s.io"
@ -171,11 +173,20 @@ func (c *Config) Start(ctx context.Context, nodeConfig *config.Node) error {
return errors.Wrap(err, "failed to create peerstore") return errors.Wrap(err, "failed to create peerstore")
} }
// get latest tag configuration override
if env := os.Getenv(P2pEnableLatestEnv); env != "" {
if b, err := strconv.ParseBool(env); err != nil {
logrus.Warnf("Invalid %s value; using default %v", P2pEnableLatestEnv, resolveLatestTag)
} else {
resolveLatestTag = b
}
}
// get port and start p2p router // get port and start p2p router
routerPort := defaultRouterPort routerPort := defaultRouterPort
if env := os.Getenv(P2pPortEnv); env != "" { if env := os.Getenv(P2pPortEnv); env != "" {
if i, err := strconv.Atoi(env); i == 0 || err != nil { if i, err := strconv.Atoi(env); i == 0 || err != nil {
logrus.Warnf("Invalid P2P node port; using default") logrus.Warnf("Invalid %s value; using default %v", P2pPortEnv, defaultRouterPort)
} else { } else {
routerPort = env routerPort = env
} }