Skip to content

Commit

Permalink
fix error when deploying images only (koderover#2645)
Browse files Browse the repository at this point in the history
Signed-off-by: allenshen <[email protected]>
  • Loading branch information
AllenShen authored May 22, 2023
1 parent abdc0c6 commit 4f9e2aa
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions pkg/microservice/aslan/core/common/service/kube/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,6 @@ func FetchCurrentAppliedYaml(option *GeneSvcYamlOption) (string, int, error) {
prodSvcTemplate.ServiceVars = setting.ServiceVarWildCard
}

// for situations only updating workload images, only return involved manifests of deployments and statefulsets
if !option.UnInstall && !option.UpdateServiceRevision && len(option.VariableYaml) == 0 {
manifest, _, err := fetchImportedManifests(option, productInfo, prodSvcTemplate)
return manifest, int(curProductSvc.Revision), err
}

// service not deployed by zadig, should only be updated with images
if !option.UnInstall && !commonutil.ServiceDeployed(option.ServiceName, productInfo.ServiceDeployStrategy) {
manifest, _, err := fetchImportedManifests(option, productInfo, prodSvcTemplate)
return manifest, int(curProductSvc.Revision), err
}

var usedRenderset *commonmodels.RenderSet
usedRenderset, err = commonrepo.NewRenderSetColl().Find(&commonrepo.RenderSetFindOption{
ProductTmpl: productInfo.ProductName,
Expand All @@ -367,6 +355,17 @@ func FetchCurrentAppliedYaml(option *GeneSvcYamlOption) (string, int, error) {
return "", 0, errors.Wrapf(err, "failed to find renderset for %s/%s", productInfo.ProductName, productInfo.EnvName)
}

// for situations only updating workload images, only return involved manifests of deployments and statefulsets
if !option.UnInstall && !option.UpdateServiceRevision && len(option.VariableYaml) == 0 {
manifest, _, err := fetchImportedManifests(option, productInfo, prodSvcTemplate, usedRenderset)
return manifest, int(curProductSvc.Revision), err
}

// service not deployed by zadig, should only be updated with images
if !option.UnInstall && !commonutil.ServiceDeployed(option.ServiceName, productInfo.ServiceDeployStrategy) {
manifest, _, err := fetchImportedManifests(option, productInfo, prodSvcTemplate, usedRenderset)
return manifest, int(curProductSvc.Revision), err
}
// @note get render for deploy job
log.Debugf("used renderset: %+v", usedRenderset)

Expand All @@ -380,9 +379,9 @@ func FetchCurrentAppliedYaml(option *GeneSvcYamlOption) (string, int, error) {
return fullRenderedYaml, 0, nil
}

func fetchImportedManifests(option *GeneSvcYamlOption, productInfo *models.Product, serviceTmp *models.Service) (string, []*WorkloadResource, error) {
fakeRenderSet := &models.RenderSet{}
fullRenderedYaml, err := RenderServiceYaml(serviceTmp.Yaml, option.ProductName, option.ServiceName, fakeRenderSet)
func fetchImportedManifests(option *GeneSvcYamlOption, productInfo *models.Product, serviceTmp *models.Service, renderset *commonmodels.RenderSet) (string, []*WorkloadResource, error) {
//fakeRenderSet := &models.RenderSet{}
fullRenderedYaml, err := RenderServiceYaml(serviceTmp.Yaml, option.ProductName, option.ServiceName, renderset)
if err != nil {
return "", nil, err
}
Expand Down Expand Up @@ -500,17 +499,6 @@ func GenerateRenderedYaml(option *GeneSvcYamlOption) (string, int, []*WorkloadRe
return "", 0, nil, fmt.Errorf("failed to find service template for service %s, isProduction %v", option.ServiceName, productInfo.Production)
}

// service not deployed by zadig, should only be updated with images
if !option.UnInstall && !option.UpdateServiceRevision && variableYamlNil(option.VariableYaml) && curProductSvc != nil && !commonutil.ServiceDeployed(option.ServiceName, productInfo.ServiceDeployStrategy) {
manifest, workloads, err := fetchImportedManifests(option, productInfo, prodSvcTemplate)
return manifest, int(curProductSvc.Revision), workloads, err
}

curContainers := latestSvcTemplate.Containers
if curProductSvc != nil {
curContainers = curProductSvc.Containers
}

usedRenderset, err := commonrepo.NewRenderSetColl().Find(&commonrepo.RenderSetFindOption{
ProductTmpl: productInfo.ProductName,
EnvName: productInfo.EnvName,
Expand All @@ -521,6 +509,18 @@ func GenerateRenderedYaml(option *GeneSvcYamlOption) (string, int, []*WorkloadRe
if err != nil {
return "", 0, nil, errors.Wrapf(err, "failed to find renderset for %s/%s", productInfo.ProductName, productInfo.EnvName)
}

// service not deployed by zadig, should only be updated with images
if !option.UnInstall && !option.UpdateServiceRevision && variableYamlNil(option.VariableYaml) && curProductSvc != nil && !commonutil.ServiceDeployed(option.ServiceName, productInfo.ServiceDeployStrategy) {
manifest, workloads, err := fetchImportedManifests(option, productInfo, prodSvcTemplate, usedRenderset)
return manifest, int(curProductSvc.Revision), workloads, err
}

curContainers := latestSvcTemplate.Containers
if curProductSvc != nil {
curContainers = curProductSvc.Containers
}

serviceVariableYaml := ""
serviceRender := usedRenderset.GetServiceRenderMap()[option.ServiceName]
if serviceRender != nil && serviceRender.OverrideYaml != nil {
Expand Down

0 comments on commit 4f9e2aa

Please sign in to comment.