Skip to content

Commit

Permalink
Add ExtractDatabaseInfo Func for Cassandra (#1351)
Browse files Browse the repository at this point in the history
Signed-off-by: Sabbir <[email protected]>
  • Loading branch information
sabbir-hossain70 authored Nov 20, 2024
1 parent 6a2e6b4 commit 6ec7763
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apis/kubedb/v1alpha2/cassandra_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
11 changes: 11 additions & 0 deletions pkg/controller/petset/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down

0 comments on commit 6ec7763

Please sign in to comment.