From d78631841e6311d86f95b7fd9c9dc8d6a3686593 Mon Sep 17 00:00:00 2001 From: rohan47 Date: Tue, 9 Jul 2019 11:25:26 +0530 Subject: [PATCH] Updated condition check to avoid operator crash Empty deployment list made the operator to crash as the condition check was checking if the value at the 0th location is nill wich fails in case of empty list. Updated it to check length of list not equals 0. Signed-off-by: rohan47 --- pkg/operator/ceph/cluster/osd/health.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/operator/ceph/cluster/osd/health.go b/pkg/operator/ceph/cluster/osd/health.go index 21da55d02..edf7652a5 100644 --- a/pkg/operator/ceph/cluster/osd/health.go +++ b/pkg/operator/ceph/cluster/osd/health.go @@ -23,6 +23,7 @@ import ( "github.com/rook/rook/pkg/clusterd" "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/pkg/operator/k8sutil" + "k8s.io/apimachinery/pkg/api/errors" ) const ( @@ -113,9 +114,14 @@ func (m *Monitor) handleOSDMarkedOut(outOSDid int) error { if safeToDestroyOSD { logger.Infof("osd.%d is 'safe-to-destroy'", outOSDid) label := fmt.Sprintf("ceph-osd-id=%d", outOSDid) - dp, _ := k8sutil.GetDeployments(m.context.Clientset, m.clusterName, label) - - if dp.Items != nil { + dp, err := k8sutil.GetDeployments(m.context.Clientset, m.clusterName, label) + if err != nil { + if errors.IsNotFound(err) { + return nil + } + return fmt.Errorf("failed to get osd deployment of osd id %d: %+v", outOSDid, err) + } + if len(dp.Items) != 0 { if err := k8sutil.DeleteDeployment(m.context.Clientset, dp.Items[0].Namespace, dp.Items[0].Name); err != nil { return fmt.Errorf("failed to delete osd deployment %s: %+v", dp.Items[0].Name, err) }