diff --git a/pkg/k8s/util.go b/pkg/k8s/util.go index 7b01a8c1..9c3ec13c 100644 --- a/pkg/k8s/util.go +++ b/pkg/k8s/util.go @@ -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 { @@ -78,8 +73,7 @@ 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 } @@ -87,13 +81,11 @@ func GetKubeConfig(kubeConfigPath ...string) (*rest.Config, error) { 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 }