diff --git a/cmd/kubebuilder_marker_generator/main.go b/cmd/kubebuilder_marker_generator/main.go index 8fd91278..1326493f 100644 --- a/cmd/kubebuilder_marker_generator/main.go +++ b/cmd/kubebuilder_marker_generator/main.go @@ -80,6 +80,12 @@ func generate(fileName string) error { //nolint:gocognit,unparam if strings.HasPrefix(comment, "// Format: ") { addSimpleMarker(field, fileName, comment, "Format", "raw") } + if strings.HasPrefix(comment, "// Required: true") { + if len(comments) == 2 && comments[0] == "// index" { + field.Decorations().Before = dst.NewLine + field.Decorations().Start.Append("// +kubebuilder:validation:Optional") + } + } } // if len(field.Names) > 0 { diff --git a/models/acl.go b/models/acl.go index 3a3d0953..f59cfbc2 100644 --- a/models/acl.go +++ b/models/acl.go @@ -51,6 +51,7 @@ type ACL struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // value diff --git a/models/backend_switching_rule.go b/models/backend_switching_rule.go index 2169194f..e5f9e2f3 100644 --- a/models/backend_switching_rule.go +++ b/models/backend_switching_rule.go @@ -47,6 +47,7 @@ type BackendSwitchingRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // name diff --git a/models/capture.go b/models/capture.go index 6fbfbb94..28e89050 100644 --- a/models/capture.go +++ b/models/capture.go @@ -34,9 +34,9 @@ import ( // // swagger:model capture type Capture struct { - // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // length diff --git a/models/filter.go b/models/filter.go index a6b2b4f8..8f54c752 100644 --- a/models/filter.go +++ b/models/filter.go @@ -64,6 +64,7 @@ type Filter struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // A sample expression rule. diff --git a/models/http_after_response_rule.go b/models/http_after_response_rule.go index d447c918..db0763fd 100644 --- a/models/http_after_response_rule.go +++ b/models/http_after_response_rule.go @@ -69,6 +69,7 @@ type HTTPAfterResponseRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // log level diff --git a/models/http_check.go b/models/http_check.go index 2d240f5d..e78849e9 100644 --- a/models/http_check.go +++ b/models/http_check.go @@ -71,6 +71,7 @@ type HTTPCheck struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // linger diff --git a/models/http_error_rule.go b/models/http_error_rule.go index f12f12fb..fc44df44 100644 --- a/models/http_error_rule.go +++ b/models/http_error_rule.go @@ -44,6 +44,7 @@ type HTTPErrorRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // return content diff --git a/models/http_request_rule.go b/models/http_request_rule.go index 17090456..bc9e9fa6 100644 --- a/models/http_request_rule.go +++ b/models/http_request_rule.go @@ -124,6 +124,7 @@ type HTTPRequestRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // log level diff --git a/models/http_response_rule.go b/models/http_response_rule.go index e5d36bfa..8acbb10b 100644 --- a/models/http_response_rule.go +++ b/models/http_response_rule.go @@ -103,6 +103,7 @@ type HTTPResponseRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // log level diff --git a/models/log_target.go b/models/log_target.go index 2b8ed1b6..5bbfd4b8 100644 --- a/models/log_target.go +++ b/models/log_target.go @@ -56,6 +56,7 @@ type LogTarget struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // length diff --git a/models/server_switching_rule.go b/models/server_switching_rule.go index 5739c387..d18dc89a 100644 --- a/models/server_switching_rule.go +++ b/models/server_switching_rule.go @@ -47,6 +47,7 @@ type ServerSwitchingRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // target server diff --git a/models/stick_rule.go b/models/stick_rule.go index acb212e6..48e42762 100644 --- a/models/stick_rule.go +++ b/models/stick_rule.go @@ -47,6 +47,7 @@ type StickRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // pattern diff --git a/models/tcp_check.go b/models/tcp_check.go index e1555aee..081daf7a 100644 --- a/models/tcp_check.go +++ b/models/tcp_check.go @@ -78,6 +78,7 @@ type TCPCheck struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // linger diff --git a/models/tcp_request_rule.go b/models/tcp_request_rule.go index 4d7662ac..81a3229b 100644 --- a/models/tcp_request_rule.go +++ b/models/tcp_request_rule.go @@ -75,6 +75,7 @@ type TCPRequestRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // log level diff --git a/models/tcp_response_rule.go b/models/tcp_response_rule.go index 1e269b35..62e8b16e 100644 --- a/models/tcp_response_rule.go +++ b/models/tcp_response_rule.go @@ -64,6 +64,7 @@ type TCPResponseRule struct { // index // Required: true + // +kubebuilder:validation:Optional Index *int64 `json:"index"` // log level