Skip to content

Commit 6ec607d

Browse files
authored
fix distribute image image pull error (#4280)
Signed-off-by: Min Min <[email protected]>
1 parent 8232cc6 commit 6ec607d

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

pkg/microservice/aslan/core/common/service/registry.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import (
3333
)
3434

3535
func FindRegistryById(registryId string, getRealCredential bool, log *zap.SugaredLogger) (reg *models.RegistryNamespace, err error) {
36+
if registryId == "" {
37+
return nil, fmt.Errorf("registryId is empty")
38+
}
3639
return findRegisty(&mongodb.FindRegOps{ID: registryId}, getRealCredential, log)
3740
}
3841

pkg/microservice/aslan/core/workflow/service/workflow/controller/job/job_distribute_image.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,9 @@ func (j DistributeImageJobController) ToTask(taskID int64) ([]*commonmodels.JobT
165165
logger := log.SugaredLogger()
166166
resp := make([]*commonmodels.JobTask, 0)
167167

168-
sourceReg, err := commonservice.FindRegistryById(j.jobSpec.SourceRegistryID, true, logger)
169-
if err != nil {
170-
return resp, fmt.Errorf("source image registry: %s not found: %v", j.jobSpec.SourceRegistryID, err)
171-
}
172-
targetReg, err := commonservice.FindRegistryById(j.jobSpec.TargetRegistryID, true, logger)
173-
if err != nil {
174-
return resp, fmt.Errorf("target image registry: %s not found: %v", j.jobSpec.TargetRegistryID, err)
175-
}
168+
var sourceReg *commonmodels.RegistryNamespace
169+
var targetReg *commonmodels.RegistryNamespace
170+
var err error
176171

177172
switch j.jobSpec.Source {
178173
case config.SourceFromJob:
@@ -184,6 +179,11 @@ func (j DistributeImageJobController) ToTask(taskID int64) ([]*commonmodels.JobT
184179

185180
j.jobSpec.SourceRegistryID = registryID
186181

182+
sourceReg, err = commonservice.FindRegistryById(j.jobSpec.SourceRegistryID, true, logger)
183+
if err != nil {
184+
return resp, fmt.Errorf("source image registry: %s not found: %v", j.jobSpec.SourceRegistryID, err)
185+
}
186+
187187
targetTagMap := map[string]commonmodels.DistributeTarget{}
188188
for _, target := range j.jobSpec.Targets {
189189
targetTagMap[getServiceKey(target.ServiceName, target.ServiceModule)] = *target
@@ -204,6 +204,11 @@ func (j DistributeImageJobController) ToTask(taskID int64) ([]*commonmodels.JobT
204204

205205
j.jobSpec.Targets = targets
206206
case config.SourceRuntime:
207+
sourceReg, err = commonservice.FindRegistryById(j.jobSpec.SourceRegistryID, true, logger)
208+
if err != nil {
209+
return resp, fmt.Errorf("source image registry: %s not found: %v", j.jobSpec.SourceRegistryID, err)
210+
}
211+
207212
for _, target := range j.jobSpec.Targets {
208213
if target.ImageName == "" {
209214
target.SourceImage = getImage(target.ServiceModule, target.SourceTag, sourceReg)
@@ -218,6 +223,11 @@ func (j DistributeImageJobController) ToTask(taskID int64) ([]*commonmodels.JobT
218223
}
219224
}
220225

226+
targetReg, err = commonservice.FindRegistryById(j.jobSpec.TargetRegistryID, true, logger)
227+
if err != nil {
228+
return resp, fmt.Errorf("target image registry: %s not found: %v", j.jobSpec.TargetRegistryID, err)
229+
}
230+
221231
stepSpec := &step.StepImageDistributeSpec{
222232
Type: j.jobSpec.DistributeMethod,
223233
SourceRegistry: getRegistry(sourceReg),

0 commit comments

Comments
 (0)