@@ -27,6 +27,7 @@ import (
2727
2828 appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
2929 "github.com/apecloud/kubeblocks/pkg/common"
30+ "github.com/apecloud/kubeblocks/pkg/controller/component"
3031 jsonpatch "github.com/evanphx/json-patch"
3132 "github.com/spf13/cobra"
3233 "github.com/stoewer/go-strcase"
@@ -1038,7 +1039,7 @@ var customOpsExample = templates.Examples(`
10381039type CustomOperations struct {
10391040 * OperationsOptions
10401041 OpsDefinitionName string `json:"opsDefinitionName"`
1041- Params []opsv1alpha1.Parameter `json:"params"`
1042+ Params []opsv1alpha1.Parameter `json:"params,omitempty "`
10421043 SchemaProperties * apiextensionsv1.JSONSchemaProps
10431044}
10441045
@@ -1107,8 +1108,6 @@ func buildCustomOpsCmds(option *OperationsOptions) []*cobra.Command {
11071108 OperationsOptions : option ,
11081109 OpsDefinitionName : t .GetName (),
11091110 }
1110- // set options to build cue struct
1111- o .CreateOptions .Options = o
11121111 cmd := & cobra.Command {
11131112 Use : strcase .KebabCase (t .GetName ()) + " <ClusterName>" ,
11141113 Short : fmt .Sprintf ("Create a custom ops with opsDef %s" , t .GetName ()),
@@ -1120,6 +1119,7 @@ func buildCustomOpsCmds(option *OperationsOptions) []*cobra.Command {
11201119 cmdutil .CheckErr (o .Complete ())
11211120 cmdutil .CheckErr (o .validateAndCompleteComponentName ())
11221121 cmdutil .CheckErr (o .completeCustomSpec (cmd ))
1122+ o .CreateOptions .Options = o
11231123 cmdutil .CheckErr (o .Run ())
11241124 },
11251125 }
@@ -1175,24 +1175,28 @@ func (o *CustomOperations) validateAndCompleteComponentName() error {
11751175 return err
11761176 }
11771177 // check if the custom ops supports the component or complete the component for the cluster
1178- supportedComponentDefs := map [string ]struct {}{}
1179- for _ , v := range opsDef .Spec .ComponentInfos {
1180- supportedComponentDefs [v .ComponentDefinitionName ] = struct {}{}
1178+ supportedComponentDef := func (compDef string ) bool {
1179+ for _ , v := range opsDef .Spec .ComponentInfos {
1180+ if component .PrefixOrRegexMatched (compDef , v .ComponentDefinitionName ) {
1181+ return true
1182+ }
1183+ }
1184+ return false
11811185 }
1182- if len (supportedComponentDefs ) > 0 {
1186+
1187+ if len (opsDef .Spec .ComponentInfos ) > 0 {
11831188 // check if the ops supports the input component
11841189 var isSupported bool
11851190 for _ , v := range clusterObj .Spec .ComponentSpecs {
11861191 if v .ComponentDef == "" {
11871192 continue
11881193 }
1189- if _ , ok := supportedComponentDefs [v .ComponentDef ]; ok {
1194+ if supportedComponentDef (v .ComponentDef ) {
1195+ isSupported = true
11901196 if o .Component == "" {
11911197 o .Component = v .Name
1192- isSupported = true
11931198 break
11941199 } else if o .Component == v .Name {
1195- isSupported = true
11961200 break
11971201 }
11981202 }
0 commit comments