77 corev1 "k8s.io/api/core/v1"
88 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
99 "k8s.io/apimachinery/pkg/runtime"
10-
11- rlconfig "github.com/stacklok/toolhive/pkg/ratelimit/config"
1210)
1311
1412// Condition types for MCPServer
@@ -513,26 +511,26 @@ type SessionStorageConfig struct {
513511type RateLimitConfig struct {
514512 // Global is a token bucket shared across all users for the entire server.
515513 // +optional
516- Global * RateLimitBucket `json:"global,omitempty"`
514+ Global * RateLimitBucket `json:"global,omitempty" yaml:"global,omitempty" `
517515
518516 // Shared is a deprecated alias for Global. Use global instead.
519517 // +optional
520- Shared * RateLimitBucket `json:"shared,omitempty"`
518+ Shared * RateLimitBucket `json:"shared,omitempty" yaml:"shared,omitempty" `
521519
522520 // PerUser is a token bucket applied independently to each authenticated user
523521 // at the server level. Requires authentication to be enabled.
524522 // Each unique userID creates Redis keys that expire after 2x refillPeriod.
525523 // Memory formula: unique_users_per_TTL_window * (1 + num_tools_with_per_user_limits) keys.
526524 // +optional
527- PerUser * RateLimitBucket `json:"perUser,omitempty"`
525+ PerUser * RateLimitBucket `json:"perUser,omitempty" yaml:"perUser,omitempty" `
528526
529527 // Tools defines per-tool rate limit overrides.
530528 // Each entry applies additional rate limits to calls targeting a specific tool name.
531529 // A request must pass both the server-level limit and the per-tool limit.
532530 // +listType=map
533531 // +listMapKey=name
534532 // +optional
535- Tools []ToolRateLimitConfig `json:"tools,omitempty"`
533+ Tools []ToolRateLimitConfig `json:"tools,omitempty" yaml:"tools,omitempty" `
536534}
537535
538536// RateLimitBucket defines a token bucket configuration with a maximum capacity
@@ -543,13 +541,13 @@ type RateLimitBucket struct {
543541 // instantaneously before the bucket is depleted.
544542 // +kubebuilder:validation:Required
545543 // +kubebuilder:validation:Minimum=1
546- MaxTokens int32 `json:"maxTokens"`
544+ MaxTokens int32 `json:"maxTokens" yaml:"maxTokens" `
547545
548546 // RefillPeriod is the duration to fully refill the bucket from zero to maxTokens.
549547 // The effective refill rate is maxTokens / refillPeriod tokens per second.
550548 // Format: Go duration string (e.g., "1m0s", "30s", "1h0m0s").
551549 // +kubebuilder:validation:Required
552- RefillPeriod metav1.Duration `json:"refillPeriod"`
550+ RefillPeriod metav1.Duration `json:"refillPeriod" yaml:"refillPeriod" `
553551}
554552
555553// ToolRateLimitConfig defines rate limits for a specific tool.
@@ -562,53 +560,19 @@ type ToolRateLimitConfig struct {
562560 // Name is the MCP tool name this limit applies to.
563561 // +kubebuilder:validation:Required
564562 // +kubebuilder:validation:MinLength=1
565- Name string `json:"name"`
563+ Name string `json:"name" yaml:"name" `
566564
567565 // Global token bucket for this specific tool.
568566 // +optional
569- Global * RateLimitBucket `json:"global,omitempty"`
567+ Global * RateLimitBucket `json:"global,omitempty" yaml:"global,omitempty" `
570568
571569 // Shared is a deprecated alias for Global. Use global instead.
572570 // +optional
573- Shared * RateLimitBucket `json:"shared,omitempty"`
571+ Shared * RateLimitBucket `json:"shared,omitempty" yaml:"shared,omitempty" `
574572
575573 // PerUser token bucket configuration for this tool.
576574 // +optional
577- PerUser * RateLimitBucket `json:"perUser,omitempty"`
578- }
579-
580- // ToInternal converts the Kubernetes API rate limit config to the runtime-neutral representation.
581- func (in * RateLimitConfig ) ToInternal () * rlconfig.Config {
582- if in == nil {
583- return nil
584- }
585- out := & rlconfig.Config {
586- Global : rateLimitBucketToInternal (in .Global ),
587- Shared : rateLimitBucketToInternal (in .Shared ),
588- PerUser : rateLimitBucketToInternal (in .PerUser ),
589- }
590- if len (in .Tools ) > 0 {
591- out .Tools = make ([]rlconfig.ToolConfig , 0 , len (in .Tools ))
592- for _ , tool := range in .Tools {
593- out .Tools = append (out .Tools , rlconfig.ToolConfig {
594- Name : tool .Name ,
595- Global : rateLimitBucketToInternal (tool .Global ),
596- Shared : rateLimitBucketToInternal (tool .Shared ),
597- PerUser : rateLimitBucketToInternal (tool .PerUser ),
598- })
599- }
600- }
601- return out
602- }
603-
604- func rateLimitBucketToInternal (in * RateLimitBucket ) * rlconfig.Bucket {
605- if in == nil {
606- return nil
607- }
608- return & rlconfig.Bucket {
609- MaxTokens : in .MaxTokens ,
610- RefillPeriod : in .RefillPeriod ,
611- }
575+ PerUser * RateLimitBucket `json:"perUser,omitempty" yaml:"perUser,omitempty"`
612576}
613577
614578// Permission profile types
0 commit comments