From fcfbd979fc7d5afb8cad6f529bf8bed3a4c6c736 Mon Sep 17 00:00:00 2001 From: wangyelei Date: Mon, 2 Dec 2024 13:59:22 +0800 Subject: [PATCH] chore: opsDef support prefix match (#8559) (cherry picked from commit 7653688d40679c883ae7a4800fa1abcbff498c38) --- apis/operations/v1alpha1/opsdefinition_types.go | 12 ------------ pkg/operations/custom/utils.go | 14 +++++++++++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apis/operations/v1alpha1/opsdefinition_types.go b/apis/operations/v1alpha1/opsdefinition_types.go index 8854921e008..31d89fe0fdc 100644 --- a/apis/operations/v1alpha1/opsdefinition_types.go +++ b/apis/operations/v1alpha1/opsdefinition_types.go @@ -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 -} diff --git a/pkg/operations/custom/utils.go b/pkg/operations/custom/utils.go index 338f1e68e0a..978d3a7c6a6 100644 --- a/pkg/operations/custom/utils.go +++ b/pkg/operations/custom/utils.go @@ -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, @@ -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)) }