diff --git a/controllers/mustgather/mustgather_controller.go b/controllers/mustgather/mustgather_controller.go index f528e6a7b..861297667 100644 --- a/controllers/mustgather/mustgather_controller.go +++ b/controllers/mustgather/mustgather_controller.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "slices" + "time" "github.com/go-logr/logr" imagev1 "github.com/openshift/api/image/v1" @@ -279,6 +280,9 @@ func (r *MustGatherReconciler) Reconcile(ctx context.Context, request reconcile. } // Check status of job and update any metric counts + jobAge := getJobAge(job1) + reqLogger.Info("checking job status", "age", jobAge) + if job1.Status.Active > 0 { reqLogger.Info("mustgather Job pods are still running") } else { @@ -419,6 +423,10 @@ func (r *MustGatherReconciler) getMustGatherImage(ctx context.Context, instance return r.DefaultMustGatherImage, nil } + if err := validateImageStreamRef(instance.Spec.ImageStreamRef); err != nil { + return "", err + } + // Use custom image from ImageStream imageStream := &imagev1.ImageStream{} if err := r.GetClient().Get(ctx, types.NamespacedName{Name: instance.Spec.ImageStreamRef.Name, Namespace: r.OperatorNamespace}, imageStream); err != nil { @@ -524,7 +532,8 @@ func (r *MustGatherReconciler) cleanupMustGatherResources(ctx context.Context, r } } - reqLogger.V(4).Info("successfully cleaned up mustgather resources") + logCleanupSummary(reqLogger, tmpJob.Name, len(podList.Items)) + return nil } @@ -673,3 +682,25 @@ func (r *MustGatherReconciler) cleanupTrustedCAConfigMap(ctx context.Context, re "configMapName", r.TrustedCAConfigMap, "remainingNumOwners", len(updatedOwnerRefs)) return nil } + +// getJobAge returns a human-readable string describing how long ago the job was created. +func getJobAge(job *batchv1.Job) string { + age := time.Since(job.CreationTimestamp.Time) + return age.String() +} + +// validateImageStreamRef validates that the ImageStreamRef fields are properly set. +func validateImageStreamRef(ref *mustgatherv1alpha1.ImageStreamTagRef) error { + if len(ref.Name) == 0 { + return goerror.New("imageStreamRef.name must not be empty") + } + if len(ref.Tag) == 0 { + return goerror.New("imageStreamRef.tag must not be empty") + } + return nil +} + +// logCleanupSummary logs a summary of the resources that were cleaned up. +func logCleanupSummary(reqLogger logr.Logger, jobName string, podCount int) { + reqLogger.Info("cleanup complete", "job", jobName, "podsDeleted", podCount) +} diff --git a/controllers/mustgather/template.go b/controllers/mustgather/template.go index e20b8783f..3646bf59a 100644 --- a/controllers/mustgather/template.go +++ b/controllers/mustgather/template.go @@ -114,6 +114,7 @@ func getJobTemplate(image string, operatorImage string, mustGather v1alpha1.Must timeout := time.Duration(0) if mustGather.Spec.MustGatherTimeout != nil { timeout = mustGather.Spec.MustGatherTimeout.Duration + log.V(4).Info("gather timeout configured", "timeout", timeout.String()) } // Build time filter from spec