package slprober

import (
	"sync"
	"time"

	"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
)

func getClusterLabel(c *v1alpha1.TidbCluster, key string) string {
	if c == nil {
		return ""
	}
	if c.Labels == nil {
		return ""
	}
	v, ok := c.Labels[key]
	if !ok {
		return ""
	}
	return v
}

func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
	c := make(chan struct{})
	go func() {
		defer close(c)
		wg.Wait()
	}()
	select {
	case <-c:
		return false
	case <-time.After(timeout):
		return true
	}
}
