Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/thv-operator/api/v1alpha1/mcpgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type MCPGroupStatus struct {

// Servers lists MCPServer names in this group
// +optional
Servers []string `json:"servers"`
Servers []string `json:"servers,omitempty"`

// ServerCount is the number of MCPServers
// +optional
ServerCount int `json:"serverCount"`
ServerCount int `json:"serverCount,omitempty"`

// RemoteProxies lists MCPRemoteProxy names in this group
// +optional
Expand Down
12 changes: 6 additions & 6 deletions cmd/thv-operator/api/v1alpha1/mcpregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ type MCPRegistryDatabaseConfig struct {
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +optional
Port int `json:"port,omitempty"`
Port int32 `json:"port,omitempty"`

// User is the application user (limited privileges: SELECT, INSERT, UPDATE, DELETE)
// Credentials should be provided via pgpass file or environment variables
Expand Down Expand Up @@ -324,13 +324,13 @@ type MCPRegistryDatabaseConfig struct {
// +kubebuilder:default=10
// +kubebuilder:validation:Minimum=1
// +optional
MaxOpenConns int `json:"maxOpenConns,omitempty"`
MaxOpenConns int32 `json:"maxOpenConns,omitempty"`

// MaxIdleConns is the maximum number of idle connections in the pool
// +kubebuilder:default=2
// +kubebuilder:validation:Minimum=0
// +optional
MaxIdleConns int `json:"maxIdleConns,omitempty"`
MaxIdleConns int32 `json:"maxIdleConns,omitempty"`

// ConnMaxLifetime is the maximum amount of time a connection may be reused (Go duration format)
// Examples: "30m", "1h", "24h"
Expand Down Expand Up @@ -541,7 +541,7 @@ type SyncStatus struct {
// AttemptCount is the number of sync attempts since last success
// +optional
// +kubebuilder:validation:Minimum=0
AttemptCount int `json:"attemptCount,omitempty"`
AttemptCount int32 `json:"attemptCount,omitempty"`

// LastSyncTime is the timestamp of the last successful sync
// +optional
Expand All @@ -555,7 +555,7 @@ type SyncStatus struct {
// ServerCount is the total number of servers in the registry
// +optional
// +kubebuilder:validation:Minimum=0
ServerCount int `json:"serverCount,omitempty"`
ServerCount int32 `json:"serverCount,omitempty"`
}

// APIStatus provides detailed information about the API service
Expand Down Expand Up @@ -823,7 +823,7 @@ func (r *MCPRegistry) GetDatabaseConfig() *MCPRegistryDatabaseConfig {
// If the port is not specified, it returns 5432.
// We do this because its likely to be 5432 due to
// it being the default port for PostgreSQL.
func (r *MCPRegistry) GetDatabasePort() int {
func (r *MCPRegistry) GetDatabasePort() int32 {
if r.Spec.DatabaseConfig == nil || r.Spec.DatabaseConfig.Port == 0 {
return 5432
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thv-operator/api/v1alpha1/virtualmcpserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ type VirtualMCPServerStatus struct {
// BackendCount is the number of healthy/ready backends
// (excludes unavailable, degraded, and unknown backends)
// +optional
BackendCount int `json:"backendCount,omitempty"`
BackendCount int32 `json:"backendCount,omitempty"`

// OIDCConfigHash is the hash of the referenced MCPOIDCConfig spec for change detection.
// Only populated when IncomingAuth.OIDCConfigRef is set.
Expand Down
6 changes: 3 additions & 3 deletions cmd/thv-operator/pkg/registryapi/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func buildDatabaseConfig(dbConfig *mcpv1alpha1.MCPRegistryDatabaseConfig) *Datab
config.Host = dbConfig.Host
}
if dbConfig.Port != 0 {
config.Port = dbConfig.Port
config.Port = int(dbConfig.Port)
}
if dbConfig.User != "" {
config.User = dbConfig.User
Expand All @@ -608,10 +608,10 @@ func buildDatabaseConfig(dbConfig *mcpv1alpha1.MCPRegistryDatabaseConfig) *Datab
config.SSLMode = dbConfig.SSLMode
}
if dbConfig.MaxOpenConns != 0 {
config.MaxOpenConns = dbConfig.MaxOpenConns
config.MaxOpenConns = int(dbConfig.MaxOpenConns)
}
if dbConfig.MaxIdleConns != 0 {
config.MaxIdleConns = dbConfig.MaxIdleConns
config.MaxIdleConns = int(dbConfig.MaxIdleConns)
}
if dbConfig.ConnMaxLifetime != "" {
config.ConnMaxLifetime = dbConfig.ConnMaxLifetime
Expand Down
2 changes: 1 addition & 1 deletion cmd/thv-operator/pkg/registryapi/pgpass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func baseMCPRegistry(t *testing.T, opts ...func(*mcpv1alpha1.MCPRegistry)) *mcpv
}

func withPort(port int) func(*mcpv1alpha1.MCPRegistry) {
return func(r *mcpv1alpha1.MCPRegistry) { r.Spec.DatabaseConfig.Port = port }
return func(r *mcpv1alpha1.MCPRegistry) { r.Spec.DatabaseConfig.Port = int32(port) }
}

func withHost(host string) func(*mcpv1alpha1.MCPRegistry) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/thv-operator/pkg/virtualmcpserverstatus/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *StatusCollector) UpdateStatus(ctx context.Context, vmcpStatus *mcpv1alp
readyCount++
}
}
vmcpStatus.BackendCount = readyCount
vmcpStatus.BackendCount = int32(readyCount)
}

ctxLogger.V(1).Info("Batched status update applied",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (h *StatusTestHelper) WaitForServerCount(registryName string, expectedCount
if err != nil {
return -1
}
return status.SyncStatus.ServerCount
return int(status.SyncStatus.ServerCount)
}, timeout, time.Second).Should(gomega.Equal(expectedCount),
"MCPRegistry %s should have server count %d", registryName, expectedCount)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ spec:
default: 2
description: MaxIdleConns is the maximum number of idle connections
in the pool
format: int32
minimum: 0
type: integer
maxOpenConns:
default: 10
description: MaxOpenConns is the maximum number of open connections
to the database
format: int32
minimum: 1
type: integer
migrationUser:
Expand All @@ -354,6 +356,7 @@ spec:
port:
default: 5432
description: Port is the database server port
format: int32
maximum: 65535
minimum: 1
type: integer
Expand Down Expand Up @@ -814,6 +817,7 @@ spec:
attemptCount:
description: AttemptCount is the number of sync attempts since
last success
format: int32
minimum: 0
type: integer
lastAttempt:
Expand Down Expand Up @@ -849,6 +853,7 @@ spec:
serverCount:
description: ServerCount is the total number of servers in the
registry
format: int32
minimum: 0
type: integer
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,7 @@ spec:
description: |-
BackendCount is the number of healthy/ready backends
(excludes unavailable, degraded, and unknown backends)
format: int32
type: integer
conditions:
description: Conditions represent the latest available observations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,14 @@ spec:
default: 2
description: MaxIdleConns is the maximum number of idle connections
in the pool
format: int32
minimum: 0
type: integer
maxOpenConns:
default: 10
description: MaxOpenConns is the maximum number of open connections
to the database
format: int32
minimum: 1
type: integer
migrationUser:
Expand All @@ -357,6 +359,7 @@ spec:
port:
default: 5432
description: Port is the database server port
format: int32
maximum: 65535
minimum: 1
type: integer
Expand Down Expand Up @@ -817,6 +820,7 @@ spec:
attemptCount:
description: AttemptCount is the number of sync attempts since
last success
format: int32
minimum: 0
type: integer
lastAttempt:
Expand Down Expand Up @@ -852,6 +856,7 @@ spec:
serverCount:
description: ServerCount is the total number of servers in the
registry
format: int32
minimum: 0
type: integer
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,7 @@ spec:
description: |-
BackendCount is the number of healthy/ready backends
(excludes unavailable, degraded, and unknown backends)
format: int32
type: integer
conditions:
description: Conditions represent the latest available observations
Expand Down
8 changes: 7 additions & 1 deletion pkg/vmcp/status/k8s_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"log/slog"
"math"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -136,7 +137,12 @@ func (*K8sReporter) updateStatus(vmcpServer *mcpv1alpha1.VirtualMCPServer, statu
vmcpServer.Status.Message = status.Message

// Update backend count (only counts healthy/ready backends)
vmcpServer.Status.BackendCount = status.BackendCount
// Cap at MaxInt32 to prevent integer overflow (gosec G115)
backendCount := status.BackendCount
if backendCount > math.MaxInt32 {
backendCount = math.MaxInt32
}
vmcpServer.Status.BackendCount = int32(backendCount) //nolint:gosec // bounds checked above

// Update discovered backends
vmcpServer.Status.DiscoveredBackends = make([]mcpv1alpha1.DiscoveredBackend, 0, len(status.DiscoveredBackends))
Expand Down
10 changes: 5 additions & 5 deletions pkg/vmcp/status/k8s_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestK8sReporter_ReportStatus_Success(t *testing.T) {
name string
phase vmcptypes.Phase
expectedPhase mcpv1alpha1.VirtualMCPServerPhase
backendCount int
backendCount int32
conditionCount int
}{
{
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestK8sReporter_ReportStatus_Success(t *testing.T) {
}

// Add backends if specified
for i := 0; i < tt.backendCount; i++ {
for i := int32(0); i < tt.backendCount; i++ {
status.DiscoveredBackends = append(status.DiscoveredBackends, vmcptypes.DiscoveredBackend{
Name: fmt.Sprintf("backend-%d", i+1),
URL: "http://backend:8080",
Expand All @@ -146,7 +146,7 @@ func TestK8sReporter_ReportStatus_Success(t *testing.T) {
})
}
// Set backend count to match number of healthy backends
status.BackendCount = tt.backendCount
status.BackendCount = int(tt.backendCount)

// Add conditions if specified
for i := 0; i < tt.conditionCount; i++ {
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestK8sReporter_ReportStatus_Success(t *testing.T) {

// Verify backend count
assert.Equal(t, tt.backendCount, updated.Status.BackendCount)
assert.Len(t, updated.Status.DiscoveredBackends, tt.backendCount)
assert.Len(t, updated.Status.DiscoveredBackends, int(tt.backendCount))

// Verify conditions
assert.Len(t, updated.Status.Conditions, tt.conditionCount)
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestK8sReporter_ReportStatus_ConcurrentUpdates(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, "Update 5", updated.Status.Message)
assert.Equal(t, 1, updated.Status.BackendCount)
assert.Equal(t, int32(1), updated.Status.BackendCount)
assert.Equal(t, "backend-5", updated.Status.DiscoveredBackends[0].Name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ var _ = Describe("VirtualMCPServer Yardstick Base", Ordered, func() {
It("should have two discovered backends initially", func() {
status, err := GetVirtualMCPServerStatus(ctx, k8sClient, vmcpServerName, testNamespace)
Expect(err).ToNot(HaveOccurred())
Expect(status.BackendCount).To(Equal(2), "Should have 2 initial backends")
Expect(status.BackendCount).To(BeEquivalentTo(2), "Should have 2 initial backends")
Expect(status.DiscoveredBackends).To(HaveLen(2), "Should have 2 discovered backends")

backendNames := make([]string, len(status.DiscoveredBackends))
Expand Down