Skip to content

Commit

Permalink
sharding determine with topology and user specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie committed Dec 18, 2024
1 parent 0fd38ad commit 7cf567a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion controllers/apps/cluster_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ func (c *clusterTransformContext) sharding(name string) (bool, error) {
// sharding defined in cd topology
if len(c.Cluster.Spec.ClusterDef) > 0 && len(c.Cluster.Spec.Topology) > 0 {
if c.clusterDef == nil {
if err := loadNCheckClusterDefinition(c, c.Cluster); err != nil {
cd, err := loadClusterDefinition(c, c.Cluster)
if err != nil {
return false, err
}
c.clusterDef = cd
}
for _, topo := range c.clusterDef.Spec.Topologies {
if c.Cluster.Spec.Topology != topo.Name {
Expand Down
12 changes: 10 additions & 2 deletions controllers/apps/transformer_cluster_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,23 @@ func (t *clusterValidationTransformer) checkNUpdateClusterTopology(transCtx *clu
return nil
}

func loadNCheckClusterDefinition(transCtx *clusterTransformContext, cluster *appsv1.Cluster) error {
func loadClusterDefinition(transCtx *clusterTransformContext, cluster *appsv1.Cluster) (*appsv1.ClusterDefinition, error) {
var cd *appsv1.ClusterDefinition
if len(cluster.Spec.ClusterDef) > 0 {
cd = &appsv1.ClusterDefinition{}
key := types.NamespacedName{Name: cluster.Spec.ClusterDef}
if err := transCtx.Client.Get(transCtx.Context, key, cd); err != nil {
return err
return nil, err
}
}
return cd, nil
}

func loadNCheckClusterDefinition(transCtx *clusterTransformContext, cluster *appsv1.Cluster) error {
cd, err := loadClusterDefinition(transCtx, cluster)
if err != nil {
return err
}
if cd != nil {
if cd.Generation != cd.Status.ObservedGeneration {
return fmt.Errorf("the referenced ClusterDefinition is not up to date: %s", cd.Name)
Expand Down

0 comments on commit 7cf567a

Please sign in to comment.