mirror of
https://github.com/lukaszraczylo/kubernetes-images-sync-operator.git
synced 2026-07-08 03:54:26 +00:00
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! General improvements
This commit is contained in:
+2
-2
@@ -10,9 +10,9 @@ description: |
|
|||||||
|
|
||||||
type: application
|
type: application
|
||||||
|
|
||||||
version: 0.2.33
|
version: 0.2.34
|
||||||
|
|
||||||
appVersion: "0.2.33"
|
appVersion: "0.2.34"
|
||||||
|
|
||||||
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
|
home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ sa:
|
|||||||
- ALL
|
- ALL
|
||||||
image:
|
image:
|
||||||
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator
|
||||||
tag: 0.2.33
|
tag: 0.2.34
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 500m
|
cpu: 500m
|
||||||
|
|||||||
@@ -157,6 +157,13 @@ func (r *ClusterImageReconciler) handlePendingClusterImage(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *ClusterImageReconciler) handleRunningClusterImage(ctx context.Context, clusterImage *raczylocomv1.ClusterImage, l logr.Logger) (ctrl.Result, error) {
|
func (r *ClusterImageReconciler) handleRunningClusterImage(ctx context.Context, clusterImage *raczylocomv1.ClusterImage, l logr.Logger) (ctrl.Result, error) {
|
||||||
|
// Get the latest version before proceeding
|
||||||
|
latest := &raczylocomv1.ClusterImage{}
|
||||||
|
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
clusterImage = latest
|
||||||
|
|
||||||
// Check for existing job for this ClusterImage
|
// Check for existing job for this ClusterImage
|
||||||
existingJob := &v1batch.Job{}
|
existingJob := &v1batch.Job{}
|
||||||
jobName := fmt.Sprintf("img-export-%s", clusterImage.Name)
|
jobName := fmt.Sprintf("img-export-%s", clusterImage.Name)
|
||||||
@@ -171,16 +178,26 @@ func (r *ClusterImageReconciler) handleRunningClusterImage(ctx context.Context,
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have retries left, consider retrying
|
// Get latest version before updating status
|
||||||
if clusterImage.Status.RetryCount < 3 {
|
latest := &raczylocomv1.ClusterImage{}
|
||||||
clusterImage.Status.Progress = shared.STATUS_RETRYING
|
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
||||||
clusterImage.Status.RetryCount++
|
return ctrl.Result{}, err
|
||||||
} else {
|
|
||||||
// Exceeded retries; mark as FAILED
|
|
||||||
clusterImage.Status.Progress = shared.STATUS_FAILED
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.Status().Update(ctx, clusterImage); err != nil {
|
// If we have retries left, consider retrying
|
||||||
|
if latest.Status.RetryCount < 3 {
|
||||||
|
latest.Status.Progress = shared.STATUS_RETRYING
|
||||||
|
latest.Status.RetryCount++
|
||||||
|
} else {
|
||||||
|
// Exceeded retries; mark as FAILED
|
||||||
|
latest.Status.Progress = shared.STATUS_FAILED
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.Status().Update(ctx, latest); err != nil {
|
||||||
|
if errors.IsConflict(err) {
|
||||||
|
// Resource was modified, requeue and try again
|
||||||
|
return ctrl.Result{Requeue: true}, nil
|
||||||
|
}
|
||||||
l.Error(err, "unable to update ClusterImage status after job not found")
|
l.Error(err, "unable to update ClusterImage status after job not found")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
@@ -192,18 +209,17 @@ func (r *ClusterImageReconciler) handleRunningClusterImage(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check job status and update ClusterImage accordingly
|
// Check job status and update ClusterImage accordingly
|
||||||
// Get latest version before updating status
|
|
||||||
latest := &raczylocomv1.ClusterImage{}
|
|
||||||
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
clusterImage = latest
|
|
||||||
|
|
||||||
if existingJob.Status.Succeeded > 0 {
|
if existingJob.Status.Succeeded > 0 {
|
||||||
clusterImage.Status.Progress = shared.STATUS_SUCCESS
|
// Get latest version before updating status
|
||||||
|
latest := &raczylocomv1.ClusterImage{}
|
||||||
|
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
latest.Status.Progress = shared.STATUS_SUCCESS
|
||||||
r.ActiveJobs--
|
r.ActiveJobs--
|
||||||
// Update the status before cleaning up the job
|
// Update the status before cleaning up the job
|
||||||
if err := r.Status().Update(ctx, clusterImage); err != nil {
|
if err := r.Status().Update(ctx, latest); err != nil {
|
||||||
if errors.IsConflict(err) {
|
if errors.IsConflict(err) {
|
||||||
// Resource was modified, requeue and try again
|
// Resource was modified, requeue and try again
|
||||||
return ctrl.Result{Requeue: true}, nil
|
return ctrl.Result{Requeue: true}, nil
|
||||||
@@ -431,6 +447,14 @@ func (r *ClusterImageReconciler) updateClusterImageExportStatus(ctx context.Cont
|
|||||||
|
|
||||||
func (r *ClusterImageReconciler) handleJobRestarts(ctx context.Context, job *v1batch.Job, clusterImage *raczylocomv1.ClusterImage) error {
|
func (r *ClusterImageReconciler) handleJobRestarts(ctx context.Context, job *v1batch.Job, clusterImage *raczylocomv1.ClusterImage) error {
|
||||||
l := log.FromContext(ctx)
|
l := log.FromContext(ctx)
|
||||||
|
|
||||||
|
// Get the latest version before proceeding
|
||||||
|
latest := &raczylocomv1.ClusterImage{}
|
||||||
|
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
clusterImage = latest
|
||||||
|
|
||||||
podList := &v1.PodList{}
|
podList := &v1.PodList{}
|
||||||
if err := r.List(ctx, podList, client.InNamespace(job.Namespace), client.MatchingLabels(job.Spec.Selector.MatchLabels)); err != nil {
|
if err := r.List(ctx, podList, client.InNamespace(job.Namespace), client.MatchingLabels(job.Spec.Selector.MatchLabels)); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -449,22 +473,21 @@ func (r *ClusterImageReconciler) handleJobRestarts(ctx context.Context, job *v1b
|
|||||||
if newRestarts > 0 {
|
if newRestarts > 0 {
|
||||||
l.Info("Container restarts detected", "job", job.Name, "newRestarts", newRestarts, "totalRestarts", totalRestarts)
|
l.Info("Container restarts detected", "job", job.Name, "newRestarts", newRestarts, "totalRestarts", totalRestarts)
|
||||||
|
|
||||||
|
// Get latest version before updating
|
||||||
|
latest := &raczylocomv1.ClusterImage{}
|
||||||
|
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Update retry count with new restarts
|
// Update retry count with new restarts
|
||||||
clusterImage.Status.RetryCount += newRestarts
|
latest.Status.RetryCount = clusterImage.Status.RetryCount + newRestarts
|
||||||
|
|
||||||
if clusterImage.Status.RetryCount >= 3 {
|
|
||||||
// Get latest version before updating status
|
|
||||||
latest := &raczylocomv1.ClusterImage{}
|
|
||||||
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if latest.Status.RetryCount >= 3 {
|
||||||
// Max retries reached
|
// Max retries reached
|
||||||
latest.Status.Progress = shared.STATUS_FAILED
|
latest.Status.Progress = shared.STATUS_FAILED
|
||||||
latest.Status.RetryCount = clusterImage.Status.RetryCount
|
|
||||||
if err := r.Status().Update(ctx, latest); err != nil {
|
if err := r.Status().Update(ctx, latest); err != nil {
|
||||||
if errors.IsConflict(err) {
|
if errors.IsConflict(err) {
|
||||||
// Resource was modified, try again
|
// Resource was modified, requeue and try again
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to update status to FAILED: %w", err)
|
return fmt.Errorf("failed to update status to FAILED: %w", err)
|
||||||
@@ -475,18 +498,11 @@ func (r *ClusterImageReconciler) handleJobRestarts(ctx context.Context, job *v1b
|
|||||||
return fmt.Errorf("failed to cleanup resources: %w", err)
|
return fmt.Errorf("failed to cleanup resources: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Get latest version before updating status
|
|
||||||
latest := &raczylocomv1.ClusterImage{}
|
|
||||||
if err := r.Get(ctx, types.NamespacedName{Name: clusterImage.Name, Namespace: clusterImage.Namespace}, latest); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Still have retries left
|
// Still have retries left
|
||||||
latest.Status.Progress = shared.STATUS_RETRYING
|
latest.Status.Progress = shared.STATUS_RETRYING
|
||||||
latest.Status.RetryCount = clusterImage.Status.RetryCount
|
|
||||||
if err := r.Status().Update(ctx, latest); err != nil {
|
if err := r.Status().Update(ctx, latest); err != nil {
|
||||||
if errors.IsConflict(err) {
|
if errors.IsConflict(err) {
|
||||||
// Resource was modified, try again
|
// Resource was modified, requeue and try again
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to update status to RETRYING: %w", err)
|
return fmt.Errorf("failed to update status to RETRYING: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user