diff --git a/bcs-services/bcs-cluster-manager/internal/actions/cluster/list.go b/bcs-services/bcs-cluster-manager/internal/actions/cluster/list.go index 0e0f3c54f7..087d944184 100644 --- a/bcs-services/bcs-cluster-manager/internal/actions/cluster/list.go +++ b/bcs-services/bcs-cluster-manager/internal/actions/cluster/list.go @@ -1035,9 +1035,10 @@ func getSharedCluster(projectId string, bizId string, model store.ClusterManager continue } // 是否共享给当前项目/业务 - if clusterList[i].SharedRanges != nil && ((len(clusterList[i].SharedRanges.GetProjectIdOrCodes()) > 0 && utils.StringContainInSlice(projectId, - clusterList[i].SharedRanges.ProjectIdOrCodes)) || - (len(clusterList[i].SharedRanges.GetBizs()) > 0 && utils.StringContainInSlice(bizId, clusterList[i].SharedRanges.GetBizs()))) { + if clusterList[i].SharedRanges != nil && ((len(clusterList[i].SharedRanges.GetProjectIdOrCodes()) > 0 && + utils.StringContainInSlice(projectId, clusterList[i].SharedRanges.ProjectIdOrCodes)) || + (len(clusterList[i].SharedRanges.GetBizs()) > 0 && + utils.StringContainInSlice(bizId, clusterList[i].SharedRanges.GetBizs()))) { clusters = append(clusters, shieldClusterInfo(&clusterList[i])) continue diff --git a/bcs-services/bcs-cluster-manager/internal/actions/cluster/utils.go b/bcs-services/bcs-cluster-manager/internal/actions/cluster/utils.go index 4a1935ae52..8ac7d62b38 100644 --- a/bcs-services/bcs-cluster-manager/internal/actions/cluster/utils.go +++ b/bcs-services/bcs-cluster-manager/internal/actions/cluster/utils.go @@ -46,6 +46,7 @@ import ( ) // ClusterInfo info +// nolint revive type ClusterInfo struct { ClusterName string ClusterID string diff --git a/bcs-services/bcs-cluster-manager/internal/actions/operationlog/taskrecord.go b/bcs-services/bcs-cluster-manager/internal/actions/operationlog/taskrecord.go index fbb28c93a1..7e4920206b 100644 --- a/bcs-services/bcs-cluster-manager/internal/actions/operationlog/taskrecord.go +++ b/bcs-services/bcs-cluster-manager/internal/actions/operationlog/taskrecord.go @@ -15,6 +15,7 @@ package operationlog import ( "context" + "github.com/Tencent/bk-bcs/bcs-common/common/blog" "github.com/Tencent/bk-bcs/bcs-common/pkg/odm/operator" diff --git a/bcs-services/bcs-cluster-manager/internal/actions/thirdparty/ip_selector.go b/bcs-services/bcs-cluster-manager/internal/actions/thirdparty/ip_selector.go index 13fb112e0f..8f8439ac86 100644 --- a/bcs-services/bcs-cluster-manager/internal/actions/thirdparty/ip_selector.go +++ b/bcs-services/bcs-cluster-manager/internal/actions/thirdparty/ip_selector.go @@ -94,9 +94,9 @@ func (la *GetCustomSettingAction) Handle(ctx context.Context, req *cmproto.GetBa // GetBizInstanceTopoAction action for get biz topo type GetBizInstanceTopoAction struct { - ctx context.Context - req *cmproto.GetBizTopologyHostRequest - resp *cmproto.GetBizTopologyHostResponse + ctx context.Context + req *cmproto.GetBizTopologyHostRequest + resp *cmproto.GetBizTopologyHostResponse } // NewGetBizInstanceTopoAction create action diff --git a/bcs-services/bcs-cluster-manager/internal/remote/cmdb/client.go b/bcs-services/bcs-cluster-manager/internal/remote/cmdb/client.go index 3fce03b057..c55f8d4c0b 100644 --- a/bcs-services/bcs-cluster-manager/internal/remote/cmdb/client.go +++ b/bcs-services/bcs-cluster-manager/internal/remote/cmdb/client.go @@ -90,27 +90,27 @@ var ( // Options for cmdb client type Options struct { // Enable enable client - Enable bool + Enable bool // AppCode app code - AppCode string + AppCode string // AppSecret app secret - AppSecret string + AppSecret string // BKUserName bk username BKUserName string // Server server - Server string + Server string // Debug debug - Debug bool + Debug bool } // AuthInfo auth user type AuthInfo struct { // BkAppCode bk app code - BkAppCode string `json:"bk_app_code"` + BkAppCode string `json:"bk_app_code"` // BkAppSecret bk app secret BkAppSecret string `json:"bk_app_secret"` // BkUserName bk username - BkUserName string `json:"bk_username"` + BkUserName string `json:"bk_username"` } // Client for cc diff --git a/bcs-services/cluster-resources/pkg/i18n/locale/lc_msgs.yaml b/bcs-services/cluster-resources/pkg/i18n/locale/lc_msgs.yaml index cdb17f9b7b..5909da5553 100644 --- a/bcs-services/cluster-resources/pkg/i18n/locale/lc_msgs.yaml +++ b/bcs-services/cluster-resources/pkg/i18n/locale/lc_msgs.yaml @@ -86,6 +86,8 @@ en: "must start and end with alphanumeric, can contain '-', '_', '.' and alphanumeric" - msgID: "不应少于 1 个项" en: "Should not be less than 1 item." +- msgID: "格式无效,请参考 Cron 格式" + en: "Invalid format, please refer to Cron format." - msgID: "资源类型 %s APIVersion %s 不在受支持的版本列表 %v 中,请改用 Yaml 模式而非表单化" en: "resource kind %s apiVersion %s not in the list of supported versions %v, please use yaml rather than form edit mode" - msgID: 标签有重复的键,请检查 diff --git a/bcs-services/cluster-resources/pkg/resource/form/renderer/manifest.go b/bcs-services/cluster-resources/pkg/resource/form/renderer/manifest.go index 9214f1ff2a..aed28c8fc8 100644 --- a/bcs-services/cluster-resources/pkg/resource/form/renderer/manifest.go +++ b/bcs-services/cluster-resources/pkg/resource/form/renderer/manifest.go @@ -204,7 +204,7 @@ func (r *ManifestRenderer) initTemplate() (err error) { func (r *ManifestRenderer) render2Map() error { // 渲染,转换并写入数据(模板名称格式:{r.kind}.yaml) var buf bytes.Buffer - err := r.tmpl.ExecuteTemplate(&buf, r.kind+".yaml", r.formData) + err := r.tmpl.ExecuteTemplate(&buf, r.kind+".yaml", r.formData) // nolint goconst if err != nil { log.Warn(r.ctx, "failed to render template:%v", err) return errorx.New(errcode.General, i18n.GetMsg(r.ctx, "渲染模板失败:%v"), err) diff --git a/bcs-services/cluster-resources/pkg/resource/form/renderer/schema.go b/bcs-services/cluster-resources/pkg/resource/form/renderer/schema.go index d3a0075f11..722ee28cc2 100644 --- a/bcs-services/cluster-resources/pkg/resource/form/renderer/schema.go +++ b/bcs-services/cluster-resources/pkg/resource/form/renderer/schema.go @@ -154,6 +154,7 @@ func (r *SchemaRenderer) renderSubTypeTmpl2Map(dir string, ret interface{}) erro } // genSchemaRules 生成 JsonSchema 校验规则 +// nolint lll func genSchemaRules(ctx context.Context) map[string]interface{} { return map[string]interface{}{ "required": map[string]interface{}{ @@ -206,5 +207,22 @@ func genSchemaRules(ctx context.Context) map[string]interface{} { "validator": "{{ $self.value.length > 0 }}", "message": i18n.GetMsg(ctx, "不应少于 1 个项"), }, + "scheduleValid": map[string]interface{}{ + "validator": `/^(\*|([0-5]?\d)(,[0-5]?\d)*|([0-5]?\d)-([0-5]?\d))(\/([0-5]?\d)(,[0-5]?\d)*)?\s+` + + `(\*|([01]?\d|2[0-3])(,[01]?\d|2[0-3])*|([01]?\d|2[0-3])-` + + `([01]?\d|2[0-3]))(\/([01]?\d|2[0-3])(,[01]?\d|2[0-3])*)?\s+` + + `(\*|(0?[1-9]|[12][0-9]|3[01])(,(0?[1-9]|[12][0-9]|3[01]))*|` + + `(0?[1-9]|[12][0-9]|3[01])-(0?[1-9]|[12][0-9]|3[01])|\?)` + + `(\/(0?[1-9]|[12][0-9]|3[01])(,(0?[1-9]|[12][0-9]|3[01]))*)?\s+` + + `(\*|(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)` + + `(,(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))*|` + + `(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-` + + `(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))` + + `(\/((0?[1-9]|1[0-2])(,((0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)))*))?\s+` + + `(\*|([0-6]|SUN|MON|TUE|WED|THU|FRI|SAT)(,[0-6]|SUN|MON|TUE|WED|THU|FRI|SAT)*|` + + `([0-6]|SUN|MON|TUE|WED|THU|FRI|SAT)-([0-6]|SUN|MON|TUE|WED|THU|FRI|SAT)|\?)` + + `(\/([0-6](,([0-6]|SUN|MON|TUE|WED|THU|FRI|SAT))*))?$/`, + "message": i18n.GetMsg(ctx, "格式无效,请参考 Cron 格式"), + }, } } diff --git a/bcs-services/cluster-resources/pkg/resource/form/renderer/schema_test.go b/bcs-services/cluster-resources/pkg/resource/form/renderer/schema_test.go index 12ec40eb5c..050fc35b29 100644 --- a/bcs-services/cluster-resources/pkg/resource/form/renderer/schema_test.go +++ b/bcs-services/cluster-resources/pkg/resource/form/renderer/schema_test.go @@ -14,12 +14,17 @@ package renderer import ( "context" + "fmt" + "regexp" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/common/ctxkey" "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/common/envs" + "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/common/runmode" + "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/common/runtime" "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/i18n" "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/resource/form/validator" "github.com/Tencent/bk-bcs/bcs-services/cluster-resources/pkg/util/schema" @@ -64,3 +69,70 @@ func TestSchemaRenderer(t *testing.T) { assert.Nil(t, err) } } + +func TestGenSchemaRulesScheduleValid(t *testing.T) { + // 不打印其他 + runtime.RunMode = runmode.UnitTest + rules := genSchemaRules(context.Background()) + validator, ok := rules["scheduleValid"].(map[string]interface{})["validator"].(string) + if !ok { + t.Errorf("schedule validator is null") + return + } + validator = strings.Trim(validator, "/") + testSample := []string{ + // valid schudule cron + "* * * * *", + "1 * * * *", + "1,2 * * * *", + "1/1,2 * * * *", + "1-2/1,2 * * * *", + + "* 1 * * *", + "* 1,2 * * *", + "* 1/1,2 * * *", + "* 1-2/1,2 * * *", + + "* * 1 * *", + "* * 1,2 * *", + "* * 1/1,2 * *", + "* * 1-2/1,2 * *", + "* * ?/1,2 * *", + + "* * * 1 *", + "* * * 1,2 *", + "* * * 1/1,2 *", + "* * * 1-2/1,2 *", + "* * * JAN-2/1,2 *", + "* * * JAN-2/1,FEB *", + + "* * * * 1", + "* * * * 1,2", + "* * * * 1/1,2", + "* * * * 1-2/1,2", + "* * * * SUN-2/1,2", + "* * * * SAT-2/1,SUN", + + "1-2/1,2 23/1,2 ?/1,2 JAN/1,DEC SUN/0,SAT", + + // invalid schudule cron + "1/1-2 * * * *", + "* * L * *", + "* * W * *", + "* * * * L", + "* * * * W", + "* * * ?/1,2 *", + "1-2/1,2 23/1,2 ?/1,2 JAN/JAN,DEC SUN/0,SAT", + "1-2/1,2 23/1,2 ?/1,2 JAN/JAN,DEC SUN/SUN,SAT", + } + scheduleReg := regexp.MustCompile(validator) + var invalidSchedule []string + for _, v := range testSample { + if !scheduleReg.MatchString(v) { + invalidSchedule = append(invalidSchedule, v) + } + } + + fmt.Println(fmt.Sprintf("invalid schedule cron:\n %s", strings.Join(invalidSchedule, "\n"))) + +} diff --git a/bcs-services/cluster-resources/pkg/resource/form/renderer/testdata/formdata/workload.go b/bcs-services/cluster-resources/pkg/resource/form/renderer/testdata/formdata/workload.go index 144027afe7..051f61de18 100644 --- a/bcs-services/cluster-resources/pkg/resource/form/renderer/testdata/formdata/workload.go +++ b/bcs-services/cluster-resources/pkg/resource/form/renderer/testdata/formdata/workload.go @@ -40,7 +40,7 @@ var DeployComplex = model.Deploy{ }, Spec: model.DeploySpec{ Replicas: model.DeployReplicas{ - Cnt: 2, + Cnt: "2", UpdateStrategy: resCsts.DefaultUpdateStrategy, MaxSurge: 0, MSUnit: util.UnitCnt, @@ -76,7 +76,7 @@ var DeploySimple = model.Deploy{ }, Spec: model.DeploySpec{ Replicas: model.DeployReplicas{ - Cnt: 2, + Cnt: "2", UpdateStrategy: resCsts.DefaultUpdateStrategy, MaxSurge: 1, MSUnit: util.UnitCnt, @@ -114,7 +114,7 @@ var STSComplex = model.STS{ Spec: model.STSSpec{ Replicas: model.STSReplicas{ SVCName: "svc-complex-y3xk1r9vg9", - Cnt: 2, + Cnt: "2", UpdateStrategy: resCsts.DefaultUpdateStrategy, PodManPolicy: "OrderedReady", Partition: 3, diff --git a/bcs-services/cluster-resources/pkg/resource/form/tmpl/schema/workload.tpl b/bcs-services/cluster-resources/pkg/resource/form/tmpl/schema/workload.tpl index 1e11b2cb2f..6ac66b4de2 100644 --- a/bcs-services/cluster-resources/pkg/resource/form/tmpl/schema/workload.tpl +++ b/bcs-services/cluster-resources/pkg/resource/form/tmpl/schema/workload.tpl @@ -454,6 +454,7 @@ jobManage: ui:rules: - required - maxLength64 + - scheduleValid concurrencyPolicy: title: {{ i18n "并发策略" .lang }} type: string