Skip to content

Commit

Permalink
Extra logging
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed May 8, 2023
1 parent a757931 commit 4736aeb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/config/cfgvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -265,17 +269,22 @@ 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
},
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
}
Expand All @@ -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
}

0 comments on commit 4736aeb

Please sign in to comment.