Skip to content

Commit fa63118

Browse files
docs: add function documentation comments across codebase test and controller files
1 parent 22c9c13 commit fa63118

13 files changed

Lines changed: 90 additions & 2 deletions

api/v1alpha1/agentdeployment_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ type AgentDeploymentList struct {
234234
Items []AgentDeployment `json:"items"`
235235
}
236236

237+
// init registers AgentDeployment and AgentDeploymentList types with the SchemeBuilder.
237238
func init() {
238239
SchemeBuilder.Register(&AgentDeployment{}, &AgentDeploymentList{})
239240
}

api/v1alpha1/error_rate_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
agentraxv1alpha1 "github.com/gitcommitankit/agentrax/api/v1alpha1"
2323
)
2424

25+
// TestParseErrorRate verifies percentage string parsing across valid, invalid, and boundary inputs.
2526
func TestParseErrorRate(t *testing.T) {
2627
t.Parallel()
2728
tests := []struct {
@@ -62,6 +63,7 @@ func TestParseErrorRate(t *testing.T) {
6263
}
6364
}
6465

66+
// abs returns the absolute value of a float64.
6567
func abs(f float64) float64 {
6668
if f < 0 {
6769
return -f

api/v1alpha1/tenantquota_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type TenantQuotaList struct {
8686
Items []TenantQuota `json:"items"`
8787
}
8888

89+
// init registers TenantQuota and TenantQuotaList types with the SchemeBuilder.
8990
func init() {
9091
SchemeBuilder.Register(&TenantQuota{}, &TenantQuotaList{})
9192
}

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var (
5252
setupLog = ctrl.Log.WithName("setup")
5353
)
5454

55+
// init registers all Kubernetes core, CRD, and monitoring schemes.
5556
func init() {
5657
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5758
utilruntime.Must(autoscalingv2.AddToScheme(scheme))
@@ -62,6 +63,7 @@ func init() {
6263
// +kubebuilder:scaffold:scheme
6364
}
6465

66+
// main is the entrypoint for the Agentrax controller manager binary.
6567
func main() {
6668
var metricsAddr string
6769
var enableLeaderElection bool

internal/controller/agentdeployment_builder_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func makeAD(name, image string, port int32, minReplicas int32) *agentraxv1alpha1
6262

6363
// ── desiredDeployment ─────────────────────────────────────────────────────────
6464

65+
// TestDesiredDeployment_Image verifies that the desired Deployment container image matches spec.image.
6566
func TestDesiredDeployment_Image(t *testing.T) {
6667
r := &AgentDeploymentReconciler{}
6768
ad := makeAD("my-agent", "registry.io/agent:v1", 8080, 1)
@@ -72,6 +73,7 @@ func TestDesiredDeployment_Image(t *testing.T) {
7273
}
7374
}
7475

76+
// TestDesiredDeployment_Port verifies container port configuration and default fallback.
7577
func TestDesiredDeployment_Port(t *testing.T) {
7678
tests := []struct {
7779
name string
@@ -94,6 +96,7 @@ func TestDesiredDeployment_Port(t *testing.T) {
9496
}
9597
}
9698

99+
// TestDesiredDeployment_Replicas verifies that desired Deployment replicas match spec.replicas.min.
97100
func TestDesiredDeployment_Replicas(t *testing.T) {
98101
r := &AgentDeploymentReconciler{}
99102
ad := makeAD(testDefaultAgent, testDefaultImage, 8080, 3)
@@ -104,6 +107,7 @@ func TestDesiredDeployment_Replicas(t *testing.T) {
104107
}
105108
}
106109

110+
// TestDesiredDeployment_EnvAndArgs verifies propagation of environment variables and container arguments.
107111
func TestDesiredDeployment_EnvAndArgs(t *testing.T) {
108112
r := &AgentDeploymentReconciler{}
109113
ad := makeAD(testDefaultAgent, testDefaultImage, 8080, 1)
@@ -121,6 +125,7 @@ func TestDesiredDeployment_EnvAndArgs(t *testing.T) {
121125
}
122126
}
123127

128+
// TestDesiredDeployment_Resources verifies container CPU and Memory resource requests/limits propagation.
124129
func TestDesiredDeployment_Resources(t *testing.T) {
125130
r := &AgentDeploymentReconciler{}
126131
ad := makeAD(testDefaultAgent, testDefaultImage, 8080, 1)
@@ -153,6 +158,7 @@ func TestDesiredDeployment_Resources(t *testing.T) {
153158
}
154159
}
155160

161+
// TestDesiredDeployment_Labels verifies required standard labels on Deployment and Pod template.
156162
func TestDesiredDeployment_Labels(t *testing.T) {
157163
r := &AgentDeploymentReconciler{}
158164
ad := makeAD(testAgentName, testDefaultImage, 8080, 1)
@@ -173,6 +179,7 @@ func TestDesiredDeployment_Labels(t *testing.T) {
173179
}
174180
}
175181

182+
// TestDesiredDeployment_SelectorMatchesPodLabels verifies Deployment selector matches Pod template labels.
176183
func TestDesiredDeployment_SelectorMatchesPodLabels(t *testing.T) {
177184
r := &AgentDeploymentReconciler{}
178185
ad := makeAD(testDefaultAgent, testDefaultImage, 8080, 1)
@@ -187,6 +194,7 @@ func TestDesiredDeployment_SelectorMatchesPodLabels(t *testing.T) {
187194

188195
// ── desiredService ────────────────────────────────────────────────────────────
189196

197+
// TestDesiredService_Port verifies Service port configuration and default fallback.
190198
func TestDesiredService_Port(t *testing.T) {
191199
tests := []struct {
192200
name string
@@ -208,6 +216,7 @@ func TestDesiredService_Port(t *testing.T) {
208216
}
209217
}
210218

219+
// TestDesiredService_Selector verifies Service selector targets the agent pod label.
211220
func TestDesiredService_Selector(t *testing.T) {
212221
r := &AgentDeploymentReconciler{}
213222
ad := makeAD(testAgentName, testDefaultImage, 8080, 1)
@@ -218,6 +227,7 @@ func TestDesiredService_Selector(t *testing.T) {
218227
}
219228
}
220229

230+
// TestDesiredService_ClusterIPType verifies that the created Service is of type ClusterIP.
221231
func TestDesiredService_ClusterIPType(t *testing.T) {
222232
r := &AgentDeploymentReconciler{}
223233
ad := makeAD(testDefaultAgent, testDefaultImage, 8080, 1)
@@ -230,6 +240,7 @@ func TestDesiredService_ClusterIPType(t *testing.T) {
230240

231241
// ── agentLabels ───────────────────────────────────────────────────────────────
232242

243+
// TestAgentLabels verifies standard label generation for an AgentDeployment.
233244
func TestAgentLabels(t *testing.T) {
234245
ad := &agentraxv1alpha1.AgentDeployment{
235246
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
@@ -251,6 +262,7 @@ func TestAgentLabels(t *testing.T) {
251262

252263
// ── condition helpers ─────────────────────────────────────────────────────────
253264

265+
// TestSetAndGetCondition verifies setting and reading status conditions on AgentDeployment.
254266
func TestSetAndGetCondition(t *testing.T) {
255267
ad := &agentraxv1alpha1.AgentDeployment{}
256268

@@ -268,6 +280,7 @@ func TestSetAndGetCondition(t *testing.T) {
268280
}
269281
}
270282

283+
// TestSetCondition_Overwrite verifies that updating an existing condition updates in-place without duplicates.
271284
func TestSetCondition_Overwrite(t *testing.T) {
272285
ad := &agentraxv1alpha1.AgentDeployment{}
273286

@@ -284,6 +297,7 @@ func TestSetCondition_Overwrite(t *testing.T) {
284297
}
285298
}
286299

300+
// TestRemoveCondition verifies condition removal from the status condition slice.
287301
func TestRemoveCondition(t *testing.T) {
288302
ad := &agentraxv1alpha1.AgentDeployment{}
289303

@@ -300,6 +314,7 @@ func TestRemoveCondition(t *testing.T) {
300314
}
301315
}
302316

317+
// TestRemoveCondition_NonExistent verifies that removing a non-existent condition is a safe no-op.
303318
func TestRemoveCondition_NonExistent(t *testing.T) {
304319
ad := &agentraxv1alpha1.AgentDeployment{}
305320
// Should be a no-op, not panic.
@@ -309,6 +324,7 @@ func TestRemoveCondition_NonExistent(t *testing.T) {
309324
}
310325
}
311326

327+
// TestGetCondition_Absent verifies that querying an un-set condition returns nil.
312328
func TestGetCondition_Absent(t *testing.T) {
313329
ad := &agentraxv1alpha1.AgentDeployment{}
314330
c := GetCondition(ad, agentraxv1alpha1.ConditionReady)
@@ -319,6 +335,7 @@ func TestGetCondition_Absent(t *testing.T) {
319335

320336
// ── desiredServiceMonitor ─────────────────────────────────────────────────────
321337

338+
// TestDesiredServiceMonitor_Endpoint verifies ServiceMonitor metrics endpoint configuration.
322339
func TestDesiredServiceMonitor_Endpoint(t *testing.T) {
323340
r := &AgentDeploymentReconciler{}
324341
ad := makeAD(testDefaultAgent, testDefaultImage, 8080, 1)
@@ -336,6 +353,7 @@ func TestDesiredServiceMonitor_Endpoint(t *testing.T) {
336353
}
337354
}
338355

356+
// TestDesiredServiceMonitor_SelectorMatchesLabels verifies ServiceMonitor selector matches agent labels.
339357
func TestDesiredServiceMonitor_SelectorMatchesLabels(t *testing.T) {
340358
r := &AgentDeploymentReconciler{}
341359
ad := makeAD(testAgentName, testDefaultImage, 8080, 1)

internal/controller/suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var testReconciler *AgentDeploymentReconciler
6767
// and the validating webhook in integration tests.
6868
var testEnforcer *quota.Enforcer
6969

70+
// TestControllers is the Ginkgo test suite runner for controller integration tests.
7071
func TestControllers(t *testing.T) {
7172
RegisterFailHandler(Fail)
7273
RunSpecs(t, "Controller Suite")

internal/controller/tenantquota_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ var _ = Describe("TenantQuota Controller", func() {
350350

351351
// ── Test helpers ──────────────────────────────────────────────────────────────
352352

353+
// makeTQ creates a TenantQuota object with the provided limits for test fixtures.
353354
func makeTQ(name, ns string, maxAgents, maxGPUs, maxTotalReplicas, maxReplicasPerAgent int32) *agentraxv1alpha1.TenantQuota { //nolint:unparam
354355
return &agentraxv1alpha1.TenantQuota{
355356
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: ns},

internal/quota/enforcer_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
// ── helpers ──────────────────────────────────────────────────────────────────
3737

38+
// makeSpec creates an AgentDeploymentSpec test fixture with given maxReplicas and GPU limit.
3839
func makeSpec(maxReplicas int32, gpuLimit string) agentraxv1alpha1.AgentDeploymentSpec {
3940
spec := agentraxv1alpha1.AgentDeploymentSpec{
4041
Image: "test-image:v1",
@@ -56,6 +57,7 @@ func makeSpec(maxReplicas int32, gpuLimit string) agentraxv1alpha1.AgentDeployme
5657
return spec
5758
}
5859

60+
// makeQuota creates a TenantQuotaSpec test fixture with given quota limits.
5961
func makeQuota(maxAgents, maxGPUs, maxTotalReplicas, maxReplicasPerAgent int32) agentraxv1alpha1.TenantQuotaSpec {
6062
return agentraxv1alpha1.TenantQuotaSpec{
6163
MaxAgents: maxAgents,
@@ -65,6 +67,7 @@ func makeQuota(maxAgents, maxGPUs, maxTotalReplicas, maxReplicasPerAgent int32)
6567
}
6668
}
6769

70+
// makeUsage creates a TenantQuotaStatus test fixture with given observed usage.
6871
func makeUsage(agents, gpus, replicas int32) agentraxv1alpha1.TenantQuotaStatus {
6972
return agentraxv1alpha1.TenantQuotaStatus{
7073
UsedAgents: agents,
@@ -84,6 +87,7 @@ func newTestEnforcer(t *testing.T) *Enforcer {
8487

8588
// ── canAdmit tests ────────────────────────────────────────────────────────────
8689

90+
// TestCanAdmit_Create verifies admission decisions for new AgentDeployment creates against various quota scenarios.
8791
func TestCanAdmit_Create(t *testing.T) {
8892
t.Parallel()
8993
tests := []struct {
@@ -170,6 +174,7 @@ func TestCanAdmit_Create(t *testing.T) {
170174
}
171175
}
172176

177+
// TestCanAdmit_Update verifies admission decisions when updating existing AgentDeployment specs.
173178
func TestCanAdmit_Update(t *testing.T) {
174179
t.Parallel()
175180
e := newTestEnforcer(t)
@@ -197,6 +202,7 @@ func TestCanAdmit_Update(t *testing.T) {
197202
}
198203
}
199204

205+
// TestCanAdmit_Update_MaxReplicasPerAgent_Downgrade verifies that lowering maxReplicasPerAgent does not deadlock updates that do not increase replicas.
200206
func TestCanAdmit_Update_MaxReplicasPerAgent_Downgrade(t *testing.T) {
201207
// When maxReplicasPerAgent is lowered below an existing AD's replicas.max,
202208
// updates that do NOT further increase replicas.max must still be allowed.
@@ -235,6 +241,7 @@ func TestCanAdmit_Update_MaxReplicasPerAgent_Downgrade(t *testing.T) {
235241

236242
// ── In-flight reservation tests ───────────────────────────────────────────────
237243

244+
// TestReservation_BlocksConcurrentCreate verifies that an in-flight reservation blocks concurrent creation of the same remaining slot.
238245
func TestReservation_BlocksConcurrentCreate(t *testing.T) {
239246
t.Parallel()
240247
e := newTestEnforcer(t)
@@ -265,6 +272,7 @@ func TestReservation_BlocksConcurrentCreate(t *testing.T) {
265272
}
266273
}
267274

275+
// TestReservation_DoesNotDoubleCount verifies that re-admission for the same AD key excludes its own prior reservation.
268276
func TestReservation_DoesNotDoubleCount(t *testing.T) {
269277
// A re-admission for the same AD key should exclude its own prior reservation
270278
// so it isn't double-counted.
@@ -398,6 +406,7 @@ func TestAdmitAndReserve_AtomicRaceProtection(t *testing.T) {
398406

399407
// ── ComputeUsage tests ────────────────────────────────────────────────────────
400408

409+
// TestComputeUsage verifies aggregation of agents, GPUs, and replicas across multiple AgentDeployment specs.
401410
func TestComputeUsage(t *testing.T) {
402411
t.Parallel()
403412
e := newTestEnforcer(t)
@@ -418,6 +427,7 @@ func TestComputeUsage(t *testing.T) {
418427
}
419428
}
420429

430+
// TestComputeUsage_Empty verifies that empty input returns all-zero usage.
421431
func TestComputeUsage_Empty(t *testing.T) {
422432
t.Parallel()
423433
e := newTestEnforcer(t)
@@ -429,6 +439,7 @@ func TestComputeUsage_Empty(t *testing.T) {
429439

430440
// ── IsOverQuota tests ─────────────────────────────────────────────────────────
431441

442+
// TestIsOverQuota verifies over-quota condition detection across agents, GPUs, and replicas dimensions.
432443
func TestIsOverQuota(t *testing.T) {
433444
t.Parallel()
434445
e := newTestEnforcer(t)
@@ -464,6 +475,7 @@ func TestIsOverQuota(t *testing.T) {
464475
// ParseErrorRate lives in api/v1alpha1 to avoid an import cycle.
465476
// Its tests are in api/v1alpha1/webhook_test.go.
466477

478+
// TestParseErrorRate_ViaV1alpha1 verifies ParseErrorRate is accessible and correct from outside api/v1alpha1.
467479
func TestParseErrorRate_ViaV1alpha1(t *testing.T) {
468480
// Smoke-test that ParseErrorRate is accessible from outside api/v1alpha1.
469481
t.Parallel()
@@ -478,6 +490,7 @@ func TestParseErrorRate_ViaV1alpha1(t *testing.T) {
478490

479491
// ── helpers ───────────────────────────────────────────────────────────────────
480492

493+
// absFloat returns the absolute value of a float64.
481494
func absFloat(f float64) float64 {
482495
if f < 0 {
483496
return -f

0 commit comments

Comments
 (0)