XnLemon commented on code in PR #1084:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1084#discussion_r4527640146
##########
pkg/config/schema/builtin.go:
##########
@@ -33,16 +33,21 @@ var supportedDubboParamTypes = []string{
"java.lang.Float", "java.lang.Double", "java.lang.Boolean",
"java.lang.Byte", "java.lang.Object", "java.util.Date",
}
-// RegisterBuiltinSchemas installs only the Admin-facing route binding. Legacy
-// Resource and Method are compiler outputs rather than form objects.
+// RegisterBuiltinSchemas installs the Admin-facing configuration objects.
func RegisterBuiltinSchemas(registry *Registry) error {
if registry == nil {
return fmt.Errorf("admin object schema registry is nil")
}
if err := registry.Register(adminRouteBindingSchema()); err != nil {
return err
}
- return registry.RegisterValidator(KindAdminRouteBinding,
validateAdminRouteBinding)
+ if err := registry.RegisterValidator(KindAdminRouteBinding,
validateAdminRouteBinding); err != nil {
+ return err
+ }
+ if err := registry.Register(adminClusterSchema()); err != nil {
Review Comment:
[P2] Reject non-route objects before persisting route drafts. Registering
AdminCluster here makes valid Cluster objects pass both ValidateRouteBinding
and RouteBindingStore.Normalize. A PUT using an existing route name can now
replace that route's draft through UpdateDraft → SaveDraft → Normalize →
commitDraft, although preview/publish later fails with `cannot compile kind
"AdminCluster"`. This violates the route endpoint's AdminRouteBinding-only
contract and discards the previous draft contents. On HEAD ef0914de, two
targeted tests reproduced successful replacement and `valid:true`; the same
tests pass on base 7ee3054b because it rejects the Cluster. Please enforce
KindAdminRouteBinding in the route store normalization boundary and standalone
validate handler before writes, with wrong-kind create/update/validate coverage.
<details>
<summary>中文</summary>
这里将 `AdminCluster` 加入共享注册表后,合法 Cluster 会通过 `ValidateRouteBinding` 和
`RouteBindingStore.Normalize`。向路由 PUT 接口提交与已有路由同名的 Cluster,会经过 `UpdateDraft →
SaveDraft → Normalize → commitDraft` 成功覆盖原路由草稿;读取也成功,但预览或发布时报 `cannot compile
kind "AdminCluster"`。这违反路由接口只保存 `AdminRouteBinding` 的契约,并丢失原草稿内容。在 HEAD
`ef0914de` 的两个针对性测试中,已复现覆盖成功和校验返回 `valid:true`;相同测试在基线 `7ee3054b` 通过,因为基线拒绝该
Cluster。请在路由 Store 的 Normalize 和独立 validate handler 中明确检查
`KindAdminRouteBinding`,在写入前拒绝其他 kind,并补充错误 kind 的创建、更新和校验用例。
</details>
##########
pkg/config/schema/cluster.go:
##########
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 schema
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "strings"
+)
+
+import (
+ "gopkg.in/yaml.v3"
+)
+
+import (
+ legacyconfig "github.com/apache/dubbo-go-pixiu/pkg/config"
+)
+
+// The enum matches the discovery types accepted by the current runtime.
+var adminClusterTypes = []any{"Static", "StrictDNS", "LogicalDns", "EDS",
"OriginalDst"}
+
+func adminClusterSchema() ObjectSchema {
+ return ObjectSchema{
+ Kind: KindAdminCluster,
+ Description: "Cluster endpoint published to the existing Pixiu
runtime",
+ Fields: map[string]*FieldSchema{
+ "type": {
+ Type: FieldTypeString,
+ Required: true,
+ Default: "Static",
+ Enum: adminClusterTypes,
+ UI: UIHints{Component: "select", Order:
10},
+ },
+ "endpoint": {
+ Type: FieldTypeObject,
+ Required: true,
+ Properties: map[string]*FieldSchema{
+ "address": {
+ Type: FieldTypeString,
+ Required: true,
+ UI: UIHints{Component:
"text", Order: 10, Placeholder: "127.0.0.1"},
+ },
+ "port": {
+ Type: FieldTypeInteger,
+ Required: true,
+ Minimum: floatPointer(1),
+ Maximum: floatPointer(65535),
+ UI: UIHints{Component:
"number", Order: 20},
+ },
+ },
+ UI: UIHints{Group: "endpoint", Order: 20},
+ },
+ },
+ }
+}
+
+func validateAdminCluster(object AdminObject) []ValidationIssue {
+ endpoint, ok := object.Spec["endpoint"].(map[string]any)
+ if !ok {
+ return nil // The schema reports a missing or mistyped endpoint.
+ }
+ address, ok := endpoint["address"].(string)
+ if ok && strings.TrimSpace(address) == "" {
+ return []ValidationIssue{issue("spec.endpoint.address",
"required", "address is required")}
+ }
+ return nil
+}
+
+// AdminClusterFromLegacy keeps the runtime ID out of editable form data.
+// Invalid legacy values remain representable as drafts; compilation validates
them.
+func AdminClusterFromLegacy(cluster legacyconfig.Cluster) AdminObject {
+ return AdminObject{
+ Kind: KindAdminCluster,
+ Metadata: ObjectMetadata{Name: cluster.Name},
+ Spec: map[string]any{
+ "type": cluster.Type,
Review Comment:
[P2] Normalize supported legacy discovery types before enum validation.
Existing runtime-valid YAML such as `type: ' Static '` is copied verbatim into
spec.type here, so DecodeLegacyClusterYAML → CompileAdminCluster rejects it
against the exact enum. The existing xDS validateClusters/makeClusters path
trims this value, and the pre-existing
TestSnapshotBuilderNormalizesValidatedFields explicitly covers it. On HEAD
ef0914de the targeted converter test fails, while that runtime test passes on
both base 7ee3054b and HEAD. This breaks the linked issue's existing-YAML
compatibility requirement: the previously valid Cluster cannot reach the new
compiler/preview boundary, and a later lifecycle using this compiler would
reject it. Please normalize the legacy discovery type before enum validation
and add this case to conversion compatibility coverage.
<details>
<summary>中文</summary>
现有运行时支持的旧 YAML(例如 `type: ' Static '`)在这里被原样复制到 `spec.type`,随后
`DecodeLegacyClusterYAML → CompileAdminCluster` 因精确枚举匹配而拒绝它。现有 xDS 的
`validateClusters` / `makeClusters` 会去除类型两端空白,既有
`TestSnapshotBuilderNormalizesValidatedFields` 也明确覆盖此行为。在 HEAD
`ef0914de`,针对转换器的测试失败,而该运行时测试在基线 `7ee3054b` 和 HEAD 均通过。这违反关联 issue 保持旧 YAML
兼容性的要求:此前有效的 Cluster 无法通过新的编译/预览边界,未来使用此编译器的生命周期流程也会拒绝它。请在枚举校验前规范化旧 discovery
type,并补充对应转换兼容性用例。
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]