Skip to content
15 changes: 12 additions & 3 deletions pkg/cli/admin/mustgather/mustgather.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (o *MustGatherOptions) completeImages(ctx context.Context) error {
return fmt.Errorf("unable to resolve image stream '%v': %v", imageStream, err)
}
}
// If no images or --all flag is set, use default must-gather image
if len(o.Images) == 0 || o.AllImages {
var image string
var err error
Expand All @@ -288,12 +289,20 @@ func (o *MustGatherOptions) completeImages(ctx context.Context) error {

pluginImages, err = o.annotatedCSVs(ctx)
if err != nil {
return err
return fmt.Errorf("failed to list CSVs: %v", err)
}
for _, csv := range csvs.Items {
ann := csv.GetAnnotations()
if v, ok := ann[mgAnnotation]; ok {
pluginImages[v] = struct{}{}
} else {
o.log("WARNING: CSV operator %s doesn't have the must-gather-image annotation.", csv.GetName())
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Compile error: csvs is undefined in this scope.

The annotatedCSVs function returns only (map[string]struct{}, error), but lines 294-300 reference csvs.Items which is undefined here. This matches the CI failure reported in PR comments.

To preserve the per-CSV warning behavior, move the warning logic into annotatedCSVs by passing the log function:

🐛 Proposed fix

Update the annotatedCSVs signature and implementation:

-func (o *MustGatherOptions) annotatedCSVs(ctx context.Context) (map[string]struct{}, error) {
+func (o *MustGatherOptions) annotatedCSVs(ctx context.Context, warnMissing bool) (map[string]struct{}, error) {
 	csvGVR := schema.GroupVersionResource{
 		Group:    "operators.coreos.com",
 		Version:  "v1alpha1",
 		Resource: "clusterserviceversions",
 	}
 	pluginImages := make(map[string]struct{})

 	csvs, err := o.DynamicClient.Resource(csvGVR).List(ctx, metav1.ListOptions{})
 	if err != nil {
 		return nil, err
 	}

 	for _, item := range csvs.Items {
 		ann := item.GetAnnotations()
 		if v, ok := ann[mgAnnotation]; ok {
 			pluginImages[v] = struct{}{}
+		} else if warnMissing {
+			o.log("WARNING: CSV operator %s doesn't have the must-gather-image annotation.", item.GetName())
 		}
 	}
 	return pluginImages, nil
 }

Then update the call site and remove the orphaned loop:

-		pluginImages, err = o.annotatedCSVs(ctx)
+		pluginImages, err = o.annotatedCSVs(ctx, true)
 		if err != nil {
 			return fmt.Errorf("failed to list CSVs: %v", err)
 		}
-		for _, csv := range csvs.Items {
-			ann := csv.GetAnnotations()
-			if v, ok := ann[mgAnnotation]; ok {
-				pluginImages[v] = struct{}{}
-			} else {
-				o.log("WARNING: CSV operator %s doesn't have the must-gather-image annotation.", csv.GetName())
-			}
-		}
🤖 Prompt for AI Agents
In `@pkg/cli/admin/mustgather/mustgather.go` around lines 290 - 301, The undefined
`csvs` bug is caused by moving CSV iteration out of annotatedCSVs; restore
per-CSV warning logic by changing annotatedCSVs to accept the logger (e.g., add
a parameter for o.log or a func like logf) and move the loop that inspects
csvs.Items and emits warnings using mgAnnotation into annotatedCSVs; update
annotatedCSVs' signature (e.g., annotatedCSVs(ctx context.Context, logf
func(string, ...interface{})) (map[string]struct{}, error)), implement the
per-CSV warning there when an annotation is missing, and then call it from
mustgather.go as pluginImages, err = o.annotatedCSVs(ctx, o.log) and remove the
orphaned for-loop in mustgather.go; also update any other callers to match the
new signature.


cos, err := o.ConfigClient.ConfigV1().ClusterOperators().List(ctx, metav1.ListOptions{})
if err != nil {
return err
return fmt.Errorf("failed to list ClusterOperators: %v", err)
}
for _, item := range cos.Items {
ann := item.GetAnnotations()
Expand All @@ -308,7 +317,7 @@ func (o *MustGatherOptions) completeImages(ctx context.Context) error {
}
}
o.log("Using must-gather plug-in image: %s", strings.Join(o.Images, ", "))

return nil
}

Expand Down