Skip to content

Commit

Permalink
Merge pull request #106 from subhamkrai/fix-dr-health
Browse files Browse the repository at this point in the history
dr: add log when dr is not configured
  • Loading branch information
subhamkrai authored May 22, 2023
2 parents 048417c + 927479b commit e3c85c2
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pkg/dr/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"encoding/json"
"fmt"

log "github.com/sirupsen/logrus"

"github.com/rook/kubectl-rook-ceph/pkg/exec"
"github.com/rook/kubectl-rook-ceph/pkg/k8sutil"
"github.com/rook/kubectl-rook-ceph/pkg/logging"
rookv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -20,22 +19,23 @@ type secretData struct {
}

func Health(context *k8sutil.Context, operatorNamespace, cephClusterNamespace string, args []string) {
fmt.Println("INFO: fetching the cephblockpools with mirroring enabled")
logging.Info("fetching the cephblockpools with mirroring enabled")
blockPoolList, err := context.RookClientset.CephV1().CephBlockPools(cephClusterNamespace).List(context.Context, v1.ListOptions{})
if err != nil {
log.Error(err)
logging.Fatal(err)
}

var mirrorBlockPool rookv1.CephBlockPool
for _, blockPool := range blockPoolList.Items {
if blockPool.Spec.Mirroring.Enabled && blockPool.Spec.Mirroring.Peers != nil {
mirrorBlockPool = blockPool
fmt.Printf("found %q cephblockpool with mirroring enabled\n", mirrorBlockPool.Name)
logging.Info("found %q cephblockpool with mirroring enabled", mirrorBlockPool.Name)
}
}

if mirrorBlockPool.Name == "" {
fmt.Printf("DR is not confiqured, cephblockpool with mirroring enabled not found.\n")
logging.Warning("DR is not confiqured, cephblockpool with mirroring enabled not found.")
return
}

var secretDetail string
Expand All @@ -48,11 +48,10 @@ func Health(context *k8sutil.Context, operatorNamespace, cephClusterNamespace st

secretData, err := extractSecretData(context, operatorNamespace, cephClusterNamespace, secretDetail)
if err != nil {
fmt.Printf("failed to extract secret %s", secretDetail)
log.Fatal(err)
logging.Fatal(fmt.Errorf("failed to extract secret %s", secretDetail))
}

fmt.Println("running ceph status from peer cluster")
logging.Info("running ceph status from peer cluster")

cephArgs := []string{"-s", "--mon-host", secretData.MonHost, "--id", secretData.ClientId, "--key", secretData.Key}

Expand All @@ -64,12 +63,12 @@ func Health(context *k8sutil.Context, operatorNamespace, cephClusterNamespace st

cephStatus := exec.RunCommandInOperatorPod(context, "ceph", cephArgs, operatorNamespace, cephClusterNamespace, false)
if cephStatus == "" {
fmt.Println("failed to get ceph status from peer cluster, please check for network issues between the clusters")
logging.Warning("failed to get ceph status from peer cluster, please check for network issues between the clusters")
return
}
fmt.Println(cephStatus)
logging.Info(cephStatus)

fmt.Println("running mirroring daemon health")
logging.Info("running mirroring daemon health")

fmt.Println(exec.RunCommandInOperatorPod(context, "rbd", []string{"-p", mirrorBlockPool.Name, "mirror", "pool", "status"}, cephClusterNamespace, operatorNamespace, true))
}
Expand Down

0 comments on commit e3c85c2

Please sign in to comment.