diff --git a/bcs-services/bcs-bscp/cmd/data-service/service/hook.go b/bcs-services/bcs-bscp/cmd/data-service/service/hook.go index 4d60f87bb8..a4a4e0cfea 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/service/hook.go +++ b/bcs-services/bcs-bscp/cmd/data-service/service/hook.go @@ -25,6 +25,7 @@ import ( pbbase "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/core/base" pbhook "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/core/hook" pbds "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/protocol/data-service" + "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/tools" "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types" ) @@ -68,6 +69,10 @@ func (s *Service) CreateHook(ctx context.Context, req *pbds.CreateHookReq) (*pbd } // 2. create hook revision + // it must be the first hook revision, so no need to check the revision name uniqueness + if req.Spec.RevisionName == "" { + req.Spec.RevisionName = tools.GenerateRevisionName() + } revision := &table.HookRevision{ Spec: &table.HookRevisionSpec{ Name: req.Spec.RevisionName, diff --git a/bcs-services/bcs-bscp/cmd/data-service/service/hook_revision.go b/bcs-services/bcs-bscp/cmd/data-service/service/hook_revision.go index 41efc2b03d..a11bad2dc2 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/service/hook_revision.go +++ b/bcs-services/bcs-bscp/cmd/data-service/service/hook_revision.go @@ -40,7 +40,7 @@ func (s *Service) CreateHookRevision(ctx context.Context, if _, err := s.dao.HookRevision().GetByName(kt, req.Attachment.BizId, req.Attachment.HookId, req.Spec.Name); err == nil { - return nil, fmt.Errorf("hook name %s already exists", req.Spec.Name) + return nil, fmt.Errorf("hook revision name %s already exists", req.Spec.Name) } spec, err := req.Spec.HookRevisionSpec()