mirror of
https://github.com/lukaszraczylo/kubernetes-images-sync-operator.git
synced 2026-07-07 03:44:38 +00:00
fixup! 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.34
|
version: 0.2.35
|
||||||
|
|
||||||
appVersion: "0.2.34"
|
appVersion: "0.2.35"
|
||||||
|
|
||||||
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.34
|
tag: 0.2.35
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 500m
|
cpu: 500m
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/client-go/util/retry"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/pointer"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
@@ -81,25 +82,29 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset status if the ClusterImageExport is in a completed state
|
// Handle status updates with retries
|
||||||
if clusterImageExport.Status.Progress == shared.STATUS_SUCCESS || clusterImageExport.Status.Progress == shared.STATUS_FAILED {
|
if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error {
|
||||||
// Reset the status to allow reprocessing
|
// Reset status if the ClusterImageExport is in a completed state
|
||||||
clusterImageExport.Status.Progress = ""
|
if export.Status.Progress == shared.STATUS_SUCCESS || export.Status.Progress == shared.STATUS_FAILED {
|
||||||
if err := r.Status().Update(ctx, clusterImageExport); err != nil {
|
export.Status.Progress = ""
|
||||||
l.Error(err, "unable to reset ClusterImageExport status")
|
return nil
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
}
|
||||||
// Requeue to process with reset status
|
|
||||||
return ctrl.Result{Requeue: true}, nil
|
// Set to PENDING if empty
|
||||||
|
if export.Status.Progress == "" {
|
||||||
|
export.Status.Progress = shared.STATUS_PENDING
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
l.Error(err, "unable to update ClusterImageExport status")
|
||||||
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the status is empty, set it to PENDING
|
// If we just reset the status, requeue to process with reset status
|
||||||
if clusterImageExport.Status.Progress == "" {
|
if clusterImageExport.Status.Progress == "" {
|
||||||
clusterImageExport.Status.Progress = shared.STATUS_PENDING
|
return ctrl.Result{Requeue: true}, nil
|
||||||
if err := r.Status().Update(ctx, clusterImageExport); err != nil {
|
|
||||||
l.Error(err, "unable to update ClusterImageExport status")
|
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proceed with the rest of the reconciliation logic
|
// Proceed with the rest of the reconciliation logic
|
||||||
@@ -120,8 +125,11 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterImageExport.Status.Progress = shared.STATUS_RUNNING
|
// Update status to RUNNING with retry
|
||||||
if err := r.Status().Update(ctx, clusterImageExport); err != nil {
|
if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error {
|
||||||
|
export.Status.Progress = shared.STATUS_RUNNING
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
l.Error(err, "unable to update ClusterImageExport status to RUNNING")
|
l.Error(err, "unable to update ClusterImageExport status to RUNNING")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
@@ -137,8 +145,10 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
// ClusterImage exists, check its status
|
// ClusterImage exists, check its status
|
||||||
if clusterImage.Status.Progress == shared.STATUS_FAILED {
|
if clusterImage.Status.Progress == shared.STATUS_FAILED {
|
||||||
clusterImageExport.Status.Progress = shared.STATUS_FAILED
|
if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error {
|
||||||
if err := r.Status().Update(ctx, clusterImageExport); err != nil {
|
export.Status.Progress = shared.STATUS_FAILED
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
l.Error(err, "unable to update ClusterImageExport status to FAILED")
|
l.Error(err, "unable to update ClusterImageExport status to FAILED")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
@@ -193,8 +203,10 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
if allCompleted {
|
if allCompleted {
|
||||||
clusterImageExport.Status.Progress = shared.STATUS_SUCCESS
|
if err := r.updateStatusWithRetry(ctx, clusterImageExport, func(export *raczylocomv1.ClusterImageExport) error {
|
||||||
if err := r.Status().Update(ctx, clusterImageExport); err != nil {
|
export.Status.Progress = shared.STATUS_SUCCESS
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
l.Error(err, "unable to update ClusterImageExport status to SUCCESS")
|
l.Error(err, "unable to update ClusterImageExport status to SUCCESS")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
@@ -203,6 +215,28 @@ func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.R
|
|||||||
return ctrl.Result{Requeue: !allCompleted}, nil
|
return ctrl.Result{Requeue: !allCompleted}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateStatusWithRetry attempts to update the status of a ClusterImageExport with retries
|
||||||
|
func (r *ClusterImageExportReconciler) updateStatusWithRetry(ctx context.Context, clusterImageExport *raczylocomv1.ClusterImageExport, updateFn func(*raczylocomv1.ClusterImageExport) error) error {
|
||||||
|
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||||
|
// Get the latest version of the resource
|
||||||
|
latest := &raczylocomv1.ClusterImageExport{}
|
||||||
|
if err := r.Get(ctx, client.ObjectKey{
|
||||||
|
Namespace: clusterImageExport.Namespace,
|
||||||
|
Name: clusterImageExport.Name,
|
||||||
|
}, latest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the update function to the latest version
|
||||||
|
if err := updateFn(latest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the status
|
||||||
|
return r.Status().Update(ctx, latest)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (r *ClusterImageExportReconciler) checkAllClusterImagesCompleted(ctx context.Context, clusterImageExport *raczylocomv1.ClusterImageExport) (bool, error) {
|
func (r *ClusterImageExportReconciler) checkAllClusterImagesCompleted(ctx context.Context, clusterImageExport *raczylocomv1.ClusterImageExport) (bool, error) {
|
||||||
clusterImageList := &raczylocomv1.ClusterImageList{}
|
clusterImageList := &raczylocomv1.ClusterImageList{}
|
||||||
if err := r.List(ctx, clusterImageList, client.InNamespace(clusterImageExport.Namespace), client.MatchingFields{"spec.exportName": clusterImageExport.Name}); err != nil {
|
if err := r.List(ctx, clusterImageList, client.InNamespace(clusterImageExport.Namespace), client.MatchingFields{"spec.exportName": clusterImageExport.Name}); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user