-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement AgentDeployment admission webhooks and resource quota… #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
66ce2c5
feat: implement AgentDeployment admission webhooks and resource quota…
gitcommitankit 6c5c2da
refactor: rename test resources for clarity and add unparam lint supp…
gitcommitankit 14cfebe
fix: improve arithmetic safety, parsing validation, and test reliabil…
gitcommitankit ddaa9c3
fix: improve deletion reliability in tests, harden GPU quota calculat…
gitcommitankit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| Copyright 2026. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math" | ||
| "strconv" | ||
| ) | ||
|
|
||
| // ParseErrorRate parses a percentage string like "2%" and returns the float64 | ||
| // value (e.g. 0.02 for "2%"). Returns an error if the format is invalid. | ||
| // Used by the validating webhook and the rollout threshold evaluator. | ||
| func ParseErrorRate(s string) (float64, error) { | ||
| if len(s) == 0 { | ||
| return 0, fmt.Errorf("empty error rate string") | ||
| } | ||
| if s[len(s)-1] != '%' { | ||
| return 0, fmt.Errorf("error rate must end with '%%': got %q", s) | ||
| } | ||
| // strconv.ParseFloat rejects trailing garbage (e.g. "5x") and leading | ||
| // whitespace (e.g. " 5"), unlike fmt.Sscanf which silently ignores them. | ||
| pct, err := strconv.ParseFloat(s[:len(s)-1], 64) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("parsing error rate %q: %w", s, err) | ||
| } | ||
| // Reject non-finite values (NaN, ±Inf) that ParseFloat may return for | ||
| // inputs like "NaN" or "Inf". | ||
| if math.IsNaN(pct) || math.IsInf(pct, 0) { | ||
| return 0, fmt.Errorf("error rate %q is not a finite number", s) | ||
| } | ||
| if pct < 0 || pct > 100 { | ||
| return 0, fmt.Errorf("error rate %q out of range [0, 100]", s) | ||
| } | ||
| return pct / 100.0, nil | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| Copyright 2026. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| agentraxv1alpha1 "github.com/gitcommitankit/agentrax/api/v1alpha1" | ||
| ) | ||
|
|
||
| func TestParseErrorRate(t *testing.T) { | ||
| t.Parallel() | ||
| tests := []struct { | ||
| input string | ||
| want float64 | ||
| wantErr bool | ||
| }{ | ||
| {"2%", 0.02, false}, | ||
| {"100%", 1.0, false}, | ||
| {"0%", 0.0, false}, | ||
| {"0.5%", 0.005, false}, | ||
| {"", 0, true}, | ||
| {"5", 0, true}, | ||
| {"-1%", 0, true}, | ||
| {"101%", 0, true}, | ||
| {"abc%", 0, true}, | ||
| // trailing garbage — strconv.ParseFloat must reject these | ||
| {"5x%", 0, true}, | ||
| // non-finite numeric input — caught by math.IsNaN / math.IsInf guard | ||
| {"NaN%", 0, true}, | ||
| {"Inf%", 0, true}, | ||
| {"-Inf%", 0, true}, | ||
| // leading whitespace — strconv.ParseFloat must reject " 5" | ||
| {" 5%", 0, true}, | ||
| } | ||
| for _, tc := range tests { | ||
| tc := tc | ||
| t.Run(tc.input, func(t *testing.T) { | ||
| t.Parallel() | ||
| got, err := agentraxv1alpha1.ParseErrorRate(tc.input) | ||
| if (err != nil) != tc.wantErr { | ||
| t.Errorf("ParseErrorRate(%q) error=%v, wantErr=%v", tc.input, err, tc.wantErr) | ||
| } | ||
| if err == nil && abs(got-tc.want) > 1e-9 { | ||
| t.Errorf("ParseErrorRate(%q) = %v, want %v", tc.input, got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func abs(f float64) float64 { | ||
| if f < 0 { | ||
| return -f | ||
| } | ||
| return f | ||
| } | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| resources: | ||
| - manifests.yaml | ||
| - service.yaml |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: MutatingWebhookConfiguration | ||
| metadata: | ||
| name: mutating-webhook-configuration | ||
| webhooks: | ||
| - admissionReviewVersions: | ||
| - v1 | ||
| clientConfig: | ||
| service: | ||
| name: webhook-service | ||
| namespace: system | ||
| path: /mutate-agentrax-io-v1alpha1-agentdeployment | ||
| failurePolicy: Fail | ||
| name: magentdeployment.kb.io | ||
| rules: | ||
| - apiGroups: | ||
| - agentrax.io | ||
| apiVersions: | ||
| - v1alpha1 | ||
| operations: | ||
| - CREATE | ||
| - UPDATE | ||
| resources: | ||
| - agentdeployments | ||
| sideEffects: None | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingWebhookConfiguration | ||
| metadata: | ||
| name: validating-webhook-configuration | ||
| webhooks: | ||
| - admissionReviewVersions: | ||
| - v1 | ||
| clientConfig: | ||
| service: | ||
| name: webhook-service | ||
| namespace: system | ||
| path: /validate-agentrax-io-v1alpha1-agentdeployment | ||
| failurePolicy: Fail | ||
| name: vagentdeployment.kb.io | ||
| rules: | ||
| - apiGroups: | ||
| - agentrax.io | ||
| apiVersions: | ||
| - v1alpha1 | ||
| operations: | ||
| - CREATE | ||
| - UPDATE | ||
| resources: | ||
| - agentdeployments | ||
| sideEffects: None |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: webhook-service | ||
| namespace: system | ||
| spec: | ||
| ports: | ||
| - port: 443 | ||
| protocol: TCP | ||
| targetPort: 9443 | ||
| selector: | ||
| control-plane: controller-manager |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.