From 7bef54c089feefa37457d25e0883bc4daef4312c Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Mon, 20 Jul 2020 17:07:47 -0600 Subject: [PATCH] edgefs: error checking for ineffectual assignments All assignments made to errors or other variables should be used instead of ignored. This checks for errors in a couple places that were previously ignored, and also initializes a variable such that it won't be always overwritten by the various if else statements. Signed-off-by: Travis Nielsen --- pkg/operator/edgefs/cluster/prepare/prepare.go | 5 ++++- pkg/operator/edgefs/isgw/isgw.go | 2 +- pkg/operator/k8sutil/prometheus.go | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/operator/edgefs/cluster/prepare/prepare.go b/pkg/operator/edgefs/cluster/prepare/prepare.go index 41c55ee87..a572cb956 100644 --- a/pkg/operator/edgefs/cluster/prepare/prepare.go +++ b/pkg/operator/edgefs/cluster/prepare/prepare.go @@ -26,7 +26,7 @@ import ( "github.com/rook/rook/pkg/clusterd" "github.com/rook/rook/pkg/operator/k8sutil" batch "k8s.io/api/batch/v1" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -158,6 +158,9 @@ func (c *Cluster) waitJob(job *batch.Job) error { batchClient := c.context.Clientset.BatchV1() jobsClient := batchClient.Jobs(job.ObjectMeta.Namespace) watch, err := jobsClient.Watch(metav1.ListOptions{LabelSelector: "job-name=" + job.ObjectMeta.Name}) + if err != nil { + return fmt.Errorf("Failed to watch job %s", job.ObjectMeta.Name) + } k8sjob, err := jobsClient.Get(job.ObjectMeta.Name, metav1.GetOptions{}) if err != nil { diff --git a/pkg/operator/edgefs/isgw/isgw.go b/pkg/operator/edgefs/isgw/isgw.go index 45ae2cb54..1b067b1ef 100644 --- a/pkg/operator/edgefs/isgw/isgw.go +++ b/pkg/operator/edgefs/isgw/isgw.go @@ -281,7 +281,7 @@ func (c *ISGWController) isgwContainer(svcname, name, containerImage string, isg direction := getDirection(isgwSpec) - replication := 3 + var replication int if isgwSpec.ReplicationType == "initial" { replication = 1 } else if isgwSpec.ReplicationType == "continuous" { diff --git a/pkg/operator/k8sutil/prometheus.go b/pkg/operator/k8sutil/prometheus.go index 37f0c4a73..079d3a462 100644 --- a/pkg/operator/k8sutil/prometheus.go +++ b/pkg/operator/k8sutil/prometheus.go @@ -34,6 +34,9 @@ import ( func getMonitoringClient() (*monitoringclient.Clientset, error) { cfg, err := clientcmd.BuildConfigFromFlags("", "") + if err != nil { + return nil, fmt.Errorf("failed to build config. %v", err) + } client, err := monitoringclient.NewForConfig(cfg) if err != nil { return nil, fmt.Errorf("failed to get monitoring client. %v", err)