diff --git a/chart/Chart.yaml b/chart/Chart.yaml index d586cdd..79bf1cc 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -10,9 +10,9 @@ description: | type: application -version: 0.5.52 +version: 0.5.53 -appVersion: "0.5.52" +appVersion: "0.5.53" home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator diff --git a/chart/values.yaml b/chart/values.yaml index 934a1a5..5fadaa3 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -11,10 +11,10 @@ sa: drop: - ALL env: - workerImage: ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:0.5.52 + workerImage: ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:0.5.53 image: repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator - tag: 0.5.52 + tag: 0.5.53 resources: limits: cpu: 500m diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index e399ae8..4524309 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -4,70 +4,71 @@ kind: ClusterRole metadata: name: impex-mgr rules: -- apiGroups: - - "" - resources: - - pods - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - apps - resources: - - daemonsets - - deployments - verbs: - - get - - list - - watch -- apiGroups: - - batch - resources: - - cronjobs - verbs: - - get - - list - - watch -- apiGroups: - - batch - resources: - - jobs - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - raczylo.com - resources: - - '*' - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - raczylo.com - resources: - - '*/finalizers' - verbs: - - update -- apiGroups: - - raczylo.com - resources: - - '*/status' - verbs: - - get - - patch - - update + - apiGroups: + - "" + resources: + - pods + verbs: + - create + - delete + - deletecollection + - get + - list + - patch + - update + - watch + - apiGroups: + - apps + resources: + - daemonsets + - deployments + verbs: + - get + - list + - watch + - apiGroups: + - batch + resources: + - cronjobs + verbs: + - get + - list + - watch + - apiGroups: + - batch + resources: + - jobs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - raczylo.com + resources: + - "*" + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - raczylo.com + resources: + - "*/finalizers" + verbs: + - update + - apiGroups: + - raczylo.com + resources: + - "*/status" + verbs: + - get + - patch + - update diff --git a/internal/controller/raczylo.com/clusterimage_controller.go b/internal/controller/raczylo.com/clusterimage_controller.go index b0b8b10..1f7c6f9 100644 --- a/internal/controller/raczylo.com/clusterimage_controller.go +++ b/internal/controller/raczylo.com/clusterimage_controller.go @@ -36,7 +36,7 @@ type ClusterImageReconciler struct { // +kubebuilder:rbac:groups=raczylo.com,resources=*/finalizers,verbs=update // # additional RBAC rules - create and manage jobs // +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch;create;update;patch;delete;deletecollection // add access to secrets // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch func (r *ClusterImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { diff --git a/internal/controller/raczylo.com/clusterimageexport_controller.go b/internal/controller/raczylo.com/clusterimageexport_controller.go index d303b78..341f6c4 100644 --- a/internal/controller/raczylo.com/clusterimageexport_controller.go +++ b/internal/controller/raczylo.com/clusterimageexport_controller.go @@ -181,7 +181,9 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R } // Check completion status and update counts - completedCount := 0 + successCount := 0 + failedCount := 0 + pendingCount := 0 clusterImageList := &raczylocomv1.ClusterImageList{} if err := r.List(ctx, clusterImageList, client.InNamespace(clusterImageExport.Namespace), client.MatchingFields{"spec.exportName": clusterImageExport.Name}); err != nil { @@ -190,30 +192,37 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R } for _, ci := range clusterImageList.Items { - if ci.Status.Progress == shared.STATUS_SUCCESS || ci.Status.Progress == shared.STATUS_PRESENT { - completedCount++ + switch ci.Status.Progress { + case shared.STATUS_SUCCESS, shared.STATUS_PRESENT: + successCount++ + case shared.STATUS_FAILED: + failedCount++ + case shared.STATUS_PENDING, shared.STATUS_RUNNING, shared.STATUS_RETRYING: + pendingCount++ } } + completedCount := successCount + failedCount + // Update status with completion info - if completedCount == totalImages && totalImages > 0 { - if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error { - export.Status.Progress = shared.STATUS_SUCCESS - export.Status.CompletedImages = completedCount - return nil - }); err != nil { - l.Error(err, "unable to update ClusterImageExport status") - return ctrl.Result{}, err - } - return ctrl.Result{}, nil - } else { - if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error { - export.Status.CompletedImages = completedCount - return nil - }); err != nil { - l.Error(err, "unable to update ClusterImageExport status") - return ctrl.Result{}, err + if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error { + export.Status.CompletedImages = completedCount + if completedCount == totalImages && totalImages > 0 { + if failedCount > 0 { + export.Status.Progress = shared.STATUS_FAILED + } else { + export.Status.Progress = shared.STATUS_SUCCESS + } } + return nil + }); err != nil { + l.Error(err, "unable to update ClusterImageExport status") + return ctrl.Result{}, err + } + + // If there are still pending images, requeue + if pendingCount > 0 { + return ctrl.Result{Requeue: true}, nil } return ctrl.Result{Requeue: true}, nil @@ -401,7 +410,7 @@ func (r *ClusterImageExportReconciler) runCleanupJob(ctx context.Context, cluste // Set up the cleanup job with retry limits and TTL backoffLimit := int32(2) // 3 total attempts (initial + 2 retries) - ttlSecondsAfterFinished := int32(30) // Delete job 30 seconds after completion + ttlSecondsAfterFinished := int32(300) // Delete job 5 minutes after completion // Merge annotations from different sources mergedAnnotations := make(map[string]string)