func (r *Resources) fetchDeploymentHealth() error {
	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
	defer cancel()
	client, err := r.context.GetDatabaseClient(ctx)
	if err != nil {
		return errors.WithStack(err)
	}
	c, err := client.Cluster(ctx)
	if err != nil {
		return errors.WithStack(err)
	}
	h, err := c.Health(ctx)
	if err != nil {
		return errors.WithStack(err)
	}
	r.health.mutex.Lock()
	defer r.health.mutex.Unlock()
	r.health.clusterHealth = h
	r.health.timestamp = time.Now()
	return nil
}
fetchDeploymentHealth performs a single fetch of cluster-health
and stores it in-memory.
package resources
import (
	"context"
	"time"
	"github.com/arangodb/kube-arangodb/pkg/util/errors"
	driver "github.com/arangodb/go-driver"
	api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
	"github.com/arangodb/kube-arangodb/pkg/metrics"
)
var (
	deploymentHealthFetchesCounters = metrics.MustRegisterCounterVec(metricsComponent, "deployment_health_fetches", "Number of times the health of the deployment was fetched", metrics.DeploymentName, metrics.Result)
	deploymentSyncFetchesCounters   = metrics.MustRegisterCounterVec(metricsComponent, "deployment_sync_fetches", "Number of times the sync status of shards of the deplyoment was fetched", metrics.DeploymentName, metrics.Result)
)
func (r *Resources) RunDeploymentHealthLoop(stopCh <-chan struct{}) {
	log := r.log
	deploymentName := r.context.GetAPIObject().GetName()
	if r.context.GetSpec().GetMode() != api.DeploymentModeCluster {
		return
	}
	for {
		if err := r.fetchDeploymentHealth(); err != nil {
			log.Debug().Err(err).Msg("Failed to fetch deployment health")
			deploymentHealthFetchesCounters.WithLabelValues(deploymentName, metrics.Failed).Inc()
		} else {
			deploymentHealthFetchesCounters.WithLabelValues(deploymentName, metrics.Success).Inc()
		}
		select {
		case <-r.shardSync.triggerSyncInspection.Done():
		case <-time.After(time.Second * 5):
		case <-stopCh:
			return
		}
	}
}