fix: correct CRD type mismatches and add omitempty to status fields#4571
Open
sharanrajt wants to merge 2 commits intostacklok:mainfrom
Open
fix: correct CRD type mismatches and add omitempty to status fields#4571sharanrajt wants to merge 2 commits intostacklok:mainfrom
sharanrajt wants to merge 2 commits intostacklok:mainfrom
Conversation
jerm-dro
previously approved these changes
Apr 6, 2026
Contributor
jerm-dro
left a comment
There was a problem hiding this comment.
nitpick: The PR description lists several changes that aren't in the diff — switching PgpassSecretRef to SecretKeyReference, adding omitempty to User/Password, and a safeIntToInt64 helper. The actual code does an inline bounds check instead of a helper, and the other two changes don't appear at all. Could you trim the description to match what's actually here? Makes it easier for reviewers (and future git-log readers) to understand the scope.
The actual changes fully address both #4544 and #4537 — looks good.
Author
|
Thanks for the review, I have updated the PR description to match the actual diff. Let me know if anything else needs adjusting! |
Add omitempty to servers and serverCount JSON tags in MCPGroupStatus so optional fields are omitted from serialized output when empty, consistent with other optional fields in the struct. Fixes stacklok#4537
The VirtualMCPServerStatus.BackendCount CRD field is int32, but test assertions compared it against int values, causing testify's assert.Equal to fail on type mismatch. Update the test struct's backendCount field to int32 and use int32 literals in direct assertions to match the CRD type. Fixes stacklok#4544
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
intis platform-dependent (32- or 64-bit), but Kubernetes CRD integer fields should use explicitly sized types (int32/int64). Several CRD structs (VirtualMCPServerStatus.BackendCount,MCPRegistryDatabaseConfig.Port/MaxOpenConns/MaxIdleConns,SyncStatus.AttemptCount/ServerCount) used bareint, producing an imprecise OpenAPI schema and causingtestifytype-mismatch failures.MCPGroupStatus.ServersandMCPGroupStatus.ServerCountlackedomitemptyon their JSON tags, causing zero-value fields to always appear in serialised status payloads.What changed:
BackendCount,Port,MaxOpenConns,MaxIdleConns,AttemptCount, andServerCountfrominttoint32in CRD typesGetDatabasePort()return type toint32math.MaxInt32) ink8s_reporter.gobefore casting toint32int()/int32()casts at all call sites to satisfy the new typesformat: int32added to affected fields)int32literals andBeEquivalentTomatcheromitemptytoServersandServerCountJSON tags inMCPGroupStatusFixes #4544
Fixes #4537
Type of change
Test plan
task test)task test-e2e)task lint-fix)Changes
cmd/thv-operator/api/v1alpha1/mcpgroup_types.goomitemptytoServersandServerCountJSON tagscmd/thv-operator/api/v1alpha1/mcpregistry_types.goPort,MaxOpenConns,MaxIdleConns,AttemptCount,ServerCountfrominttoint32; updateGetDatabasePort()return typecmd/thv-operator/api/v1alpha1/virtualmcpserver_types.goBackendCountfrominttoint32cmd/thv-operator/pkg/registryapi/config/config.goint()casts when assigningint32CRD fields to internal configcmd/thv-operator/pkg/registryapi/pgpass_test.goint32in test helpercmd/thv-operator/pkg/virtualmcpserverstatus/collector.goreadyCounttoint32when assigningBackendCountcmd/thv-operator/test-integration/mcp-registry/status_helpers.goSyncStatus.ServerCounttointfor Gomega comparisondeploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_mcpregistries.yamlformat: int32toport,maxOpenConns,maxIdleConns,attemptCount,serverCountdeploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_virtualmcpservers.yamlformat: int32tobackendCountdeploy/charts/operator-crds/templates/toolhive.stacklok.dev_mcpregistries.yamldeploy/charts/operator-crds/templates/toolhive.stacklok.dev_virtualmcpservers.yamlpkg/vmcp/status/k8s_reporter.gomathimport; inline bounds check capping atMaxInt32beforeint32castpkg/vmcp/status/k8s_reporter_test.gobackendCountfield toint32; update loop variable, assertions, andLencallstest/e2e/thv-operator/virtualmcp/virtualmcp_yardstick_base_test.goBeEquivalentTo(2)instead ofEqual(2)forBackendCountDoes this introduce a user-facing change?
No. The serialised status output becomes cleaner (zero-value MCPGroupStatus fields now omitted), and the CRD OpenAPI schema is more precise (
format: int32), but API semantics are unchanged.Special notes for reviewers
nolint:goseccomments onint32()casts are guarded by an explicitmath.MaxInt32bounds check ink8s_reporter.go, or are inherently safe because the values are small counts (backend count, connection pool sizes).Equal(2)toBeEquivalentTo(2)to avoid Gomega's strict type matching betweenintandint32.