Skip to content

fix: expose the actual model name instead of the resource name#143

Merged
openshift-merge-bot[bot] merged 9 commits intoopendatahub-io:mainfrom
mholder6:maas-api/fix/model-name
Oct 10, 2025
Merged

fix: expose the actual model name instead of the resource name#143
openshift-merge-bot[bot] merged 9 commits intoopendatahub-io:mainfrom
mholder6:maas-api/fix/model-name

Conversation

@mholder6
Copy link
Copy Markdown
Contributor

@mholder6 mholder6 commented Oct 7, 2025

follow-up to PR #88 - This fixes the bug in /v1/models listing. Previously, the /v1/models endpoint incorrectly used the resource name [metadata.name] instead of the actual model name.

This fix populates .spec.model.name from LLMInferenceService, and if spec.model.name is not specified, it should fall back to use metadata.name, as it aligns with the behaviour of LLMInferenceService controller.

Summary by CodeRabbit

  • New Features

    • Model IDs now prefer a model name provided in a deployment spec; if absent they fall back to the resource name. URL-related error logs include namespace/name for clearer diagnostics.
  • Tests

    • Test fixtures and scenarios expanded to cover overridden and empty spec model names and to verify ID selection and readiness behavior.

@openshift-ci openshift-ci bot requested review from SB159 and bartoszmajsak October 7, 2025 13:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Prefer spec.model.name as the model ID for KServe InferenceService objects, falling back to metadata.name when missing; log read errors and include namespace/name in URL-retrieval error messages. Add test coverage and fixture support for optionally specifying spec.model.name via functional options and a local strptr test helper.

Changes

Cohort / File(s) Summary
Model conversion logic
maas-api/internal/models/kserve.go
toModels derives modelID defaulting to item.GetName() but overrides it with spec.model.name when present (reads from the unstructured object). Read errors are logged and processing continues. URL-retrieval error logs now include namespace/name.
Handler tests
maas-api/internal/handlers/models_test.go
Adds local helper strptr and a new test scenario "fallback-model-name" that sets SpecModelName (pointer), URL, and Ready=true. Adjusts assertions to expect Model.ID from spec.model.name when provided.
Test fixtures / API
maas-api/test/fixtures/llm_models.go
Adds functional-options pattern: LLMInferenceServiceOption type and WithSpecModelName(name string) option. CreateLLMInferenceService accepts opts ...LLMInferenceServiceOption and applies them. LLMTestScenario gains SpecModelName *string; CreateLLMInferenceServices passes per-scenario options.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Caller
  participant Handler as ModelsHandler
  participant KS as KServe API
  participant Conv as toModels()

  Client->>Handler: GET /models
  Handler->>KS: List InferenceServices
  KS-->>Handler: Items[]
  Handler->>Conv: Convert Items to []Model

  rect rgba(220,235,255,0.25)
    note right of Conv: For each InferenceService item
    Conv->>Conv: Read spec.model.name (unstructured)
    alt spec.model.name present & non-empty
      Conv->>Conv: modelID = spec.model.name
    else spec.model.name missing/empty or read error
      Conv->>Conv: Log read issue (if any)\nmodelID = metadata.name
    end
    Conv->>Conv: Derive URL from status/annotations
    alt URL retrieval fails
      Conv->>Conv: Log error including namespace/name
    end
    Conv-->>Handler: Append Model{ID: modelID, URL, Ready}
  end

  Handler-->>Client: 200 OK, []Model
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my nose at names that hide,
I peek in spec where secrets bide.
A helper here, an option there,
Tests now prove the name we share.
Hops of joy — logs crisp and bright 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the core fix by indicating that the actual model name will be exposed instead of the resource name, directly reflecting the changes to use spec.model.name with a metadata fallback; it is clear, concise, and focuses on the primary behavioral change introduced by the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 867e0cf and 97d5c85.

📒 Files selected for processing (1)
  • maas-api/internal/handlers/models_test.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • maas-api/internal/handlers/models_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mholder6 mholder6 changed the title (fix):Expose the actual model name instead of the resource name fix:Expose the actual model name instead of the resource name Oct 7, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18fb484 and 72e4c40.

📒 Files selected for processing (2)
  • maas-api/internal/handlers/models_test.go (4 hunks)
  • maas-api/internal/models/kserve.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
maas-api/internal/models/kserve.go (1)
maas-api/internal/models/types.go (1)
  • Model (14-18)
maas-api/internal/handlers/models_test.go (2)
maas-api/test/fixtures/const.go (1)
  • TestNamespace (4-4)
maas-api/internal/models/types.go (1)
  • Model (14-18)
🪛 GitHub Actions: MaaS API
maas-api/internal/handlers/models_test.go

[error] 81-81: Go test failed: cannot use unsetSpecModelNameISVC (variable of type unstructured.Unstructured) as "k8s.io/apimachinery/pkg/runtime.Object" value in argument to append: unstructured.Unstructured does not implement runtime.Object (DeepCopyObject has a pointer receiver).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Validate PR Title
🔇 Additional comments (5)
maas-api/internal/models/kserve.go (3)

81-83: LGTM! Enhanced error logging.

The addition of namespace, name, and kind to the error log message improves debuggability when URL retrieval fails.


85-94: LGTM! Model ID derivation logic is correct.

The implementation properly:

  • Defaults to metadata.name when spec.model.name is absent
  • Overrides with spec.model.name when present
  • Logs errors without disrupting the flow
  • Uses appropriate error context (kind, namespace, name)

This aligns with the PR objective to expose the actual model name.


98-98: LGTM! Correctly uses the derived model ID.

The change from item.GetName() to modelID ensures the Model.ID field reflects either spec.model.name (when present) or metadata.name (as fallback).

maas-api/internal/handlers/models_test.go (2)

8-8: LGTM! Required imports added.

The time and unstructured imports are necessary for constructing the test object with spec.model.name unset.

Also applies to: 17-17


134-146: LGTM! Test expectations correctly validate the fallback behavior.

The test case properly verifies that when spec.model.name is absent, the model ID defaults to metadata.name (unsetSpecModelName). The expected model structure and assertions are correct.

Comment on lines +56 to +81
//Add a model where .spec.model.name is unset; should default to metadata.name
unsetSpecModelName := "unset-spec-model-name"
unsetSpecModelNameNamespace := fixtures.TestNamespace

unsetSpecModelNameISVC := unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "serving.kserve.io/v1beta1",
"kind": "InferenceService",
"metadata": map[string]any{
"name": unsetSpecModelName,
"namespace": unsetSpecModelNameNamespace,
"creationTimestamp": time.Now().UTC().Format(time.RFC3339),
},
"spec": map[string]any{
"model": map[string]any{
//left out the "name" key
},
},
"status": map[string]any{
"url": "http://" + unsetSpecModelName + "." + unsetSpecModelNameNamespace + ".acme.com/v1",
},
},
}

// Append the model to the objects used by the fake server
llmInferenceServices = append(llmInferenceServices, unsetSpecModelNameISVC)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need to use LLMInferenceService not InferenceService

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can reuse CreateLLMInferenceService to create the object

mholder6 and others added 4 commits October 7, 2025 09:28
@mholder6 mholder6 changed the title fix:Expose the actual model name instead of the resource name draft:Expose the actual model name instead of the resource name Oct 7, 2025
@mholder6 mholder6 changed the title draft:Expose the actual model name instead of the resource name fix:Expose the actual model name instead of the resource name Oct 9, 2025
@pierDipi pierDipi changed the title fix:Expose the actual model name instead of the resource name fix: Expose the actual model name instead of the resource name Oct 9, 2025
@mholder6 mholder6 changed the title fix: Expose the actual model name instead of the resource name fix: Expose the actual model name instead of the resource name. Oct 9, 2025
@mholder6 mholder6 changed the title fix: Expose the actual model name instead of the resource name. fix: expose the actual model name instead of the resource name. Oct 9, 2025
@mholder6 mholder6 changed the title fix: expose the actual model name instead of the resource name. fix: expose the actual model name instead of the resource name Oct 9, 2025
@pierDipi
Copy link
Copy Markdown
Member

pierDipi commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

@jland-redhat jland-redhat left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@nerdalert nerdalert left a comment

Choose a reason for hiding this comment

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

LGTM ty

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Oct 9, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jland-redhat, mholder6, nerdalert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [jland-redhat,nerdalert]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Co-authored-by: Edgar Hernández <ehernand@redhat.com>
@openshift-ci openshift-ci bot removed the lgtm label Oct 10, 2025
@israel-hdez
Copy link
Copy Markdown
Collaborator

/label tide/merge-method-squash

@israel-hdez
Copy link
Copy Markdown
Collaborator

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Oct 10, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit a285d66 into opendatahub-io:main Oct 10, 2025
8 checks passed
SB159 pushed a commit to SB159/maas-billing that referenced this pull request Oct 15, 2025
…atahub-io#143)

* expose the actual model name instead of the resource name for the /v1/models endpoint

* Update maas-api/internal/models/kserve.go

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>

* updated testing isvc to be llmisvc

* typo

* squash

* Update maas-api/internal/handlers/models_test.go

Co-authored-by: Edgar Hernández <ehernand@redhat.com>

* updated the test to test the fallback logic instead

---------

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
Co-authored-by: Edgar Hernández <ehernand@redhat.com>
liangwen12year pushed a commit to liangwen12year/maas-billing that referenced this pull request Dec 10, 2025
…konflux-fix

fix: align Dockerfile.konflux with upstream (add FIPS compliance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants