Skip to content

Commit 611030c

Browse files
Merge upstream/main: resolve migration conflicts (user contact indexes + service module)
Signed-off-by: huanghongbo-hhb <huanghongbo@koderover.com>
2 parents e4381fe + 9b288c9 commit 611030c

79 files changed

Lines changed: 4066 additions & 435 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkg/cli/initconfig/cmd/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ func createOrUpdateMongodbIndex(ctx context.Context) {
154154
commonrepo.NewS3StorageColl(),
155155
commonrepo.NewServiceColl(),
156156
commonrepo.NewProductionServiceColl(),
157+
commonrepo.NewServiceModuleColl(),
158+
commonrepo.NewProductionServiceModuleColl(),
157159
commonrepo.NewStrategyColl(),
158160
commonrepo.NewStatsColl(),
159161
commonrepo.NewSubscriptionColl(),

pkg/microservice/aslan/core/build/service/build.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package service
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"strings"
@@ -29,6 +30,7 @@ import (
2930
commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
3031
commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb"
3132
commonservice "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service"
33+
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/repository"
3234
commonutil "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/util"
3335
"github.com/koderover/zadig/v2/pkg/setting"
3436
"github.com/koderover/zadig/v2/pkg/shared/client/systemconfig"
@@ -195,7 +197,14 @@ func ListBuildModulesByServiceModule(encryptedKey, productName, envName string,
195197
ModuleBuilds: resp,
196198
})
197199
} else {
198-
for _, container := range serviceTmpl.Containers {
200+
// Service.Containers no longer persisted — pull merged modules
201+
// (non-production: this function targets the test service path
202+
// per its NewServiceColl().ListMaxRevisionsByProduct call above).
203+
resolved, _, rerr := repository.ResolveServiceModules(context.Background(), serviceTmpl.ProductName, serviceTmpl.ServiceName, false, serviceTmpl.Revision)
204+
if rerr != nil {
205+
return nil, e.ErrListBuildModule.AddErr(rerr)
206+
}
207+
for _, container := range resolved {
199208
opt := &commonrepo.BuildListOption{
200209
ServiceName: serviceTmpl.ServiceName,
201210
Targets: []string{container.Name},

pkg/microservice/aslan/core/build/service/target.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ limitations under the License.
1717
package service
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
"go.uber.org/zap"
2324

2425
commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
2526
commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb"
27+
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/service/repository"
2628
"github.com/koderover/zadig/v2/pkg/setting"
2729
e "github.com/koderover/zadig/v2/pkg/tool/errors"
2830
)
@@ -39,7 +41,14 @@ func ListDeployTarget(productName string, log *zap.SugaredLogger) ([]*commonmode
3941
for _, svc := range services {
4042
switch svc.Type {
4143
case setting.K8SDeployType, setting.HelmDeployType:
42-
for _, container := range svc.Containers {
44+
// Service.Containers no longer persisted — pull merged modules
45+
// from service_module table.
46+
resolved, _, rerr := repository.ResolveServiceModules(context.Background(), svc.ProductName, svc.ServiceName, false, svc.Revision)
47+
if rerr != nil {
48+
log.Errorf("failed to resolve modules for %s/%s rev %d: %s", svc.ProductName, svc.ServiceName, svc.Revision, rerr)
49+
continue
50+
}
51+
for _, container := range resolved {
4352
serviceObjects = append(serviceObjects, &commonmodels.ServiceModuleTarget{
4453
ProductName: svc.ProductName,
4554
ServiceWithModule: commonmodels.ServiceWithModule{
@@ -85,7 +94,14 @@ func ListContainers(productName string, log *zap.SugaredLogger) ([]*commonmodels
8594
log.Errorf("ServiceTmpl.Find error: %v", err)
8695
continue
8796
}
88-
for _, container := range serviceDetail.Containers {
97+
// Service.Containers no longer persisted — read modules from
98+
// the service_module table.
99+
resolved, _, rerr := repository.ResolveServiceModules(context.Background(), serviceDetail.ProductName, serviceDetail.ServiceName, false, serviceDetail.Revision)
100+
if rerr != nil {
101+
log.Errorf("failed to resolve modules for %s/%s rev %d: %s", serviceDetail.ProductName, serviceDetail.ServiceName, serviceDetail.Revision, rerr)
102+
continue
103+
}
104+
for _, container := range resolved {
89105
containerList = append(containerList, &commonmodels.ServiceModuleTarget{
90106
ProductName: service.ProductName,
91107
ServiceWithModule: commonmodels.ServiceWithModule{

pkg/microservice/aslan/core/common/repository/models/im_app.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ type IMApp struct {
4848
DingTalkDefaultApprovalFormCode string `json:"-" bson:"dingtalk_default_approval_form_code"`
4949

5050
// workwx fields
51-
Host string `json:"host" bson:"host"`
52-
CorpID string `json:"corp_id" bson:"corp_id"`
53-
AgentID int `json:"agent_id" bson:"agent_id"`
54-
AgentSecret string `json:"agent_secret" bson:"agent_secret"`
55-
WorkWXApprovalTemplateID string `json:"workwx_approval_template_id" bson:"workwx_approval_template_id"`
56-
WorkWXToken string `json:"workwx_token" bson:"workwx_token"`
57-
WorkWXAESKey string `json:"workwx_aes_key" bson:"workwx_aes_key"`
51+
Host string `json:"host" bson:"host"`
52+
CorpID string `json:"corp_id" bson:"corp_id"`
53+
AgentID int `json:"agent_id" bson:"agent_id"`
54+
AgentSecret string `json:"agent_secret" bson:"agent_secret"`
55+
WorkWXApprovalTemplateID string `json:"workwx_approval_template_id" bson:"workwx_approval_template_id"`
56+
WorkWXApprovalTemplateIDList map[string]string `json:"-" bson:"workwx_approval_template_id_list"`
57+
WorkWXToken string `json:"workwx_token" bson:"workwx_token"`
58+
WorkWXAESKey string `json:"workwx_aes_key" bson:"workwx_aes_key"`
5859
}
5960

6061
func (IMApp) TableName() string {

pkg/microservice/aslan/core/common/repository/models/llm_integration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424

2525
type LLMIntegration struct {
2626
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`
27+
Name string `bson:"name" json:"name"`
2728
ProviderName llm.Provider `bson:"provider_name" json:"provider_name"`
29+
Protocol llm.Protocol `bson:"protocol" json:"protocol"`
2830
Token string `bson:"token" json:"token"`
2931
BaseURL string `bson:"base_url" json:"base_url"`
3032
Model string `bson:"model" json:"model"`

pkg/microservice/aslan/core/common/repository/models/service.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ type Service struct {
4848
Hash string `bson:"hash256,omitempty" json:"hash256,omitempty"`
4949
CreateTime int64 `bson:"create_time" json:"create_time"`
5050
CreateBy string `bson:"create_by" json:"create_by"`
51-
Containers []*Container `bson:"containers,omitempty" json:"containers,omitempty"`
51+
// Containers is an in-memory transit field used by the parsing helpers
52+
// (SetCurrentContainerImages, parseContainer) and JSON responses for the
53+
// frontend. Authoritative storage lives in the service_module collection
54+
// — read via repository.ResolveServiceModules and write via
55+
// repository.SyncAutoServiceModules. The bson tag is `-` so MongoDB does
56+
// not persist this field; fresh DB loads will have it nil.
57+
//
58+
// Deprecated: do not add new readers of this field. Use
59+
// repository.ResolveServiceModules instead.
60+
Containers []*Container `bson:"-" json:"containers,omitempty"`
5261
Description string `bson:"description,omitempty" json:"description,omitempty"`
5362
Visibility string `bson:"visibility,omitempty" json:"visibility,omitempty"` // DEPRECATED since 1.17.0
5463
Status string `bson:"status,omitempty" json:"status,omitempty"`
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2026 The KodeRover Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package models
18+
19+
import (
20+
"go.mongodb.org/mongo-driver/bson/primitive"
21+
22+
"github.com/koderover/zadig/v2/pkg/setting"
23+
)
24+
25+
// ServiceModule is a first-class record of a deployable unit ("module" /
26+
// "container") attached to a service template. Modules can originate from:
27+
//
28+
// - Auto-discovery: parsed out of a service template's KubeYamls for the
29+
// workload kinds we recognize (Deployment, StatefulSet, Job, CronJob,
30+
// CloneSet). Auto records are bound to a specific service revision via
31+
// RevisionBound and are re-derived every time SetCurrentContainerImages
32+
// re-parses YAML.
33+
//
34+
// - Manual declaration: added through the manual-module API by users for
35+
// workload kinds we cannot parse (CRDs, DaemonSets, Argo Rollouts, etc.).
36+
// Manual records carry RevisionBound = 0 — they are version-agnostic and
37+
// load for every revision of the service.
38+
//
39+
// Read-merge rule (see ResolveServiceModules): records are unioned by Name with
40+
// time-of-creation precedence ("first-come-first-served" by CreateTime).
41+
// Conflicts are recorded and surfaced to the caller so the UI can warn users.
42+
type ServiceModule struct {
43+
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
44+
ProjectName string `bson:"project_name" json:"project_name"`
45+
ServiceName string `bson:"service_name" json:"service_name"`
46+
47+
// IsManual: true if added explicitly by the user via the manual-module API.
48+
// Manual records MUST have RevisionBound = 0.
49+
IsManual bool `bson:"is_manual" json:"is_manual"`
50+
51+
// RevisionBound: the service revision this record belongs to.
52+
// 0 -> manual / version-agnostic, loads for every revision
53+
// >0 -> auto-discovered, scoped to that revision only
54+
RevisionBound int64 `bson:"revision_bound" json:"revision_bound"`
55+
56+
// Name is the module identifier. For auto records it equals the parsed
57+
// container's Name; for manual records it is the user-supplied name that
58+
// $<name>-image$ placeholders in YAML resolve against.
59+
Name string `bson:"name" json:"name"`
60+
61+
// Type carries the legacy Container.Type distinction (normal vs init
62+
// container). No K8s deployment logic in this codebase branches on this
63+
// field — it is preserved for OpenAPI parity. Manual records default to
64+
// ContainerTypeNormal ("").
65+
Type setting.ContainerType `bson:"type,omitempty" json:"type,omitempty"`
66+
67+
// Image is the resolved image URI. For auto records it is whatever the
68+
// parsed YAML had; for manual records it is what the user typed. Either
69+
// may be empty at creation time (an unbuilt module).
70+
Image string `bson:"image,omitempty" json:"image,omitempty"`
71+
72+
// ImageName is the registry-friendly name used for build target paths and
73+
// image webhook matching. Required for manual records (enforced at the
74+
// service layer); for auto records it is derived from Image via
75+
// ExtractImageName, falling back to Name.
76+
ImageName string `bson:"image_name,omitempty" json:"image_name,omitempty"`
77+
ImagePath *ImagePathSpec `bson:"image_path,omitempty" json:"image_path,omitempty"`
78+
79+
// Ignored marks an auto-discovered module as hidden for this revision.
80+
// It is used as a tombstone when users delete an auto module, so later YAML
81+
// re-parses (for example saving variables) don't silently add it back.
82+
Ignored bool `bson:"ignored,omitempty" json:"ignored,omitempty"`
83+
84+
CreateTime int64 `bson:"create_time" json:"create_time"`
85+
UpdateTime int64 `bson:"update_time,omitempty" json:"update_time,omitempty"`
86+
}
87+
88+
func (ServiceModule) TableName() string {
89+
return "service_module"
90+
}

pkg/microservice/aslan/core/common/repository/models/task/model.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ type Task struct {
8585
Features []string `bson:"features" json:"features"`
8686
IsRestart bool `bson:"is_restart" json:"is_restart"`
8787
StorageEndpoint string `bson:"storage_endpoint" json:"storage_endpoint"`
88-
Events *models.Events `bson:"-" json:"events,omitempty"`
8988
}
9089

9190
func (Task) TableName() string {

pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,11 @@ type ImageAndServiceModule struct {
347347
type JobTaskFreestyleSpec struct {
348348
Properties JobProperties `bson:"properties" json:"properties" yaml:"properties"`
349349
Steps []*StepTask `bson:"steps" json:"steps" yaml:"steps"`
350-
Events *Events `bson:"-" json:"events" yaml:"events"`
351350
}
352351

353352
type JobTaskPluginSpec struct {
354353
Properties JobProperties `bson:"properties" json:"properties" yaml:"properties"`
355354
Plugin *PluginTemplate `bson:"plugin" json:"plugin" yaml:"plugin"`
356-
Events *Events `bson:"-" json:"events" yaml:"events"`
357355
}
358356

359357
type JobTaskBlueGreenDeploySpec struct {
@@ -701,6 +699,7 @@ type JobTaskApprovalSpec struct {
701699
DingTalkApproval *DingTalkApproval `bson:"dingtalk_approval" yaml:"dingtalk_approval,omitempty" json:"dingtalk_approval,omitempty"`
702700
WorkWXApproval *WorkWXApproval `bson:"workwx_approval" yaml:"workwx_approval,omitempty" json:"workwx_approval,omitempty"`
703701
ApprovalMessage string `bson:"approval_message" yaml:"approval_message,omitempty" json:"approval_message,omitempty"`
702+
ApprovalTitle string `bson:"approval_title" yaml:"approval_title,omitempty" json:"approval_title,omitempty"`
704703
}
705704

706705
type JobTaskWorkflowTriggerSpec struct {

pkg/microservice/aslan/core/common/repository/models/workflow_v4.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ func (l LarkApproval) GetNodeTypeKey() string {
251251
return strings.Join(keys, "-")
252252
}
253253

254+
func (l LarkApproval) GetNodeTypeTitleKey(title string) string {
255+
nodeTypeKey := l.GetNodeTypeKey()
256+
title = strings.TrimSpace(title)
257+
if title == "" {
258+
return nodeTypeKey
259+
}
260+
261+
return fmt.Sprintf("%s-%s", nodeTypeKey, title)
262+
}
263+
254264
// GetLarkApprovalNode convert approval node to lark sdk approval node
255265
func (l LarkApproval) GetLarkApprovalNode() (resp []*lark.ApprovalNode) {
256266
for _, node := range l.ApprovalNodes {
@@ -1192,6 +1202,7 @@ type ApprovalJobSpec struct {
11921202
WorkWXApproval *WorkWXApproval `bson:"workwx_approval" yaml:"workwx_approval,omitempty" json:"workwx_approval,omitempty"`
11931203
ApprovalMessage string `bson:"approval_message" yaml:"approval_message,omitempty" json:"approval_message,omitempty"`
11941204
ApprovalMessageSource config.DeploySourceType `bson:"approval_message_source" yaml:"approval_message_source,omitempty" json:"approval_message_source,omitempty"`
1205+
ApprovalTitle string `bson:"approval_title" yaml:"approval_title,omitempty" json:"approval_title,omitempty"`
11951206
}
11961207

11971208
type NotificationJobSpec struct {

0 commit comments

Comments
 (0)