@@ -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