From b3761378c152527432735d29c4e39753905a72fa Mon Sep 17 00:00:00 2001 From: Sahil Raja Date: Thu, 6 May 2021 07:45:54 +0530 Subject: [PATCH] (bugbash) Fix G104 gosec warnings (#570) Signed-off-by: Sahil Raja --- cmd/manager/main.go | 6 +++++- cmd/ndm_daemonset/controller/controller.go | 5 ++++- cmd/ndm_daemonset/controller/sparsefilegenerator.go | 5 ++++- cmd/ndm_daemonset/grpc/api.go | 5 ++++- cmd/ndm_daemonset/probe/udevprobe.go | 5 ++++- pkg/logs/logs.go | 5 ++++- pkg/smart/satadevice.go | 5 ++++- pkg/smart/scsiinquirypage.go | 5 ++++- 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 0f6cdaa3d..3b1a8b977 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -87,7 +87,11 @@ func main() { } // Become the leader before proceeding - leader.Become(context.TODO(), "node-disk-manager-lock") + err = leader.Become(context.TODO(), "node-disk-manager-lock") + if err != nil { + klog.Errorf("Failed to become leader, Error: %v", err) + os.Exit(1) + } r := ready.NewFileReady() err = r.Set() diff --git a/cmd/ndm_daemonset/controller/controller.go b/cmd/ndm_daemonset/controller/controller.go index 9837ea77e..841fbcd4b 100644 --- a/cmd/ndm_daemonset/controller/controller.go +++ b/cmd/ndm_daemonset/controller/controller.go @@ -243,7 +243,10 @@ func (c *Controller) WaitForBlockDeviceCRD() { if err != nil { klog.Errorf("BlockDevice CRD is not available yet. Retrying after %v, error: %v", CRDRetryInterval, err) time.Sleep(CRDRetryInterval) - c.newClientSet() + _, err := c.newClientSet() + if err != nil { + klog.Errorf("unable to set clientset field in controller struct, Error: %v",err) + } continue } klog.Info("BlockDevice CRD is available") diff --git a/cmd/ndm_daemonset/controller/sparsefilegenerator.go b/cmd/ndm_daemonset/controller/sparsefilegenerator.go index bdccac497..e985d395a 100644 --- a/cmd/ndm_daemonset/controller/sparsefilegenerator.go +++ b/cmd/ndm_daemonset/controller/sparsefilegenerator.go @@ -220,5 +220,8 @@ func (c *Controller) MarkSparseBlockDeviceStateActive(sparseFile string, sparseF //If a BlockDevice CR already exits, update it. If not create a new one. klog.Info("Updating the BlockDevice CR for Sparse file: ", BlockDeviceDetails.UUID) - c.CreateBlockDevice(BlockDeviceDetails.ToDevice()) + err = c.CreateBlockDevice(BlockDeviceDetails.ToDevice()) + if err != nil { + klog.Error("Failed to create a block device resource in etcd, Error: ", err) + } } diff --git a/cmd/ndm_daemonset/grpc/api.go b/cmd/ndm_daemonset/grpc/api.go index 7fe7c3c34..517368a93 100644 --- a/cmd/ndm_daemonset/grpc/api.go +++ b/cmd/ndm_daemonset/grpc/api.go @@ -68,7 +68,10 @@ func Start() { // Listen for requests klog.Infof("Starting server at : %v ", Address) - grpcServer.Serve(l) + err = grpcServer.Serve(l) + if err != nil { + klog.Errorf("Unable to Serve %v", err) + } } } diff --git a/cmd/ndm_daemonset/probe/udevprobe.go b/cmd/ndm_daemonset/probe/udevprobe.go index dddcd88ee..cd760d02a 100644 --- a/cmd/ndm_daemonset/probe/udevprobe.go +++ b/cmd/ndm_daemonset/probe/udevprobe.go @@ -120,7 +120,10 @@ func (up *udevProbe) Start() { go up.listen() go udevevent.Monitor() probeEvent := newUdevProbe(up.controller) - probeEvent.scan() + err := probeEvent.scan() + if err != nil { + klog.Errorf("error while scanning system for block devices, Error: %v", err) + } } // Rescan syncs etcd and NDM diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go index 4fdd4377d..ce5ac6176 100644 --- a/pkg/logs/logs.go +++ b/pkg/logs/logs.go @@ -30,7 +30,10 @@ var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum // TODO(thockin): This is temporary until we agree on log dirs and put those into each cmd. func init() { - flag.Set("logtostderr", "true") + err := flag.Set("logtostderr", "true") + if err != nil { + klog.Errorf("unable to set flag, Error: %v",err) + } } // KlogWriter serves as a bridge between the standard log package and the klog package. diff --git a/pkg/smart/satadevice.go b/pkg/smart/satadevice.go index 38e9cea47..a13db8459 100644 --- a/pkg/smart/satadevice.go +++ b/pkg/smart/satadevice.go @@ -47,7 +47,10 @@ func (d *SATA) ataIdentify() (ATACSPage, error) { if err := d.sendSCSICDB(cdb16[:], &responseBuf); err != nil { return identifyBuf, fmt.Errorf("error in sending SCSICDB 16 for ATA device, Error: %+v", err) } - binary.Read(bytes.NewBuffer(responseBuf), NativeEndian, &identifyBuf) + err := binary.Read(bytes.NewBuffer(responseBuf), NativeEndian, &identifyBuf) + if err != nil { + return identifyBuf, fmt.Errorf("error in reading data, Error: %+v", err) + } return identifyBuf, nil } diff --git a/pkg/smart/scsiinquirypage.go b/pkg/smart/scsiinquirypage.go index 29b440662..143047ec3 100644 --- a/pkg/smart/scsiinquirypage.go +++ b/pkg/smart/scsiinquirypage.go @@ -48,7 +48,10 @@ func (d *SCSIDev) scsiInquiry() (InquiryResponse, error) { return response, err } - binary.Read(bytes.NewBuffer(respBuf), NativeEndian, &response) + err := binary.Read(bytes.NewBuffer(respBuf), NativeEndian, &response) + if err != nil { + return response, fmt.Errorf("error in reading data, Error: %+v", err) + } return response, nil }