Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ kube-ovn.yaml
!/charts/kube-ovn-v2/crds/kube-ovn-crd.yaml
!/charts/kube-ovn/templates/kube-ovn-crd.yaml
kube-ovn-crd.yaml
yamls/crds
ovn.yaml
ovn-ic-controller.yaml
ovn-ic-server.yaml
Expand Down
14 changes: 14 additions & 0 deletions hack/update-codegen-crd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -eux
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure the script runs correctly regardless of the directory from which it is called, it's a good practice to change the directory to the project root at the beginning of the script. This makes the script more robust.

Suggested change
set -eux
set -eux
cd "$(dirname "$0")/.."

# usage: bash ./hack/update-codegen-crd.sh

# set GOPROXY you like
export GOPROXY=https://goproxy.cn
# use controller-gen to generate CRDs
# ensure controller-gen is installed
CONTROLLER_TOOLS_VERSION=${CONTROLLER_TOOLS_VERSION:-"v0.17.3"}
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
3 changes: 2 additions & 1 deletion pkg/apis/kubeovn/v1/provider-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type ProviderNetworkSpec struct {
type ProviderNetworkCondition struct {
// Node name
Node string `json:"node"`
Condition

Condition `json:"condition"`
}

type ProviderNetworkStatus struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/kubeovn/v1/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ type NatOutGoingPolicyMatch struct {

type NatOutgoingPolicyRuleStatus struct {
RuleID string `json:"ruleID"`
NatOutgoingPolicyRule

NatOutgoingPolicyRule `json:"natOutgoingPolicyRule"`
}
type SubnetStatus struct {
// Conditions represents the latest state of the object
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/big_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type BigInt struct {
big.Int
big.Int `json:"bigInt"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Adding a json tag to the embedded big.Int field might cause issues with CRD generation. The BigInt type has custom MarshalJSON and UnmarshalJSON methods that serialize it to a JSON string. However, controller-gen might interpret this json:"bigInt" tag to mean that the serialized form is an object with a bigInt field, leading to an incorrect OpenAPI schema for the CRD. This will cause schema validation failures for clients.

The recommended way to handle types with custom JSON marshalling is to use // +kubebuilder:validation:Type=string on the fields of type BigInt within your CRD structs (e.g., in IPPoolStatus). This tells controller-gen to treat it as a string in the schema, which matches the behavior of your custom marshaller.

Please remove this tag and apply the +kubebuilder marker on the relevant fields in the CRD definitions.

Suggested change
big.Int `json:"bigInt"`
big.Int

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root@debian:~/f/kube-ovn controller-gen ✔ 3m ⍉
▶ bash ./hack/update-codegen-crd.sh

  • export GOPROXY=https://goproxy.cn
  • GOPROXY=https://goproxy.cn
  • CONTROLLER_TOOLS_VERSION=v0.17.3
  • go install sigs.k8s.io/controller-tools/cmd/[email protected]
  • go mod tidy
  • controller-gen crd:allowDangerousTypes=true paths=./pkg/apis/kubeovn/v1 output:crd:artifacts:config=./yamls/crds
    /root/f/kube-ovn/pkg/internal/big_int.go:9:2: encountered struct field "" without JSON tag in type "BigInt"
    github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1:-: conflicting types in allOf branches in schema: object vs string
    github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1:-: conflicting types in allOf branches in schema: object vs string
    github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1:-: conflicting types in allOf branches in schema: object vs string
    github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1:-: conflicting types in allOf branches in schema: object vs string
    Error: not all generators ran successfully

}

func (b BigInt) DeepCopyInto(n *BigInt) {
Expand Down
Loading