Skip to content

Commit

Permalink
Add ExtractDatabaseInfo Func for Cassandra
Browse files Browse the repository at this point in the history
Signed-off-by: Sabbir <[email protected]>
  • Loading branch information
sabbir-hossain70 committed Nov 20, 2024
1 parent 6a2e6b4 commit 9ce85c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 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)
}
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.bytebuilders.dev/audit v0.0.38 h1:4DEYVfBNeAfI9rctVWmpDOvEExh3gIuPsXVAg4Z3FWA=
go.bytebuilders.dev/audit v0.0.38/go.mod h1:6RC3gMMFpAzTzGJuJg8Ghgvebde4vvXkmDtUo11ypQw=
go.bytebuilders.dev/license-proxyserver v0.0.18 h1:Ii8B4yesaKWM7BTIEjsMONy7+gqnBXambMG5m2J1VbI=
go.bytebuilders.dev/license-proxyserver v0.0.18/go.mod h1:7Y8xJwxWuZXHlnETBE9JqMJrSdA+Vw+zTMZVurxSwrA=
go.bytebuilders.dev/license-proxyserver v0.0.18 h1:x6sbwvjYyYtL/eH3gNgOosxL5bpbg3utSr5N3lX+n1s=
go.bytebuilders.dev/license-proxyserver v0.0.18/go.mod h1:7wLFkvqfHwmB6MHcdTHB72M8+b63jApS59efrqZlY1E=
go.bytebuilders.dev/license-verifier v0.14.3 h1:5BTwmFEgCjSlAs2Nzh3/7+u//VoF93xjqywrJiqmZsg=
go.bytebuilders.dev/license-verifier v0.14.3/go.mod h1:bNNaVbry3TZbu54pf57LkhjsFX94T6O62w0roiy1yiE=
go.bytebuilders.dev/license-verifier/kubernetes v0.14.3 h1:PlzARW7Dt/t8WHtuNOxnB7GLhgdq30smRMAPRfyrhh8=
Expand Down
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 9ce85c2

Please sign in to comment.