feat(v0.1.58): ImageExists cache hit, timing analysis, in-cluster registry plan
This commit is contained in:
@@ -109,7 +109,8 @@ func (r *FunctionJobReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
return r.createRunJob(ctx, fj, deployNS, jobName)
|
||||
}
|
||||
|
||||
// startJobBuild запускает kaniko сборку образа и переводит FunctionJob в фазу Building.
|
||||
// startJobBuild проверяет наличие образа в registry и либо пропускает сборку,
|
||||
// либо запускает kaniko Job. Идемпотентность по hash s3Key аналогична service/function.
|
||||
func (r *FunctionJobReconciler) startJobBuild(ctx context.Context, fj *slessv1alpha1.FunctionJob) (ctrl.Result, error) {
|
||||
logger := log.FromContext(ctx)
|
||||
|
||||
@@ -120,6 +121,28 @@ func (r *FunctionJobReconciler) startJobBuild(ctx context.Context, fj *slessv1al
|
||||
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
|
||||
}
|
||||
|
||||
imageRef := r.Builder.ImageRef(r.OperatorNamespace, fj.Name, fj.Spec.S3Key)
|
||||
|
||||
// Проверяем: образ с этим тегом уже существует в registry?
|
||||
if r.Builder.ImageExists(ctx, imageRef) {
|
||||
logger.Info("image already exists in registry, skipping build", "imageRef", imageRef)
|
||||
|
||||
if fj.Annotations == nil {
|
||||
fj.Annotations = map[string]string{}
|
||||
}
|
||||
if err := r.Update(ctx, fj); err != nil {
|
||||
return ctrl.Result{}, fmt.Errorf("update annotations (cache hit): %w", err)
|
||||
}
|
||||
|
||||
fj.Status.Phase = slessv1alpha1.FunctionJobPhaseBuilding // перейдёт в run сразу
|
||||
fj.Status.ImageRef = imageRef
|
||||
fj.Status.Message = "Image restored from registry cache"
|
||||
if err := r.Status().Update(ctx, fj); err != nil {
|
||||
return ctrl.Result{}, fmt.Errorf("update status (cache hit): %w", err)
|
||||
}
|
||||
return ctrl.Result{Requeue: true}, nil
|
||||
}
|
||||
|
||||
buildJobName, err := r.Builder.Build(ctx, r.OperatorNamespace, fj.Name, fj.Spec.S3Key)
|
||||
if err != nil {
|
||||
fj.Status.Phase = slessv1alpha1.FunctionJobPhaseFailed
|
||||
|
||||
Reference in New Issue
Block a user