From 7054b1906483883789d1f93feb9ffa6c83434a1f Mon Sep 17 00:00:00 2001 From: SeanHH86 <154984842+SeanHH86@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:45:53 +0800 Subject: [PATCH] [Deploy] fix deploy update with wrong image (#194) Co-authored-by: Haihui.Wang --- builder/deploy/deployer.go | 20 +++++++++++--------- component/repo.go | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/builder/deploy/deployer.go b/builder/deploy/deployer.go index e3937807..d20c17d5 100644 --- a/builder/deploy/deployer.go +++ b/builder/deploy/deployer.go @@ -132,12 +132,12 @@ func (d *deployer) serverlessDeploy(ctx context.Context, dr types.DeployRepo) (* deploy.SKU = dr.SKU // dr.ImageID is not null for nginx space, otherwise it's "" deploy.ImageID = dr.ImageID - slog.Info("do deployer.serverlessDeploy", slog.Any("dr", dr), slog.Any("deploy", deploy)) + slog.Debug("do deployer.serverlessDeploy", slog.Any("dr", dr), slog.Any("deploy", deploy)) err = d.store.UpdateDeploy(ctx, deploy) if err != nil { return nil, fmt.Errorf("fail reset deploy image, %w", err) } - slog.Info("return deployer.serverlessDeploy", slog.Any("dr", dr), slog.Any("deploy", deploy)) + slog.Debug("return deployer.serverlessDeploy", slog.Any("dr", dr), slog.Any("deploy", deploy)) return deploy, nil } @@ -542,10 +542,17 @@ func (d *deployer) UpdateDeploy(ctx context.Context, dur *types.DeployUpdateReq, if err != nil { return fmt.Errorf("error finding space resource %d, %w", *dur.ResourceID, err) } - var err = json.Unmarshal([]byte(resource.Resources), &hardware) + err = json.Unmarshal([]byte(resource.Resources), &hardware) if err != nil { return fmt.Errorf("invalid resource hardware setting, %w", err) } + deploy.Hardware = resource.Resources + deploy.SKU = strconv.FormatInt(resource.ID, 10) + } else { + err = json.Unmarshal([]byte(deploy.Hardware), &hardware) + if err != nil { + return fmt.Errorf("invalid deploy hardware setting, %w", err) + } } if dur.DeployName != nil { @@ -555,11 +562,6 @@ func (d *deployer) UpdateDeploy(ctx context.Context, dur *types.DeployUpdateReq, deploy.Env = *dur.Env } - if resource != nil { - deploy.Hardware = resource.Resources - deploy.SKU = strconv.FormatInt(resource.ID, 10) - } - if frame != nil { // choose image containerImg := frame.FrameCpuImage @@ -670,7 +672,7 @@ func (d *deployer) startAccountingRequestMeter(resMap map[string]string, svcRes } resName, exists := resMap[svcRes.DeploySku] if !exists { - slog.Warn("Did not find resource for metering", slog.Any("deploy_sku", svcRes.DeploySku)) + slog.Warn("Did not find space resource by id for metering", slog.Any("id", svcRes.DeploySku), slog.Any("deploy_id", svcRes.DeployID), slog.Any("svc_name", svcRes.ServiceName)) return } slog.Debug("metering service", slog.Any("svcRes", svcRes)) diff --git a/component/repo.go b/component/repo.go index d1378f42..310ecc28 100644 --- a/component/repo.go +++ b/component/repo.go @@ -2526,7 +2526,7 @@ func (c *repoComponentImpl) DeployUpdate(ctx context.Context, updateReq types.De } exist, err := c.deployer.Exist(ctx, deployRepo) if err != nil { - return err + return fmt.Errorf("check deploy exists, err: %w", err) } if exist {