fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! General improvements

This commit is contained in:
2025-01-10 15:15:20 +00:00
parent cc066a2502
commit d6707cf25d
3 changed files with 15 additions and 10 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ def get_s3_client(use_role=False, role_name=None, use_current_role=False, aws_ac
if endpoint_url: if endpoint_url:
client_kwargs['endpoint_url'] = endpoint_url client_kwargs['endpoint_url'] = endpoint_url
elif region: if region:
client_kwargs['region_name'] = region client_kwargs['region_name'] = region
# Check for AWS Web Identity token # Check for AWS Web Identity token
@@ -44,7 +44,7 @@ func (r *ClusterImageExportReconciler) InjectPodAnnotations(annotations map[stri
// +kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;watch // +kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;watch
// +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
const clusterImageExportFinalizer = "finalizer.clusterimageexport.raczylo.com" const clusterImageExportFinalizer = "raczylo.com/clusterimageexport-finalizer"
func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { func (r *ClusterImageExportReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
l := log.FromContext(ctx) l := log.FromContext(ctx)
@@ -308,7 +308,7 @@ func (r *ClusterImageExportReconciler) handleDeletion(ctx context.Context, clust
// Continue with deletion even if cleanup fails // Continue with deletion even if cleanup fails
} }
// Check if cleanup job already exists // Delete existing cleanup job if it exists
jobName := "cleanup-" + shared.NormalizeImageName(clusterImageExport.Name) jobName := "cleanup-" + shared.NormalizeImageName(clusterImageExport.Name)
existingJob := &batchv1.Job{} existingJob := &batchv1.Job{}
err := r.Get(ctx, client.ObjectKey{ err := r.Get(ctx, client.ObjectKey{
@@ -317,16 +317,21 @@ func (r *ClusterImageExportReconciler) handleDeletion(ctx context.Context, clust
}, existingJob) }, existingJob)
if err == nil { if err == nil {
// Job exists, don't create a new one // Job exists, delete it
l.Info("Cleanup job already exists, skipping creation", "job", jobName) if err := r.Delete(ctx, existingJob); err != nil && !errors.IsNotFound(err) {
} else if errors.IsNotFound(err) { l.Error(err, "Failed to delete existing cleanup job")
// Job doesn't exist, create it // Continue with deletion even if cleanup job deletion fails
r.runCleanupJob(ctx, clusterImageExport) } else {
} else { l.Info("Successfully deleted existing cleanup job", "job", jobName)
}
} else if !errors.IsNotFound(err) {
// Unexpected error, log but continue // Unexpected error, log but continue
l.Error(err, "Error checking for existing cleanup job") l.Error(err, "Error checking for existing cleanup job")
} }
// Create new cleanup job
r.runCleanupJob(ctx, clusterImageExport)
// Remove the finalizer regardless of cleanup job status // Remove the finalizer regardless of cleanup job status
controllerutil.RemoveFinalizer(clusterImageExport, clusterImageExportFinalizer) controllerutil.RemoveFinalizer(clusterImageExport, clusterImageExportFinalizer)
if err := r.Update(ctx, clusterImageExport); err != nil { if err := r.Update(ctx, clusterImageExport); err != nil {
+1 -1
View File
@@ -118,7 +118,7 @@ func SetupS3Params(s3Config raczylocomv1.ClusterImageStorageS3) []string {
params = append(params, fmt.Sprintf("--endpoint_url='%s'", s3Config.Endpoint)) params = append(params, fmt.Sprintf("--endpoint_url='%s'", s3Config.Endpoint))
} }
if s3Config.Region != "" { if s3Config.Region != "" {
params = append(params, fmt.Sprintf("--region=%s", s3Config.Region)) params = append(params, fmt.Sprintf("--region='%s'", s3Config.Region))
} }
return params return params
} }