Skip to content

Commit

Permalink
avoid printing errors to stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <bala@minio.io>
  • Loading branch information
balamurugana committed Sep 20, 2022
1 parent d9ff9e2 commit 5257429
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
19 changes: 6 additions & 13 deletions pkg/client/init.go
Expand Up @@ -17,14 +17,12 @@
package client

import (
"fmt"
"os"
"sync/atomic"

"github.com/fatih/color"
"github.com/minio/directpv/pkg/clientset"
"github.com/minio/directpv/pkg/k8s"
"github.com/minio/directpv/pkg/types"
"k8s.io/klog/v2"
)

// Init initializes various clients.
Expand All @@ -37,23 +35,18 @@ func Init() {

cs, err := clientset.NewForConfig(k8s.KubeConfig())
if err != nil {
fmt.Printf("%s: unable to create new clientset interface; %v\n", color.HiRedString("Error"), err)
os.Exit(1)
klog.Fatalf("unable to create new clientset interface; %v", err)
}
clientsetInterface = types.NewExtClientset(cs)

restClient = clientsetInterface.DirectpvLatest().RESTClient()

driveClient, err = latestDriveClientForConfig(k8s.KubeConfig())
if err != nil {
fmt.Printf("%s: unable to create new drive interface; %v\n", color.HiRedString("Error"), err)
os.Exit(1)
if driveClient, err = latestDriveClientForConfig(k8s.KubeConfig()); err != nil {
klog.Fatalf("unable to create new drive interface; %v", err)
}

volumeClient, err = latestVolumeClientForConfig(k8s.KubeConfig())
if err != nil {
fmt.Printf("%s: unable to create new volume interface; %v\n", color.HiRedString("Error"), err)
os.Exit(1)
if volumeClient, err = latestVolumeClientForConfig(k8s.KubeConfig()); err != nil {
klog.Fatalf("unable to create new volume interface; %v", err)
}

initEvent(k8s.KubeClient())
Expand Down
16 changes: 5 additions & 11 deletions pkg/k8s/init.go
Expand Up @@ -17,14 +17,12 @@
package k8s

import (
"fmt"
"os"
"sync/atomic"

"github.com/fatih/color"
apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"

// support gcp, azure, and oidc client auth
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
Expand All @@ -41,23 +39,19 @@ func Init() {
var err error

if kubeConfig, err = GetKubeConfig(); err != nil {
fmt.Printf("%s: unable to get kubernetes configuration\n", color.HiRedString("Error"))
os.Exit(1)
klog.Fatalf("unable to get kubernetes configuration; %v", err)
}

if kubeClient, err = kubernetes.NewForConfig(kubeConfig); err != nil {
fmt.Printf("%s: unable to create new kubernetes client interface; %v\n", color.HiRedString("Error"), err)
os.Exit(1)
klog.Fatalf("unable to create new kubernetes client interface; %v", err)
}

if apiextensionsClient, err = apiextensions.NewForConfig(kubeConfig); err != nil {
fmt.Printf("%s: unable to create new API extensions client interface; %v\n", color.HiRedString("Error"), err)
os.Exit(1)
klog.Fatalf("unable to create new API extensions client interface; %v", err)
}
crdClient = apiextensionsClient.CustomResourceDefinitions()

if discoveryClient, err = discovery.NewDiscoveryClientForConfig(kubeConfig); err != nil {
fmt.Printf("%s: unable to create new discovery client interface; %v\n", color.HiRedString("Error"), err)
os.Exit(1)
klog.Fatalf("unable to create new discovery client interface; %v", err)
}
}

0 comments on commit 5257429

Please sign in to comment.