Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion controllers/mustgather/mustgather_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"slices"
"time"

"github.com/go-logr/logr"
imagev1 "github.com/openshift/api/image/v1"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions controllers/mustgather/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down