From 4736aeba54981d2d7393c17e0776585f16f02358 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Mon, 8 May 2023 11:37:06 +0300 Subject: [PATCH] Extra logging Signed-off-by: Kimmo Lehto --- pkg/config/cfgvars.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/config/cfgvars.go b/pkg/config/cfgvars.go index 94add05fba22..6113f1b629cd 100644 --- a/pkg/config/cfgvars.go +++ b/pkg/config/cfgvars.go @@ -28,6 +28,7 @@ import ( "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" "github.com/k0sproject/k0s/pkg/constant" kubeutil "github.com/k0sproject/k0s/pkg/kubernetes" + "github.com/sirupsen/logrus" "github.com/avast/retry-go" "github.com/imdario/mergo" @@ -251,11 +252,14 @@ func (c *CfgVars) NodeConfig() (*v1beta1.ClusterConfig, error) { func (c *CfgVars) FetchDynamicConfig(ctx context.Context, kubeClientFactory kubeutil.ClientFactoryInterface) (*v1beta1.ClusterConfig, error) { if !c.EnableDynamicConfig { + logrus.Debug("Dynamic config is disabled, returning static config") return c.NodeConfig() } var apiConfig *v1beta1.ClusterConfig + logrus.Debug("Building config client to fetch dynamic config from API") + client, err := kubeClientFactory.GetConfigClient() if err != nil { return nil, err @@ -265,10 +269,12 @@ func (c *CfgVars) FetchDynamicConfig(ctx context.Context, kubeClientFactory kube func() (err error) { ctx, cancel := context.WithTimeout(ctx, 2*time.Second) defer cancel() + logrus.Debug("Trying to fetch dynamic config from API") c, err := client.Get(ctx, constant.ClusterConfigObjectName, metav1.GetOptions{}) if err != nil { return err } + logrus.Debug("Successfully fetched dynamic config from API") apiConfig = c.GetClusterWideConfig() return nil @@ -276,6 +282,9 @@ func (c *CfgVars) FetchDynamicConfig(ctx context.Context, kubeClientFactory kube retry.Context(ctx), retry.LastErrorOnly(true), retry.Delay(1*time.Second), + retry.OnRetry(func(attempt uint, err error) { + logrus.WithError(err).Debugf("Failed to get cluster config from API - attempt #%d", attempt+1) + }), ); err != nil { return nil, err } @@ -296,5 +305,6 @@ func (c *CfgVars) FetchDynamicConfig(ctx context.Context, kubeClientFactory kube return nil, fmt.Errorf("cluster config: merge nodeconfig: %w", err) } + logrus.Debug("Using dynamic config from API") return clusterConfig, nil }