-
Notifications
You must be signed in to change notification settings - Fork 26
feat: improve verbose output readability #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lburgazzoli
merged 1 commit into
opendatahub-io:main
from
andyatmiami:chore/better-verbose-output-format
Mar 3, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
pkg/lint/checks/workloads/notebook/verbose_formatter.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| package notebook | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "github.com/opendatahub-io/odh-cli/pkg/lint/check/result" | ||
| ) | ||
|
|
||
| // NotebookVerboseFormatter provides a namespace-grouped rendering for impacted objects | ||
| // in verbose table output. Embed this in any check struct to get a default | ||
| // FormatVerboseOutput that lists objects grouped by namespace with requester info | ||
| // and CRD-qualified resource names. | ||
| // | ||
| // Output format: | ||
| // | ||
| // namespace: <ns> | requester: <email> | ||
| // - <resource>.<group>/<name> | ||
| // - <resource>.<group>/<name> | ||
| // | ||
| // The CRD FQN (e.g. "notebooks.kubeflow.org") is read from the DiagnosticResult's | ||
| // AnnotationResourceCRDName annotation, which is automatically set by SetImpactedObjects | ||
| // and AddImpactedObjects. This makes the formatter adoptable by any resource type | ||
| // without hardcoding. | ||
| // | ||
| // Checks that need custom formatting (e.g. ImpactedWorkloadsCheck groups by image) | ||
| // should define their own FormatVerboseOutput method instead. | ||
| type NotebookVerboseFormatter struct { | ||
| // NamespaceRequesters maps namespace names to their openshift.io/requester annotation value. | ||
| // Populated automatically by the output renderer before FormatVerboseOutput is called. | ||
| NamespaceRequesters map[string]string | ||
| } | ||
|
|
||
| // SetNamespaceRequesters sets the namespace-to-requester mapping. | ||
| // Called by the output renderer before FormatVerboseOutput. | ||
| func (f *NotebookVerboseFormatter) SetNamespaceRequesters(m map[string]string) { | ||
| f.NamespaceRequesters = m | ||
| } | ||
|
|
||
| // FormatVerboseOutput implements check.VerboseOutputFormatter. | ||
| // Renders impacted objects grouped by namespace with requester info and CRD FQN. | ||
| func (f *NotebookVerboseFormatter) FormatVerboseOutput(out io.Writer, dr *result.DiagnosticResult) { | ||
| crdName := crdFQN(dr) | ||
|
|
||
| nsMap := make(map[string][]string) | ||
| for _, obj := range dr.ImpactedObjects { | ||
| nsMap[obj.Namespace] = append(nsMap[obj.Namespace], obj.Name) | ||
| } | ||
|
|
||
| namespaces := make([]string, 0, len(nsMap)) | ||
| for ns := range nsMap { | ||
| namespaces = append(namespaces, ns) | ||
| } | ||
| sort.Strings(namespaces) | ||
|
|
||
| for idx, ns := range namespaces { | ||
| names := make([]string, len(nsMap[ns])) | ||
| copy(names, nsMap[ns]) | ||
| sort.Strings(names) | ||
|
|
||
| if ns == "" { | ||
| // Cluster-scoped objects listed without namespace header. | ||
| for _, name := range names { | ||
| _, _ = fmt.Fprintf(out, " - %s/%s\n", crdName, name) | ||
| } | ||
| } else { | ||
| nsHeader := "namespace: " + ns | ||
| if f.NamespaceRequesters != nil { | ||
| if requester, ok := f.NamespaceRequesters[ns]; ok && requester != "" { | ||
| nsHeader = fmt.Sprintf("namespace: %s | requester: %s", ns, requester) | ||
| } | ||
| } | ||
|
|
||
| _, _ = fmt.Fprintf(out, " %s\n", nsHeader) | ||
| for _, name := range names { | ||
| _, _ = fmt.Fprintf(out, " - %s/%s\n", crdName, name) | ||
| } | ||
| } | ||
|
|
||
| // Blank line between namespace groups (except after last). | ||
| if idx < len(namespaces)-1 { | ||
| _, _ = fmt.Fprintln(out) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // crdFQN returns the CRD fully-qualified name for the impacted objects in a DiagnosticResult. | ||
| // It first checks the AnnotationResourceCRDName annotation (automatically set by SetImpactedObjects | ||
| // and AddImpactedObjects from ResourceType.CRDFQN()). Falls back to deriving the FQN from the | ||
| // first impacted object's TypeMeta if the annotation is absent. | ||
| func crdFQN(dr *result.DiagnosticResult) string { | ||
| // Prefer the annotation set by SetImpactedObjects — uses ResourceType.Resource | ||
| // for the correct plural form (e.g. "inferenceservices", not "inferenceservices" from naive pluralization). | ||
| if name, ok := dr.Annotations[result.AnnotationResourceCRDName]; ok && name != "" { | ||
| return name | ||
| } | ||
|
|
||
| // Fallback: derive from TypeMeta (for callers that set ImpactedObjects directly). | ||
| return deriveCRDFQNFromTypeMeta(dr.ImpactedObjects) | ||
| } | ||
|
|
||
| // deriveCRDFQNFromTypeMeta derives the CRD FQN from the first impacted object's TypeMeta. | ||
| // For example, APIVersion "kubeflow.org/v1" with Kind "Notebook" produces "notebooks.kubeflow.org". | ||
| // Falls back to the lowercase Kind if TypeMeta is not populated. | ||
| func deriveCRDFQNFromTypeMeta(objects []metav1.PartialObjectMetadata) string { | ||
| if len(objects) == 0 { | ||
| return "" | ||
| } | ||
|
|
||
| obj := objects[0] | ||
|
|
||
| kind := obj.Kind | ||
| if kind == "" { | ||
| return "" | ||
| } | ||
|
|
||
| // Kubernetes CRD plural convention: lowercase kind + "s" | ||
| // (e.g. Notebook → notebooks, InferenceService → inferenceservices, RayCluster → rayclusters). | ||
| plural := strings.ToLower(kind) + "s" | ||
|
|
||
| // Extract API group from APIVersion (e.g. "kubeflow.org/v1" → "kubeflow.org"). | ||
| // Core resources have no group (APIVersion is just "v1"), so return plural only. | ||
| apiVersion := obj.APIVersion | ||
| if apiVersion == "" { | ||
| return plural | ||
| } | ||
|
|
||
| group, _, found := strings.Cut(apiVersion, "/") | ||
| if !found { | ||
| // Core API (e.g. "v1") — no group prefix. | ||
| return plural | ||
| } | ||
|
|
||
| return plural + "." + group | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.