Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipeline): implement template #956

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ database:
host: pg-sql
port: 5432
name: pipeline
version: 39
version: 40
timezone: Etc/UTC
pool:
idleconnections: 5
Expand Down
11,207 changes: 8,451 additions & 2,756 deletions pkg/component/internal/mock/app_public_service_server_mock.gen.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pkg/datamodel/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ type Pipeline struct {
Recipe *Recipe `gorm:"-"`
RecipeYAML string `gorm:"recipe_yaml"`

UseTemplate bool
TemplatePipelineUID uuid.UUID
TemplatePipelineReleaseUID uuid.UUID
TemplateOverrides datatypes.JSON `gorm:"type:jsonb"`

DefaultReleaseUID uuid.UUID
Sharing *Sharing `gorm:"type:jsonb"`
ShareCode string
Expand Down
8 changes: 8 additions & 0 deletions pkg/db/migration/000040_template.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

ALTER TABLE pipeline DROP COLUMN IF EXISTS template_overrides;
ALTER TABLE pipeline DROP COLUMN IF EXISTS template_pipeline_release_uid;
ALTER TABLE pipeline DROP COLUMN IF EXISTS template_pipeline_uid;
ALTER TABLE pipeline DROP COLUMN IF EXISTS use_template;

COMMIT;
15 changes: 15 additions & 0 deletions pkg/db/migration/000040_template.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BEGIN;

-- Add column to indicate if pipeline is using a template
ALTER TABLE pipeline ADD COLUMN IF NOT EXISTS use_template BOOLEAN DEFAULT FALSE;

-- Add column to store the UUID of the template pipeline being used
ALTER TABLE pipeline ADD COLUMN IF NOT EXISTS template_pipeline_uid UUID;

-- Add column to store the UUID of the specific template pipeline release being used
ALTER TABLE pipeline ADD COLUMN IF NOT EXISTS template_pipeline_release_uid UUID;

-- Add column to store JSON overrides for template customization
ALTER TABLE pipeline ADD COLUMN IF NOT EXISTS template_overrides JSONB;

COMMIT;
3 changes: 3 additions & 0 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ var (
// ErrAlreadyExists is used when a resource can't be created because it
// already exists.
ErrAlreadyExists = errmsg.AddMessage(fmt.Errorf("resource already exists"), "Resource already exists.")
// ErrCanNotUpdatePipelineWithTemplate is used when a request want to update
// a pipeline with template.
ErrCanNotUpdatePipelineWithTemplate = fmt.Errorf("can not update pipeline with template")
)
6 changes: 6 additions & 0 deletions pkg/handler/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ func (h *PublicHandler) CloneNamespacePipeline(ctx context.Context, req *pb.Clon

logger, _ := logger.GetZapLogger(ctx)

fmt.Println("0")
ns, err := h.service.GetNamespaceByID(ctx, req.NamespaceId)
if err != nil {
span.SetStatus(1, err.Error())
Expand All @@ -869,6 +870,7 @@ func (h *PublicHandler) CloneNamespacePipeline(ctx context.Context, req *pb.Clon
span.SetStatus(1, err.Error())
return nil, err
}
fmt.Println("1")

pbPipeline, err := h.service.CloneNamespacePipeline(
ctx,
Expand All @@ -878,6 +880,8 @@ func (h *PublicHandler) CloneNamespacePipeline(ctx context.Context, req *pb.Clon
req.GetTargetPipelineId(),
req.GetDescription(),
req.GetSharing(),
req.GetAsTemplate(),
req.GetTemplateOverrides(),
)
if err != nil {
span.SetStatus(1, err.Error())
Expand Down Expand Up @@ -928,6 +932,8 @@ func (h *PublicHandler) CloneNamespacePipelineRelease(ctx context.Context, req *
req.GetTargetPipelineId(),
req.GetDescription(),
req.GetSharing(),
req.GetAsTemplate(),
req.GetTemplateOverrides(),
)
if err != nil {
span.SetStatus(1, err.Error())
Expand Down
3 changes: 2 additions & 1 deletion pkg/middleware/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func AsGRPCError(err error) error {
errors.Is(err, service.ErrTriggerFail),
errors.Is(err, handler.ErrFieldMask),
errors.Is(err, handler.ErrSematicVersion),
errors.Is(err, handler.ErrUpdateMask):
errors.Is(err, handler.ErrUpdateMask),
errors.Is(err, errdomain.ErrCanNotUpdatePipelineWithTemplate):

code = codes.InvalidArgument
case
Expand Down
Loading
Loading