func (m *SubclusterFinder) FindSubclusters(ctx context.Context, flags FindFlags) ([]*vapi.Subcluster, error) {
	subclusters := []*vapi.Subcluster{}
	if flags&FindInVdb != 0 {
		for i := range m.Vdb.Spec.Subclusters {
			subclusters = append(subclusters, &m.Vdb.Spec.Subclusters[i])
		}
	}
	if flags&FindNotInVdb != 0 || flags&FindExisting != 0 {
		missingSts, err := m.FindStatefulSets(ctx, FindNotInVdb)
		if err != nil {
			return nil, err
		}
		for i := range missingSts.Items {
			scName := missingSts.Items[i].Labels[SubclusterLabel]
			subclusters = append(subclusters, &vapi.Subcluster{Name: scName})
		}
	}
	return subclusters, nil
}
FindSubclusters will return a list of subclusters.
It accepts a flags field to indicate whether to return subclusters in the vdb,
not in the vdb or both.
package controllers
import (
	"context"
	"fmt"
	vapi "github.com/vertica/vertica-kubernetes/api/v1beta1"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/meta"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/apimachinery/pkg/runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
)
type SubclusterFinder struct {
	client.Client
	Vdb         *vapi.VerticaDB
	Subclusters map[string]*vapi.Subcluster
}
type FindFlags uint8
const (
	FindInVdb FindFlags = 1 << iota
	FindNotInVdb
	FindExisting
	FindAll = FindInVdb | FindNotInVdb
)
func MakeSubclusterFinder(cli client.Client, vdb *vapi.VerticaDB) SubclusterFinder {
	return SubclusterFinder{
		Client:      cli,
		Vdb:         vdb,
		Subclusters: vdb.GenSubclusterMap(),
	}
}
func (m *SubclusterFinder) FindStatefulSets(ctx context.Context, flags FindFlags) (*appsv1.StatefulSetList, error) {
	sts := &appsv1.StatefulSetList{}
	if err := m.buildObjList(ctx, sts, flags); err != nil {
		return nil, err
	}
	return sts, nil
}
func (m *SubclusterFinder) FindServices(ctx context.Context, flags FindFlags) (*corev1.ServiceList, error) {
	svcs := &corev1.ServiceList{}
	if err := m.buildObjList(ctx, svcs, flags); err != nil {
		return nil, err
	}
	return svcs, nil
}
func (m *SubclusterFinder) FindPods(ctx context.Context, flags FindFlags) (*corev1.PodList, error) {
	pods := &corev1.PodList{}
	if err := m.buildObjList(ctx, pods, flags); err != nil {
		return nil, err
	}
	return pods, nil
}