From 84a071a81e5f2ade3f1c1c73ef681c7cfc942742 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Thu, 29 Feb 2024 22:46:16 +0000 Subject: [PATCH] Add env var to allow spegel mirroring of `latest` tag Signed-off-by: Brad Davidson --- pkg/spegel/spegel.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/spegel/spegel.go b/pkg/spegel/spegel.go index acbd65c71d..a138d10eea 100644 --- a/pkg/spegel/spegel.go +++ b/pkg/spegel/spegel.go @@ -54,6 +54,9 @@ var ( P2pAddressAnnotation = "p2p." + version.Program + ".cattle.io/node-address" P2pEnabledLabel = "p2p." + version.Program + ".cattle.io/enabled" P2pPortEnv = version.ProgramUpper + "_P2P_PORT" + P2pEnableLatestEnv = version.ProgramUpper + "_P2P_ENABLE_LATEST" + + resolveLatestTag = false ) type authFunc func() authenticator.Request @@ -93,7 +96,6 @@ type Config struct { // These values are not currently configurable const ( - resolveLatestTag = false resolveRetries = 0 resolveTimeout = time.Second * 5 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") } + // 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 routerPort := defaultRouterPort if env := os.Getenv(P2pPortEnv); env != "" { 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 { routerPort = env }