fixup! fixup! fixup! fixup! fixup! fixup! Improve helm chart allowing for lock of the worker image

This commit is contained in:
2025-01-14 01:25:42 +00:00
parent 03214c8a47
commit 067a51c9c7
5 changed files with 103 additions and 93 deletions
+2 -2
View File
@@ -10,9 +10,9 @@ description: |
type: application 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 home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
+2 -2
View File
@@ -11,10 +11,10 @@ sa:
drop: drop:
- ALL - ALL
env: env:
workerImage: ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:0.5.52 workerImage: ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:0.5.53
image: image:
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
tag: 0.5.52 tag: 0.5.53
resources: resources:
limits: limits:
cpu: 500m cpu: 500m
+68 -67
View File
@@ -4,70 +4,71 @@ kind: ClusterRole
metadata: metadata:
name: impex-mgr name: impex-mgr
rules: rules:
- apiGroups: - apiGroups:
- "" - ""
resources: resources:
- pods - pods
verbs: verbs:
- create - create
- delete - delete
- get - deletecollection
- list - get
- patch - list
- update - patch
- watch - update
- apiGroups: - watch
- apps - apiGroups:
resources: - apps
- daemonsets resources:
- deployments - daemonsets
verbs: - deployments
- get verbs:
- list - get
- watch - list
- apiGroups: - watch
- batch - apiGroups:
resources: - batch
- cronjobs resources:
verbs: - cronjobs
- get verbs:
- list - get
- watch - list
- apiGroups: - watch
- batch - apiGroups:
resources: - batch
- jobs resources:
verbs: - jobs
- create verbs:
- delete - create
- get - delete
- list - get
- patch - list
- update - patch
- watch - update
- apiGroups: - watch
- raczylo.com - apiGroups:
resources: - raczylo.com
- '*' resources:
verbs: - "*"
- create verbs:
- delete - create
- get - delete
- list - get
- patch - list
- update - patch
- watch - update
- apiGroups: - watch
- raczylo.com - apiGroups:
resources: - raczylo.com
- '*/finalizers' resources:
verbs: - "*/finalizers"
- update verbs:
- apiGroups: - update
- raczylo.com - apiGroups:
resources: - raczylo.com
- '*/status' resources:
verbs: - "*/status"
- get verbs:
- patch - get
- update - patch
- update
@@ -36,7 +36,7 @@ type ClusterImageReconciler struct {
// +kubebuilder:rbac:groups=raczylo.com,resources=*/finalizers,verbs=update // +kubebuilder:rbac:groups=raczylo.com,resources=*/finalizers,verbs=update
// # additional RBAC rules - create and manage jobs // # additional RBAC rules - create and manage jobs
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete // +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 // add access to secrets
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
func (r *ClusterImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { func (r *ClusterImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -181,7 +181,9 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
} }
// Check completion status and update counts // Check completion status and update counts
completedCount := 0 successCount := 0
failedCount := 0
pendingCount := 0
clusterImageList := &raczylocomv1.ClusterImageList{} clusterImageList := &raczylocomv1.ClusterImageList{}
if err := r.List(ctx, clusterImageList, client.InNamespace(clusterImageExport.Namespace), if err := r.List(ctx, clusterImageList, client.InNamespace(clusterImageExport.Namespace),
client.MatchingFields{"spec.exportName": clusterImageExport.Name}); err != nil { 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 { for _, ci := range clusterImageList.Items {
if ci.Status.Progress == shared.STATUS_SUCCESS || ci.Status.Progress == shared.STATUS_PRESENT { switch ci.Status.Progress {
completedCount++ 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 // Update status with completion info
if completedCount == totalImages && totalImages > 0 { if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error {
if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error { export.Status.CompletedImages = completedCount
export.Status.Progress = shared.STATUS_SUCCESS if completedCount == totalImages && totalImages > 0 {
export.Status.CompletedImages = completedCount if failedCount > 0 {
return nil export.Status.Progress = shared.STATUS_FAILED
}); err != nil { } else {
l.Error(err, "unable to update ClusterImageExport status") export.Status.Progress = shared.STATUS_SUCCESS
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
} }
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 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 // Set up the cleanup job with retry limits and TTL
backoffLimit := int32(2) // 3 total attempts (initial + 2 retries) 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 // Merge annotations from different sources
mergedAnnotations := make(map[string]string) mergedAnnotations := make(map[string]string)