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/go.sum b/go.sum index dd1ad0351b..1859417ded 100644 --- a/go.sum +++ b/go.sum @@ -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= 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{})