From 2191bc14a2227544ea9d35daa188f398ce2ca06b Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Thu, 14 Nov 2024 10:16:30 +0800 Subject: [PATCH] refactor(checker): set kubeclient during initialization Signed-off-by: Chin-Ya Huang --- pkg/local/preflight/checker.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/local/preflight/checker.go b/pkg/local/preflight/checker.go index a2c55876..3d39ae28 100644 --- a/pkg/local/preflight/checker.go +++ b/pkg/local/preflight/checker.go @@ -53,6 +53,16 @@ type Checker struct { func (local *Checker) Init() error { local.collection.Log = &types.LogCollection{} + config, err := commonkube.GetInClusterConfig() + if err != nil { + return errors.Wrap(err, "failed to get client config") + } + + local.kubeClient, err = kubeclient.NewForConfig(config) + if err != nil { + return errors.Wrap(err, "failed to get Kubernetes clientset") + } + osRelease, err := utils.GetOSRelease() if err != nil { return errors.Wrap(err, "failed to get OS release") @@ -61,16 +71,6 @@ func (local *Checker) Init() error { local.logger = logrus.WithField("os", local.osRelease) if local.osRelease == fmt.Sprint(consts.OperatingSystemContainerOptimizedOS) { - config, err := commonkube.GetInClusterConfig() - if err != nil { - return errors.Wrap(err, "failed to get client config") - } - - local.kubeClient, err = kubeclient.NewForConfig(config) - if err != nil { - return errors.Wrap(err, "failed to get Kubernetes clientset") - } - return nil }