xiaobaicai66695 commented on code in PR #1084: URL: https://github.com/apache/dubbo-go-pixiu/pull/1084#discussion_r4537323822
########## 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: 已在 232cabe9 修复:旧 Cluster 转换现在对 discovery type 使用 strings.TrimSpace,与现有运行时行为一致。新增 type: ' Static ' 的 DecodeLegacyClusterYAML → CompileAdminCluster → PreviewYAML 回归测试;相关包的 go test -race、go vet 均通过。 ########## 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: 已在 232cabe9 修复:路由 Store 写入前及独立 validate 接口均明确限制 AdminRouteBinding。新增错误 kind 的创建、同名更新和校验测试,并确认被拒绝的更新不会改变原草稿及 revision。相关包的 go test -race、go vet 均通过。 -- 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]
