Skip to content

Commit

Permalink
Remove from the util go file the setupLog and replace it with fmt.Err…
Browse files Browse the repository at this point in the history
…orf()

Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Nov 21, 2024
1 parent c355ba1 commit 8158551
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pkg/k8s/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ package k8s

import (
"embed"
"fmt"
"github.com/cnoe-io/idpbuilder/pkg/util"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"os"
"path/filepath"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/cnoe-io/idpbuilder/pkg/util"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
setupLog = ctrl.Log.WithName("k8s")
)

func BuildCustomizedManifests(filePath, fsPath string, resourceFS embed.FS, scheme *runtime.Scheme, templateData any) ([][]byte, error) {
rawResources, err := util.ConvertFSToBytes(resourceFS, fsPath, templateData)
if err != nil {
Expand Down Expand Up @@ -78,22 +73,19 @@ func GetKubeConfig(kubeConfigPath ...string) (*rest.Config, error) {

kubeConfig, err := clientcmd.BuildConfigFromFlags("", path)
if err != nil {
setupLog.Error(err, "Error building kubeconfig from kind cluster")
return nil, err
return nil, fmt.Errorf("Error building kubeconfig from kind cluster: %w", err)
}
return kubeConfig, nil
}

func GetKubeClient(kubeConfigPath ...string) (client.Client, error) {
kubeCfg, err := GetKubeConfig(kubeConfigPath...)
if err != nil {
setupLog.Error(err, "Error getting kubeconfig")
return nil, err
return nil, fmt.Errorf("Error getting kubeconfig: %w", err)
}
kubeClient, err := client.New(kubeCfg, client.Options{Scheme: GetScheme()})
if err != nil {
setupLog.Error(err, "Error creating kubernetes client")
return nil, err
return nil, fmt.Errorf("Error creating kubernetes client: %w", err)
}
return kubeClient, nil
}

0 comments on commit 8158551

Please sign in to comment.