Skip to content

Commit

Permalink
fix error when fetch service workloads (koderover#2849)
Browse files Browse the repository at this point in the history
Signed-off-by: allenshen <[email protected]>
  • Loading branch information
AllenShen authored Jul 18, 2023
1 parent 951ed0c commit 7445136
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions pkg/microservice/aslan/core/environment/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,25 @@ func GetService(envName, productName, serviceName string, production bool, workL
return nil, e.ErrGetService.AddErr(err)
}

productSvc := env.GetServiceMap()[serviceName]
if productSvc == nil {
return nil, e.ErrGetService.AddErr(fmt.Errorf("failed to find service %s in product %s", serviceName, productName))
}
projectType := getProjectType(productName)
var serviceTmpl *commonmodels.Service
if projectType == setting.K8SDeployType {
productSvc := env.GetServiceMap()[serviceName]
if productSvc == nil {
return nil, e.ErrGetService.AddErr(fmt.Errorf("failed to find service %s in product %s", serviceName, productName))
}

serviceTmpl, err := repository.QueryTemplateService(&commonrepo.ServiceFindOption{
ServiceName: serviceName,
Revision: productSvc.Revision,
ProductName: productSvc.ProductName,
}, env.Production)
if err != nil {
return nil, e.ErrGetService.AddErr(fmt.Errorf("failed to find template service %s in product %s", serviceName, productName))
serviceTmpl, err = repository.QueryTemplateService(&commonrepo.ServiceFindOption{
ServiceName: serviceName,
Revision: productSvc.Revision,
ProductName: productSvc.ProductName,
}, env.Production)
if err != nil {
return nil, e.ErrGetService.AddErr(fmt.Errorf("failed to find template service %s in product %s", serviceName, productName))
}
}

ret, err = GetServiceImpl(serviceTmpl, workLoadType, env, clientset, inf, log)
ret, err = GetServiceImpl(serviceName, serviceTmpl, workLoadType, env, clientset, inf, log)
if err != nil {
return nil, e.ErrGetService.AddErr(err)
}
Expand Down Expand Up @@ -305,8 +309,8 @@ func GetServiceWorkloads(svcTmpl *commonmodels.Service, env *commonmodels.Produc
return ret, nil
}

func GetServiceImpl(serviceTmpl *commonmodels.Service, workLoadType string, env *commonmodels.Product, clientset *kubernetes.Clientset, inf informers.SharedInformerFactory, log *zap.SugaredLogger) (ret *SvcResp, err error) {
envName, productName, serviceName := env.EnvName, env.ProductName, serviceTmpl.ServiceName
func GetServiceImpl(serviceName string, serviceTmpl *commonmodels.Service, workLoadType string, env *commonmodels.Product, clientset *kubernetes.Clientset, inf informers.SharedInformerFactory, log *zap.SugaredLogger) (ret *SvcResp, err error) {
envName, productName := env.EnvName, env.ProductName
ret = &SvcResp{
ServiceName: serviceName,
EnvName: envName,
Expand Down Expand Up @@ -717,7 +721,7 @@ func queryPodsStatus(productInfo *commonmodels.Product, serviceTmpl *commonmodel
return resp
}

svcResp, err := GetServiceImpl(serviceTmpl, "", productInfo, clientset, informer, log)
svcResp, err := GetServiceImpl(serviceTmpl.ServiceName, serviceTmpl, "", productInfo, clientset, informer, log)
if err != nil {
return resp
}
Expand Down

0 comments on commit 7445136

Please sign in to comment.