Skip to content

Commit

Permalink
refactor(checker): set kubeclient during initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Nov 14, 2024
1 parent aff0c7d commit 2191bc1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/local/preflight/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}

Expand Down

0 comments on commit 2191bc1

Please sign in to comment.