Skip to content

Commit

Permalink
Merge pull request #3654 from PetrusZ/fix/helm_svc_gone
Browse files Browse the repository at this point in the history
fix update helm services cause all service disappear
  • Loading branch information
jamsman94 authored Aug 20, 2024
2 parents 0011561 + a337594 commit 1a49c97
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/microservice/aslan/core/common/service/kube/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
templatemodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models/template"
commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb/template"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/notify"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/repository"
commonutil "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/util"
Expand Down Expand Up @@ -366,12 +367,31 @@ func UpgradeHelmRelease(product *commonmodels.Product, productSvc *commonmodels.
}
}

newProductInfo.Services = [][]*commonmodels.ProductService{{}}
for _, service := range productSvcMap {
newProductInfo.Services[0] = append(newProductInfo.Services[0], service)
templateProduct, err := template.NewProductCollWithSess(session).Find(product.ProductName)
if err != nil {
mongo.AbortTransaction(session)
return errors.Wrapf(err, "failed to find template product %s", product.ProductName)
}

newProductInfo.Services = [][]*commonmodels.ProductService{}
serviceOrchestration := templateProduct.Services
if product.Production {
serviceOrchestration = templateProduct.ProductionServices
}

for i, svcGroup := range serviceOrchestration {
if len(newProductInfo.Services) >= i {
newProductInfo.Services = append(newProductInfo.Services, []*commonmodels.ProductService{})
}

for _, svc := range svcGroup {
if productSvcMap[svc] != nil {
newProductInfo.Services[i] = append(newProductInfo.Services[i], productSvcMap[svc])
}
}
}
for _, service := range productChartSvcMap {
newProductInfo.Services[0] = append(newProductInfo.Services[0], service)
newProductInfo.Services[len(newProductInfo.Services)-1] = append(newProductInfo.Services[len(newProductInfo.Services)-1], service)
}

if productSvc.DeployStrategy == setting.ServiceDeployStrategyDeploy {
Expand Down
34 changes: 34 additions & 0 deletions pkg/microservice/aslan/core/delivery/service/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,40 @@ func CreateNewHelmDeliveryVersion(args *CreateHelmDeliveryVersionArgs, logger *z
return e.ErrCreateDeliveryVersion.AddErr(err)
}

registryMap, err := buildRegistryMap()
if err != nil {
return fmt.Errorf("failed to build registry map")
}

var targetRegistry *commonmodels.RegistryNamespace
if len(args.ImageRegistryID) != 0 {
for _, registry := range registryMap {
if registry.ID.Hex() == args.ImageRegistryID {
targetRegistry = registry
break
}
}
targetRegistryProjectSet := sets.NewString()
for _, project := range targetRegistry.Projects {
targetRegistryProjectSet.Insert(project)
}
if !targetRegistryProjectSet.Has(productInfo.ProductName) && !targetRegistryProjectSet.Has(setting.AllProjects) {
return fmt.Errorf("registry %s/%s not support project %s", targetRegistry.RegAddr, targetRegistry.Namespace, productInfo.ProductName)
}
}

for _, chartData := range args.ChartDatas {
for _, imageData := range chartData.ImageData {
if !imageData.Selected {
continue
}
_, err := getImageSourceRegistry(imageData, registryMap)
if err != nil {
return fmt.Errorf("failed to check registry, err: %v", err)
}
}
}

productInfo.ID, _ = primitive.ObjectIDFromHex("")

workflowName := generateDeliveryWorkflowName(args.ProductName)
Expand Down
2 changes: 2 additions & 0 deletions pkg/microservice/aslan/core/environment/service/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func getReleaseStatus(re *release.Release) ReleaseStatus {
}

type ImageData struct {
Image string `json:"image"`
ImageName string `json:"imageName"`
ImageTag string `json:"imageTag"`
Selected bool `json:"selected"`
Expand Down Expand Up @@ -585,6 +586,7 @@ func GetImageInfos(productName, envName, serviceNames string, production bool, l
}

svcImage.Images = append(svcImage.Images, &ImageData{
imageUrl,
util.GetImageNameFromContainerInfo(container.ImageName, container.Name),
commonservice.ExtractImageTag(imageUrl),
containerNameSet.Has(container.ImageName),
Expand Down

0 comments on commit 1a49c97

Please sign in to comment.