Skip to content

Conversation

@dittops
Copy link
Member

@dittops dittops commented Dec 21, 2025

Summary

  • Fixes namespace length exceeding Kubernetes 63 character limit when benchmark names are too long
  • Adds multi-layer validation for benchmark names (max 50 characters)
  • Improves error handling to display API validation errors to users

Changes

Backend (budcluster)

  • deployment/handler.py: Fixed _get_namespace() to truncate endpoint names to 50 chars max, remove consecutive hyphens, and ensure namespace stays within 63 char limit
  • benchmark_ops/schemas.py: Added max_length=50 validation to benchmark name field

Backend (budapp)

  • benchmark_ops/schemas.py: Added max_length=50 validation to benchmark name field

Frontend (budadmin)

  • AddBenchmark.tsx: Added maxLength={50} prop and validation rule for benchmark name input
  • TextInput.tsx: Added maxLength prop support to the component
  • usePerfomanceBenchmark.tsx: Added proper error handling to display API validation errors as toast notifications

Test plan

  • Create a benchmark with a name longer than 50 characters - should be blocked by frontend
  • Verify API returns proper validation error for names > 50 chars
  • Verify toast notification appears when API validation fails
  • Create a benchmark with a valid name (≤50 chars) - should work normally
  • Redeploy budcluster and verify namespace truncation works for long names

🤖 Generated with Claude Code

- Fix _get_namespace() to truncate endpoint names to 50 chars max
- Add consecutive hyphen removal and cleanup in namespace generation
- Add max_length=50 validation to benchmark name schemas (budapp, budcluster)
- Add frontend validation with maxLength prop and error toast display
- Prevents Ansible failures when deploying benchmarks with long names

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dittops, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where long benchmark names could lead to Kubernetes namespace names exceeding the 63-character limit, causing deployment failures. The solution involves a comprehensive, multi-layered approach to enforce a 50-character limit for benchmark names, ensuring that the generated Kubernetes namespaces remain within acceptable bounds. Additionally, the changes improve the user experience by providing clearer feedback through enhanced error handling for API validation failures.

Highlights

  • Kubernetes Namespace Length Enforcement: Implemented a fix to ensure Kubernetes namespace names generated from benchmark names adhere to the 63-character limit, preventing deployment failures for long benchmark names.
  • Multi-Layer Benchmark Name Validation: Introduced a 50-character maximum length validation for benchmark names across the frontend UI, backend API schemas (budapp and budcluster), and the namespace generation logic.
  • Improved API Error Handling: Enhanced the frontend error handling to properly parse and display API validation errors as user-friendly toast notifications, improving the user experience.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively enforces the 63-character limit for Kubernetes namespaces by adding validation on multiple layers (frontend, backend schemas) and implementing robust truncation logic on the backend. The improved error handling on the frontend to display API validation errors is also a great addition.

I've provided two suggestions:

  • A high-severity fix in deployment/handler.py to handle edge cases in namespace generation that could lead to invalid names.
  • A medium-severity refactoring suggestion in usePerfomanceBenchmark.tsx to improve the clarity and maintainability of the new error handling logic.

Overall, this is a solid and well-thought-out fix.

Comment on lines 75 to 77
if len(cleaned_name) > max_name_length:
cleaned_name = cleaned_name[:max_name_length].rstrip("-")
return f"bud-{cleaned_name}-{unique_id}"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current logic has two edge cases that can produce invalid Kubernetes namespaces:

  1. Names shorter than 50 chars but ending with a hyphen are not handled, leading to invalid names like bud-my-name--... because the rstrip is only inside the if block for long names.
  2. Empty names after cleaning (e.g., from input _) result in invalid names like bud--....

The suggested change makes the truncation and cleaning more robust to handle these cases by always stripping trailing hyphens and providing a fallback for empty names.

Suggested change
if len(cleaned_name) > max_name_length:
cleaned_name = cleaned_name[:max_name_length].rstrip("-")
return f"bud-{cleaned_name}-{unique_id}"
cleaned_name = cleaned_name[:max_name_length].rstrip("-")
if not cleaned_name:
cleaned_name = "benchmark"
return f"bud-{cleaned_name}-{unique_id}"

Comment on lines 484 to 501
// Handle validation errors from API (Pydantic 422 errors)
if (error?.response?.data?.detail) {
const details = error.response.data.detail;
if (Array.isArray(details)) {
const messages = details.map((d: any) => d.msg || d.message).join(", ");
errorToast(messages || "Validation error");
} else if (typeof details === "string") {
errorToast(details);
} else {
errorToast("Validation error");
}
} else if (error?.response?.data?.message) {
errorToast(error.response.data.message);
} else if (error?.message) {
errorToast(error.message);
} else {
errorToast("Failed to create benchmark");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error handling logic is a bit verbose with multiple errorToast calls inside the if/else chain. This can be refactored to be more concise and maintainable by first determining the error message and then calling errorToast once at the end.

Suggested change
// Handle validation errors from API (Pydantic 422 errors)
if (error?.response?.data?.detail) {
const details = error.response.data.detail;
if (Array.isArray(details)) {
const messages = details.map((d: any) => d.msg || d.message).join(", ");
errorToast(messages || "Validation error");
} else if (typeof details === "string") {
errorToast(details);
} else {
errorToast("Validation error");
}
} else if (error?.response?.data?.message) {
errorToast(error.response.data.message);
} else if (error?.message) {
errorToast(error.message);
} else {
errorToast("Failed to create benchmark");
}
// Handle validation errors from API (Pydantic 422 errors)
let errorMessage = "Failed to create benchmark";
const detail = error?.response?.data?.detail;
if (detail) {
if (Array.isArray(detail)) {
errorMessage = detail.map((d: any) => d.msg || d.message).join(", ") || "Validation error";
} else if (typeof detail === "string") {
errorMessage = detail;
} else {
errorMessage = "Validation error";
}
} else if (error?.response?.data?.message) {
errorMessage = error.response.data.message;
} else if (error?.message) {
errorMessage = error.message;
}
errorToast(errorMessage);

- Always truncate and strip trailing hyphens from namespace names
- Add fallback to "benchmark" for empty names after cleaning
- Refactor error handling to be more concise with single errorToast call
- Fix ruff formatting: add blank lines before module-level constants

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dittops dittops merged commit ea13648 into master Dec 21, 2025
11 checks passed
@dittops dittops deleted the fix/benchmark-namespace-length-validation branch January 1, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants