func findImageByContainerName(flatMap map[string]interface{}, matchedPath []map[string]string, container *models.Container) error {
	for _, searchResult := range matchedPath {
		imageURI, err := commonservice.GeneImageURI(searchResult, flatMap)
		if err != nil {
			log.Error("GeneImageURI fail, err %s", err.Error())
			continue
		}
		if container.Name != commonservice.ExtractImageName(imageURI) {
			continue
		}
		container.ImagePath = &models.ImagePathSpec{
			Repo:  searchResult[setting.PathSearchComponentRepo],
			Image: searchResult[setting.PathSearchComponentImage],
			Tag:   searchResult[setting.PathSearchComponentTag],
		}
		return nil
	}
	return fmt.Errorf("faild to find image for contianer %s", container.Image)
}
find match rule
package migrate
import (
	"fmt"
	"github.com/koderover/zadig/pkg/cli/upgradeassistant/internal/upgradepath"
	"github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/models"
	commonmodels "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/models"
	"github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/mongodb"
	commonrepo "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/mongodb"
	commonservice "github.com/koderover/zadig/pkg/microservice/aslan/core/common/service"
	"github.com/koderover/zadig/pkg/setting"
	"github.com/koderover/zadig/pkg/tool/log"
	"github.com/koderover/zadig/pkg/util/converter"
)
func init() {
	upgradepath.AddHandler(upgradepath.V140, upgradepath.V150, V140ToV150)
	upgradepath.AddHandler(upgradepath.V150, upgradepath.V140, V150ToV140)
}
func V140ToV150() error {
	log.Info("Migrating data from 1.4.0 to 1.5.0")
	products, err := mongodb.NewProductColl().List(&mongodb.ProductListOptions{
		ExcludeStatus: setting.ProductStatusDeleting,
		Source:        setting.SourceFromHelm,
	})
	if err != nil {
		return err
	}
	for _, product := range products {
		renderSetName := product.Namespace
		renderSetOpt := &commonrepo.RenderSetFindOption{Name: renderSetName, Revision: product.Render.Revision}
		renderSet, err := commonrepo.NewRenderSetColl().Find(renderSetOpt)
		if err != nil {
			log.Errorf("find helm renderset[%s] error: %v", renderSetName, err)
			continue
		}
		product.ChartInfos = renderSet.ChartInfos
		err = fillImageParseInfo(product)
		if err != nil {
			log.Error("failed to fill image parse info for product %s, err %s", product.ProductName, err.Error())
			continue
		}
	}
	return nil
}
func V150ToV140() error {
	log.Info("Rollback data from 1.5.0 to 1.4.0")
	return nil
}
func missContainerImagePath(container *commonmodels.Container) bool {
	if container.ImagePath == nil {
		return true
	}
	return container.ImagePath.Repo == "" && container.ImagePath.Image == "" && container.ImagePath.Tag == ""
}
func fillImageParseInfo(prod *commonmodels.Product) error {
	rendersetMap := make(map[string]string)
	for _, singleData := range prod.ChartInfos {
		rendersetMap[singleData.ServiceName] = singleData.ValuesYaml
	}
	fillHappen := false
	serviceMap := prod.GetServiceMap()
	for _, singleService := range serviceMap {
		findEmptySpec := false
		for _, container := range singleService.Containers {
			if missContainerImagePath(container) {
				findEmptySpec = true
				break
			}
		}
		if !findEmptySpec {
			continue
		}
		flatMap, err := converter.YamlToFlatMap([]byte(rendersetMap[singleService.ServiceName]))
		if err != nil {
			log.Errorf("get flat map fail for service: %s.%s, err %s", prod.ProductName, singleService.ServiceName, err.Error())
			continue
		}
		matchedPath, err := commonservice.ParseImagesByPresetRules(flatMap)
		if err != nil {
			log.Errorf("failed to parse images from service:%s.%s in product:%s", prod.ProductName, singleService.ServiceName, singleService.ProductName)
			continue
		}
		for _, container := range singleService.Containers {
			if !missContainerImagePath(container) {
				continue
			}
			err = findImageByContainerName(flatMap, matchedPath, container)
			if err != nil {
				log.Errorf("failed to find image pathL %s.%s, err: %s", prod.ProductName, singleService.ServiceName, err.Error())
				continue
			}
			fillHappen = true
			log.Infof("fill parse data to  %s.%s.%s successfully", prod.ProductName, singleService.ServiceName, container.Name)
		}
	}
	if fillHappen {
		err := commonrepo.NewProductColl().Update(prod)
		if err != nil {
			return err
		}
	}
	return nil
}