From ce1b2d54c2a7af4023daf0eb3d2e26f378fa0dc0 Mon Sep 17 00:00:00 2001 From: Sabbir Date: Wed, 20 Nov 2024 13:48:06 +0600 Subject: [PATCH] Add ExtractDatabaseInfo Func for Cassandra Signed-off-by: Sabbir --- apis/kubedb/v1alpha2/cassandra_helpers.go | 11 +++++++++++ pkg/controller/petset/util.go | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/apis/kubedb/v1alpha2/cassandra_helpers.go b/apis/kubedb/v1alpha2/cassandra_helpers.go index 95e1e2418c..95f2e25d19 100644 --- a/apis/kubedb/v1alpha2/cassandra_helpers.go +++ b/apis/kubedb/v1alpha2/cassandra_helpers.go @@ -31,6 +31,7 @@ import ( "gomodules.xyz/pointer" core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" "kmodules.xyz/client-go/apiextensions" @@ -40,6 +41,7 @@ import ( appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1" mona "kmodules.xyz/monitoring-agent-api/api/v1" ofst "kmodules.xyz/offshoot-api/api/v2" + pslister "kubeops.dev/petset/client/listers/apps/v1" ) type CassandraApp struct { @@ -419,3 +421,12 @@ func (r *Cassandra) GetSeed() string { } return seed } + +func (c *Cassandra) ReplicasAreReady(lister pslister.PetSetLister) (bool, string, error) { + // Desire number of petSets + expectedItems := 1 + if c.Spec.Topology != nil { + expectedItems = len(c.Spec.Topology.Rack) + } + return checkReplicasOfPetSet(lister.PetSets(c.Namespace), labels.SelectorFromSet(c.OffshootLabels()), expectedItems) +} diff --git a/pkg/controller/petset/util.go b/pkg/controller/petset/util.go index 8a1519fa1c..3eeef41a93 100644 --- a/pkg/controller/petset/util.go +++ b/pkg/controller/petset/util.go @@ -64,6 +64,17 @@ func (c *Controller) extractDatabaseInfo(ps *petsetapps.PetSet) (*databaseInfo, } switch owner.Kind { + case olddbapi.ResourceKindCassandra: + dbInfo.opts.GVR.Resource = olddbapi.ResourcePluralCassandra + cas, err := c.DBClient.KubedbV1alpha2().Cassandras(dbInfo.opts.Namespace).Get(context.TODO(), dbInfo.opts.Name, metav1.GetOptions{}) + if err != nil { + return nil, err + } + dbInfo.replicasReady, dbInfo.msg, err = cas.ReplicasAreReady(c.PSLister) + if err != nil { + return nil, err + } + case olddbapi.ResourceKindClickHouse: dbInfo.opts.GVR.Resource = olddbapi.ResourcePluralClickHouse ch, err := c.DBClient.KubedbV1alpha2().ClickHouses(dbInfo.opts.Namespace).Get(context.TODO(), dbInfo.opts.Name, metav1.GetOptions{})