File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -605,8 +605,29 @@ func (o *OperationsOptions) validatePromote(cluster *appsv1alpha1.Cluster) error
605605 return nil
606606 }
607607
608- if cluster .Spec .ComponentSpecs [0 ].ComponentDef != "" {
609- return validateBaseOnCompDef (cluster .Spec .ComponentSpecs [0 ].ComponentDef )
608+ resolveComponent := func (cluster * appsv1alpha1.Cluster , componentName string ) * appsv1alpha1.ClusterComponentSpec {
609+ componentSpec := cluster .Spec .GetComponentByName (componentName )
610+ if componentSpec != nil {
611+ return componentSpec
612+ }
613+ for i , spec := range cluster .Spec .ShardingSpecs {
614+ if spec .Name == componentName {
615+ return & cluster .Spec .ShardingSpecs [i ].Template
616+ }
617+ }
618+ return nil
619+ }
620+
621+ if componentName == "" {
622+ componentName = cluster .Spec .ComponentSpecs [0 ].Name
623+ }
624+ componentSpec := resolveComponent (cluster , componentName )
625+ if componentSpec == nil {
626+ return fmt .Errorf ("component %s not found" , componentName )
627+ }
628+
629+ if componentSpec .ComponentDef != "" {
630+ return validateBaseOnCompDef (componentSpec .ComponentDef )
610631 } else {
611632 return validateBaseOnClusterCompDef ()
612633 }
Original file line number Diff line number Diff line change @@ -362,7 +362,7 @@ var _ = Describe("operations", func() {
362362 o .Instance = ""
363363 o .Component = testing .ComponentDefName
364364 Expect (o .Validate ()).ShouldNot (Succeed ())
365- Expect (testing .ContainExpectStrings (o .Validate ().Error (), "is invalid " )).Should (BeTrue ())
365+ Expect (testing .ContainExpectStrings (o .Validate ().Error (), "component fake-component-type not found " )).Should (BeTrue ())
366366 })
367367
368368 It ("Switchover ops base on component definition" , func () {
@@ -405,7 +405,7 @@ var _ = Describe("operations", func() {
405405 o .Component = testing .ComponentDefName
406406 Expect (o .Validate ()).ShouldNot (Succeed ())
407407 fmt .Println (o .Validate ().Error ())
408- Expect (testing .ContainExpectStrings (o .Validate ().Error (), "is invalid " )).Should (BeTrue ())
408+ Expect (testing .ContainExpectStrings (o .Validate ().Error (), "component fake-component-type not found " )).Should (BeTrue ())
409409 })
410410
411411 It ("Custom ops base on component definition" , func () {
You can’t perform that action at this time.
0 commit comments