From 8dde6cd48e63b079b77eb72b64748eed008bfc22 Mon Sep 17 00:00:00 2001 From: Mihai Idu Date: Thu, 7 Aug 2025 17:57:10 +0200 Subject: [PATCH 1/3] enhance must-gather image collection with CSV annotation warnings - Updated completeImages() to log a warning when a ClusterServiceVersion (CSV) is missing the "operators.openshift.io/must-gather-image" annotation. - Inlined CSV processing logic to allow detailed per-CSV warning logging. - Improved error handling and logging for image stream tag resolution. - Ensured deduplication of default must-gather image from plug-in list. - Maintained compatibility with --all-images and fallback logic. --- pkg/cli/admin/mustgather/mustgather.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/cli/admin/mustgather/mustgather.go b/pkg/cli/admin/mustgather/mustgather.go index 86e9c7a8bd..ab9ba61cfd 100644 --- a/pkg/cli/admin/mustgather/mustgather.go +++ b/pkg/cli/admin/mustgather/mustgather.go @@ -256,6 +256,7 @@ func (o *MustGatherOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg } func (o *MustGatherOptions) completeImages() error { + // Resolve explicitly provided image streams for _, imageStream := range o.ImageStreams { if image, err := o.resolveImageStreamTagString(imageStream); err == nil { o.Images = append(o.Images, image) @@ -263,6 +264,7 @@ func (o *MustGatherOptions) completeImages() 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 @@ -277,14 +279,24 @@ func (o *MustGatherOptions) completeImages() error { pluginImages := make(map[string]struct{}) var err error - pluginImages, err = o.annotatedCSVs() + // Annotated CSVs + csvs, err := o.OperatorClient.OperatorsV1alpha1().ClusterServiceVersions("").List(context.TODO(), metav1.ListOptions{}) 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()) + } } + // Annotated ClusterOperators cos, err := o.ConfigClient.ConfigV1().ClusterOperators().List(context.TODO(), metav1.ListOptions{}) if err != nil { - return err + return fmt.Errorf("failed to list ClusterOperators: %v", err) } for _, item := range cos.Items { ann := item.GetAnnotations() @@ -299,7 +311,7 @@ func (o *MustGatherOptions) completeImages() error { } } o.log("Using must-gather plug-in image: %s", strings.Join(o.Images, ", ")) - + return nil } From 3845d4b28cc14485094b52122d0796b9df588f0b Mon Sep 17 00:00:00 2001 From: Mihai IDU Date: Wed, 17 Sep 2025 11:49:45 +0200 Subject: [PATCH 2/3] Fix compile error --- pkg/cli/admin/mustgather/mustgather.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/cli/admin/mustgather/mustgather.go b/pkg/cli/admin/mustgather/mustgather.go index 6eff8a6ea5..14a6301eba 100644 --- a/pkg/cli/admin/mustgather/mustgather.go +++ b/pkg/cli/admin/mustgather/mustgather.go @@ -281,17 +281,22 @@ func (o *MustGatherOptions) completeImages() error { pluginImages := make(map[string]struct{}) var err error - // Annotated CSVs - csvs, err := o.OperatorClient.OperatorsV1alpha1().ClusterServiceVersions("").List(context.TODO(), metav1.ListOptions{}) + // Annotated CSVs (via dynamic client) + csvGVR := schema.GroupVersionResource{ + Group: "operators.coreos.com", + Version: "v1alpha1", + Resource: "clusterserviceversions", + } + uList, err := o.DynamicClient.Resource(csvGVR).List(context.TODO(), metav1.ListOptions{}) if err != nil { return fmt.Errorf("failed to list CSVs: %v", err) } - for _, csv := range csvs.Items { - ann := csv.GetAnnotations() + for _, u := range uList.Items { + ann := u.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()) + o.log("WARNING: CSV operator %s doesn't have the must-gather-image annotation.", u.GetName()) } } @@ -313,7 +318,7 @@ func (o *MustGatherOptions) completeImages() error { } } o.log("Using must-gather plug-in image: %s", strings.Join(o.Images, ", ")) - + return nil } From e9f31051d41658588d04b6fde3332ffaba3c089d Mon Sep 17 00:00:00 2001 From: Mihai IDU Date: Wed, 17 Sep 2025 22:49:12 +0200 Subject: [PATCH 3/3] Revert "Fix compile error" This reverts commit 3845d4b28cc14485094b52122d0796b9df588f0b. --- pkg/cli/admin/mustgather/mustgather.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/cli/admin/mustgather/mustgather.go b/pkg/cli/admin/mustgather/mustgather.go index 14a6301eba..6eff8a6ea5 100644 --- a/pkg/cli/admin/mustgather/mustgather.go +++ b/pkg/cli/admin/mustgather/mustgather.go @@ -281,22 +281,17 @@ func (o *MustGatherOptions) completeImages() error { pluginImages := make(map[string]struct{}) var err error - // Annotated CSVs (via dynamic client) - csvGVR := schema.GroupVersionResource{ - Group: "operators.coreos.com", - Version: "v1alpha1", - Resource: "clusterserviceversions", - } - uList, err := o.DynamicClient.Resource(csvGVR).List(context.TODO(), metav1.ListOptions{}) + // Annotated CSVs + csvs, err := o.OperatorClient.OperatorsV1alpha1().ClusterServiceVersions("").List(context.TODO(), metav1.ListOptions{}) if err != nil { return fmt.Errorf("failed to list CSVs: %v", err) } - for _, u := range uList.Items { - ann := u.GetAnnotations() + 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.", u.GetName()) + o.log("WARNING: CSV operator %s doesn't have the must-gather-image annotation.", csv.GetName()) } } @@ -318,7 +313,7 @@ func (o *MustGatherOptions) completeImages() error { } } o.log("Using must-gather plug-in image: %s", strings.Join(o.Images, ", ")) - + return nil }