Skip to content

Commit

Permalink
chore: opsDef support prefix match (#8559)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7653688)
  • Loading branch information
wangyelei committed Dec 2, 2024
1 parent d7e06e5 commit fcfbd97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 0 additions & 12 deletions apis/operations/v1alpha1/opsdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,3 @@ type OpsDefinitionList struct {
func init() {
SchemeBuilder.Register(&OpsDefinition{}, &OpsDefinitionList{})
}

func (o *OpsDefinition) GetComponentInfo(compDefName string) *ComponentInfo {
if o == nil {
return nil
}
for _, v := range o.Spec.ComponentInfos {
if compDefName == v.ComponentDefinitionName {
return &v
}
}
return nil
}
14 changes: 13 additions & 1 deletion pkg/operations/custom/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ const (
kbEnvAccountPassword = "KB_ACCOUNT_PASSWORD"
)

func getComponentInfo(opsDef *opsv1alpha1.OpsDefinition, compDefName string) *opsv1alpha1.ComponentInfo {
if opsDef == nil {
return nil
}
for _, v := range opsDef.Spec.ComponentInfos {
if component.PrefixOrRegexMatched(compDefName, v.ComponentDefinitionName) {
return &v
}
}
return nil
}

// buildComponentDefEnvs builds the env vars by the opsDefinition.spec.componentDefinitionRef
func buildComponentEnvs(reqCtx intctrlutil.RequestCtx,
cli client.Client,
Expand All @@ -78,7 +90,7 @@ func buildComponentEnvs(reqCtx intctrlutil.RequestCtx,
if err != nil {
return err
}
componentInfo := opsDef.GetComponentInfo(compDef.Name)
componentInfo := getComponentInfo(opsDef, compDef.Name)
if componentInfo == nil {
return intctrlutil.NewFatalError(fmt.Sprintf(`componentDefinition "%s" is not support for this operations`, compDef.Name))
}
Expand Down

0 comments on commit fcfbd97

Please sign in to comment.