feat(v0.1.58): ImageExists cache hit, timing analysis, in-cluster registry plan
This commit is contained in:
@@ -101,8 +101,35 @@ func (r *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// startServiceBuild запускает kaniko Job и помечает сервис как Building.
|
||||
// startServiceBuild проверяет наличие образа в registry и либо пропускает сборку,
|
||||
// либо запускает kaniko Job. Идемпотентность: если код не менялся (тег = hash s3Key),
|
||||
// образ уже в registry → deploy без пересборки.
|
||||
func (r *ServiceReconciler) startServiceBuild(ctx context.Context, svc *slessv1alpha1.Service) (ctrl.Result, error) {
|
||||
imageRef := r.Builder.ImageRef(svc.Namespace, svc.Name, svc.Spec.S3Key)
|
||||
|
||||
// Проверяем: образ с этим тегом уже существует в registry?
|
||||
// Если да — пропускаем kaniko, сразу переходим в Ready с известным imageRef.
|
||||
if r.Builder.ImageExists(ctx, imageRef) {
|
||||
logger := log.FromContext(ctx)
|
||||
logger.Info("image already exists in registry, skipping build", "imageRef", imageRef)
|
||||
|
||||
if svc.Annotations == nil {
|
||||
svc.Annotations = map[string]string{}
|
||||
}
|
||||
svc.Annotations["sless.kube5s.ru/last-built-s3key"] = svc.Spec.S3Key
|
||||
if err := r.Update(ctx, svc); err != nil {
|
||||
return ctrl.Result{}, fmt.Errorf("update service annotations (cache hit): %w", err)
|
||||
}
|
||||
|
||||
svc.Status.Phase = slessv1alpha1.ServicePhaseReady
|
||||
svc.Status.ImageRef = imageRef
|
||||
svc.Status.Message = "Image restored from registry cache"
|
||||
if err := r.Status().Update(ctx, svc); err != nil {
|
||||
return ctrl.Result{}, fmt.Errorf("update service status (cache hit): %w", err)
|
||||
}
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
jobName, err := r.Builder.Build(ctx, svc.Namespace, svc.Name, svc.Spec.S3Key)
|
||||
if err != nil {
|
||||
return r.setServiceFailed(ctx, svc, fmt.Sprintf("failed to start build: %v", err))
|
||||
|
||||
Reference in New Issue
Block a user