Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: opsDef support prefix match #8559

Merged
merged 1 commit into from
Dec 2, 2024
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
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