-
Notifications
You must be signed in to change notification settings - Fork 495
Controller gen #5543
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
Open
zbb88888
wants to merge
19
commits into
kubeovn:master
Choose a base branch
from
zbb88888:controller-gen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Controller gen #5543
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
df5d028
support crd gen
zbb88888 bb2f640
ignore temp crds for now
zbb88888 41ddcf7
Update hack/update-codegen-crd.sh
zbb88888 817a16f
fix as gemini, but err
zbb88888 19e90d7
fix big int json and upgrade controller-gen version
zbb88888 93ddef5
subnet status use big int
zbb88888 899d4df
Merge branch 'master' into controller-gen
zbb88888 dfb5f71
fix(subnet): correct IP availability check by using big.Int addition
zbb88888 b6d2b5a
fix lint
zbb88888 388d650
fix e2e
zbb88888 6f10d09
fix ut
zbb88888 18683f2
fix lint
zbb88888 3a7860c
修复 BigInt JSON 序列化导致的 E2E 测试失败
zbb88888 44d8c4e
test: 新增 BigInt K8s API 集成 E2E 测试
zbb88888 f238abb
fix: 移除未使用的 currentSubnet 变量
zbb88888 a3ce50a
fix: 修复 golangci-lint 错误
zbb88888 6b78d85
fix: 使用 any 替换 interface{} (Go 1.18+)
zbb88888 5bc4386
fix: 使用 any 替换 interface{} (Go 1.18+)
zbb88888 d8754a7
ignore pinger
zbb88888 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
| # usage: bash -x ./hack/update-codegen-crd.sh | ||
| set -eux | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| # set GOPROXY you like | ||
| export GOPROXY=${GOPROXY:-"https://goproxy.cn"} | ||
| # use controller-gen to generate CRDs | ||
| # ensure controller-gen is installed | ||
| CONTROLLER_TOOLS_VERSION=${CONTROLLER_TOOLS_VERSION:-"v0.19.0"} | ||
| go install sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_TOOLS_VERSION}" | ||
| go mod tidy | ||
|
|
||
| # generate CRDs | ||
| controller-gen crd:allowDangerousTypes=true paths=./pkg/apis/kubeovn/v1 output:crd:artifacts:config=./yamls/crds | ||
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
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,132 @@ | ||
| package v1 | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| kotypes "github.com/kubeovn/kube-ovn/pkg/types" | ||
| ) | ||
|
|
||
| // TestSubnetStatusBigIntJSONSerialization 验证 SubnetStatus 的 BigInt 字段正确序列化为 JSON 字符串 | ||
| func TestSubnetStatusBigIntJSONSerialization(t *testing.T) { | ||
| subnet := &Subnet{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
| Kind: "Subnet", | ||
| APIVersion: "kubeovn.io/v1", | ||
| }, | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test-subnet", | ||
| }, | ||
| Spec: SubnetSpec{ | ||
| CIDRBlock: "10.16.0.0/16", | ||
| }, | ||
| Status: SubnetStatus{ | ||
| V4AvailableIPs: kotypes.NewBigInt(65533), | ||
| V4UsingIPs: kotypes.NewBigInt(3), | ||
| V6AvailableIPs: kotypes.NewBigInt(0), | ||
| V6UsingIPs: kotypes.NewBigInt(0), | ||
| }, | ||
| } | ||
|
|
||
| // Marshal to JSON | ||
| data, err := json.Marshal(subnet) | ||
| if err != nil { | ||
| t.Fatalf("Marshal failed: %v", err) | ||
| } | ||
|
|
||
| jsonStr := string(data) | ||
| t.Logf("Serialized Subnet JSON (truncated): %s", jsonStr[:min(200, len(jsonStr))]) | ||
|
|
||
| // Verify the status field contains quoted strings | ||
| var decoded map[string]any | ||
| if err := json.Unmarshal(data, &decoded); err != nil { | ||
| t.Fatalf("Unmarshal to map failed: %v", err) | ||
| } | ||
|
|
||
| status, ok := decoded["status"].(map[string]any) | ||
| if !ok { | ||
| t.Fatal("status field not found or not an object") | ||
| } | ||
|
|
||
| // Check each BigInt field is a string | ||
| checkStringField := func(name, expected string) { | ||
| value, ok := status[name] | ||
| if !ok { | ||
| t.Errorf("Field %s not found in status", name) | ||
| return | ||
| } | ||
| strValue, ok := value.(string) | ||
| if !ok { | ||
| t.Errorf("Field %s should be string, got %T: %v", name, value, value) | ||
| return | ||
| } | ||
| if strValue != expected { | ||
| t.Errorf("Field %s = %q, want %q", name, strValue, expected) | ||
| } | ||
| } | ||
|
|
||
| checkStringField("v4availableIPs", "65533") | ||
| checkStringField("v4usingIPs", "3") | ||
| checkStringField("v6availableIPs", "0") | ||
| checkStringField("v6usingIPs", "0") | ||
|
|
||
| // Unmarshal back to Subnet | ||
| var decodedSubnet Subnet | ||
| if err := json.Unmarshal(data, &decodedSubnet); err != nil { | ||
| t.Fatalf("Unmarshal to Subnet failed: %v", err) | ||
| } | ||
|
|
||
| // Verify values match | ||
| if !decodedSubnet.Status.V4AvailableIPs.Equal(subnet.Status.V4AvailableIPs) { | ||
| t.Errorf("V4AvailableIPs mismatch after round-trip: got %v, want %v", | ||
| decodedSubnet.Status.V4AvailableIPs.String(), subnet.Status.V4AvailableIPs.String()) | ||
| } | ||
| } | ||
|
|
||
| // TestSubnetStatusPatchJSON 模拟 Kubernetes patch 操作的 JSON 序列化 | ||
| func TestSubnetStatusPatchJSON(t *testing.T) { | ||
| status := SubnetStatus{ | ||
| V4AvailableIPs: kotypes.NewBigInt(253), | ||
| V4UsingIPs: kotypes.NewBigInt(1), | ||
| V6AvailableIPs: kotypes.NewBigInt(0), | ||
| V6UsingIPs: kotypes.NewBigInt(0), | ||
| } | ||
|
|
||
| data, err := json.Marshal(status) | ||
| if err != nil { | ||
| t.Fatalf("Marshal failed: %v", err) | ||
| } | ||
|
|
||
| t.Logf("SubnetStatus JSON: %s", string(data)) | ||
|
|
||
| // Parse as generic map to verify field types | ||
| var m map[string]any | ||
| if err := json.Unmarshal(data, &m); err != nil { | ||
| t.Fatalf("Unmarshal to map failed: %v", err) | ||
| } | ||
|
|
||
| // All BigInt fields must be strings, not numbers | ||
| for fieldName, expectedValue := range map[string]string{ | ||
| "v4availableIPs": "253", | ||
| "v4usingIPs": "1", | ||
| "v6availableIPs": "0", | ||
| "v6usingIPs": "0", | ||
| } { | ||
| value, ok := m[fieldName] | ||
| if !ok { | ||
| t.Errorf("Field %s not found", fieldName) | ||
| continue | ||
| } | ||
| strValue, ok := value.(string) | ||
| if !ok { | ||
| t.Errorf("Field %s should be string (for K8s CRD validation), got %T: %v", | ||
| fieldName, value, value) | ||
| continue | ||
| } | ||
| if strValue != expectedValue { | ||
| t.Errorf("Field %s = %q, want %q", fieldName, strValue, expectedValue) | ||
| } | ||
| } | ||
| } |
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.