Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkg/cmd/cluster/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,29 @@ func (o *OperationsOptions) validatePromote(cluster *appsv1alpha1.Cluster) error
return nil
}

if cluster.Spec.ComponentSpecs[0].ComponentDef != "" {
return validateBaseOnCompDef(cluster.Spec.ComponentSpecs[0].ComponentDef)
resolveComponent := func(cluster *appsv1alpha1.Cluster, componentName string) *appsv1alpha1.ClusterComponentSpec {
componentSpec := cluster.Spec.GetComponentByName(componentName)
if componentSpec != nil {
return componentSpec
}
for i, spec := range cluster.Spec.ShardingSpecs {
if spec.Name == componentName {
return &cluster.Spec.ShardingSpecs[i].Template
}
}
return nil
}

if componentName == "" {
componentName = cluster.Spec.ComponentSpecs[0].Name
}
componentSpec := resolveComponent(cluster, componentName)
if componentSpec == nil {
return fmt.Errorf("component %s not found", componentName)
}

if componentSpec.ComponentDef != "" {
return validateBaseOnCompDef(componentSpec.ComponentDef)
} else {
return validateBaseOnClusterCompDef()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cluster/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ var _ = Describe("operations", func() {
o.Instance = ""
o.Component = testing.ComponentDefName
Expect(o.Validate()).ShouldNot(Succeed())
Expect(testing.ContainExpectStrings(o.Validate().Error(), "is invalid")).Should(BeTrue())
Expect(testing.ContainExpectStrings(o.Validate().Error(), "component fake-component-type not found")).Should(BeTrue())
})

It("Switchover ops base on component definition", func() {
Expand Down Expand Up @@ -405,7 +405,7 @@ var _ = Describe("operations", func() {
o.Component = testing.ComponentDefName
Expect(o.Validate()).ShouldNot(Succeed())
fmt.Println(o.Validate().Error())
Expect(testing.ContainExpectStrings(o.Validate().Error(), "is invalid")).Should(BeTrue())
Expect(testing.ContainExpectStrings(o.Validate().Error(), "component fake-component-type not found")).Should(BeTrue())
})

It("Custom ops base on component definition", func() {
Expand Down