From 22ef6f78d576aea0d194f91a21b9dc70ec22e9de Mon Sep 17 00:00:00 2001 From: DanielaS12 <111055962+DanielaS12@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:09:52 +0300 Subject: [PATCH] chore(ff): add ff for upserting pipeline. (#179) * chore(ff): add ff for upserting pipeline. * chore(ff): add ff for upserting pipeline. * chore(ff): add ff for upserting pipeline. --- go.mod | 2 +- go.sum | 2 ++ pkg/dinghyfile/builder.go | 56 +++++++++++++++++++-------------- pkg/dinghyfile/plank_mock.go | 14 +++++++++ pkg/settings/global/settings.go | 2 ++ pkg/util/plank.go | 1 + pkg/util/plank_readonly.go | 13 ++++++++ pkg/web/routes.go | 1 + 8 files changed, 66 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 158d8bb8..e3ba58e2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/armory/dinghy require ( github.com/Masterminds/sprig/v3 v3.1.0 github.com/armory/go-yaml-tools v0.0.2 - github.com/armory/plank/v4 v4.1.1 + github.com/armory/plank/v4 v4.1.2 github.com/dlclark/regexp2 v1.7.0 github.com/go-redis/redis v6.14.1+incompatible github.com/golang/mock v1.3.1 diff --git a/go.sum b/go.sum index b7046ea3..efe27dbf 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/armory/go-yaml-tools v0.0.2 h1:IYAbeGQJQKFwBAdl4u9IVrENgHjjUsOxZRSTvy github.com/armory/go-yaml-tools v0.0.2/go.mod h1:LasFFVo6zuV334Pmx7Diq9L3muOUUI8MF79QUFC1jq0= github.com/armory/plank/v4 v4.1.1 h1:z/+PCCtra5EW0tfOCeE5K5ewRTIOAsYMxP8zqhdXcS8= github.com/armory/plank/v4 v4.1.1/go.mod h1:xH8nrFDGCXEL+zZpLMxrdTq395DHvtrHgJmEdg9Ygo4= +github.com/armory/plank/v4 v4.1.2 h1:FwDazjvSE5S6BUZ/Pmr6wnis8/OixhDz2LTnGiOp/g0= +github.com/armory/plank/v4 v4.1.2/go.mod h1:xH8nrFDGCXEL+zZpLMxrdTq395DHvtrHgJmEdg9Ygo4= github.com/aws/aws-sdk-go v1.28.9 h1:grIuBQc+p3dTRXerh5+2OxSuWFi0iXuxbFdTSg0jaW0= github.com/aws/aws-sdk-go v1.28.9/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= diff --git a/pkg/dinghyfile/builder.go b/pkg/dinghyfile/builder.go index 28e1f9e1..19d80e0f 100644 --- a/pkg/dinghyfile/builder.go +++ b/pkg/dinghyfile/builder.go @@ -42,26 +42,27 @@ type Parser interface { // PipelineBuilder is responsible for downloading dinghyfiles/modules, compiling them, and sending them to Spinnaker type PipelineBuilder struct { - Downloader Downloader - Depman DependencyManager - TemplateRepo string - TemplateOrg string - DinghyfileName string - Client util.PlankClient - DeleteStalePipelines bool - AutolockPipelines string - EventClient events.EventClient - Parser Parser - Logger log.DinghyLog - Ums []Unmarshaller - Notifiers []notifiers.Notifier - PushRaw map[string]interface{} - GlobalVariablesMap map[string]interface{} - RepositoryRawdataProcessing bool - RebuildingModules bool - Action pipebuilder.BuilderAction - JsonValidationDisabled bool - UserWriteAccessValidation UserWriteAccessValidation + Downloader Downloader + Depman DependencyManager + TemplateRepo string + TemplateOrg string + DinghyfileName string + Client util.PlankClient + DeleteStalePipelines bool + AutolockPipelines string + EventClient events.EventClient + Parser Parser + Logger log.DinghyLog + Ums []Unmarshaller + Notifiers []notifiers.Notifier + PushRaw map[string]interface{} + GlobalVariablesMap map[string]interface{} + RepositoryRawdataProcessing bool + RebuildingModules bool + Action pipebuilder.BuilderAction + JsonValidationDisabled bool + UserWriteAccessValidation UserWriteAccessValidation + UpsertPipelineUsingOrcaTaskEnabled bool } // DependencyManager is an interface for assigning dependencies and looking up root nodes @@ -467,10 +468,17 @@ func (b *PipelineBuilder) updatePipelines(dinghyfile Dinghyfile, pusher string) p.Lock() } - if err := b.Client.UpsertPipeline(p, p.ID, ""); err != nil { - err = unwrapFront50Error(err) - b.Logger.Errorf("Upsert failed: %s", err.Error()) - return err + if b.UpsertPipelineUsingOrcaTaskEnabled { + if err := b.Client.UpsertPipelineUsingOrca(p, p.ID, ""); err != nil { + b.Logger.Errorf("Upsert failed: %s", err.Error()) + return err + } + } else { + if err := b.Client.UpsertPipeline(p, p.ID, ""); err != nil { + err = unwrapFront50Error(err) + b.Logger.Errorf("Upsert failed: %s", err.Error()) + return err + } } b.Logger.Info("Upsert succeeded.") } diff --git a/pkg/dinghyfile/plank_mock.go b/pkg/dinghyfile/plank_mock.go index cf912217..f5d7d782 100644 --- a/pkg/dinghyfile/plank_mock.go +++ b/pkg/dinghyfile/plank_mock.go @@ -189,6 +189,20 @@ func (mr *MockPlankClientMockRecorder) UpsertPipeline(arg0, arg1, arg2 interface return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsertPipeline", reflect.TypeOf((*MockPlankClient)(nil).UpsertPipeline), arg0, arg1, arg2) } +// UpsertPipeline mocks base method. +func (m *MockPlankClient) UpsertPipelineUsingOrca(arg0 plank.Pipeline, arg1, arg2 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpsertPipelineUsingOrca", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpsertPipeline indicates an expected call of UpsertPipeline. +func (mr *MockPlankClientMockRecorder) UpsertPipelineUsingOrca(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsertPipelineUsingOrca", reflect.TypeOf((*MockPlankClient)(nil).UpsertPipeline), arg0, arg1, arg2) +} + // UseGateEndpoints mocks base method. func (m *MockPlankClient) UseGateEndpoints() { m.ctrl.T.Helper() diff --git a/pkg/settings/global/settings.go b/pkg/settings/global/settings.go index 510526c6..29b069b7 100644 --- a/pkg/settings/global/settings.go +++ b/pkg/settings/global/settings.go @@ -165,6 +165,8 @@ type Settings struct { IgnoreUsersPermissions []string `json:"ignoreUsersWritePermissions" yaml:"ignoreUsersWritePermissions"` // Enable processing of multiple branches in single repository MultipleBranchesEnabled bool `json:"multipleBranchesEnabled" yaml:"multipleBranchesEnabled"` + // Enable using savePipeline and updatePipeline tasks from Orca + UpsertPipelineUsingOrcaTaskEnabled bool `json:"upsertPipelineUsingOrcaTaskEnabled" yaml:"upsertPipelineUsingOrcaTaskEnabled"` } type Sqlconfig struct { diff --git a/pkg/util/plank.go b/pkg/util/plank.go index 414627bb..351fb72e 100644 --- a/pkg/util/plank.go +++ b/pkg/util/plank.go @@ -13,6 +13,7 @@ type PlankClient interface { GetPipelines(string, string) ([]plank.Pipeline, error) DeletePipeline(plank.Pipeline, string) error UpsertPipeline(plank.Pipeline, string, string) error + UpsertPipelineUsingOrca(plank.Pipeline, string, string) error ResyncFiat(string) error ArmoryEndpointsEnabled() bool EnableArmoryEndpoints() diff --git a/pkg/util/plank_readonly.go b/pkg/util/plank_readonly.go index 7061d3b1..129f39ff 100644 --- a/pkg/util/plank_readonly.go +++ b/pkg/util/plank_readonly.go @@ -79,6 +79,19 @@ func (p *PlankReadOnly) UpsertPipeline(pipe plank.Pipeline, appName string, trac return nil } +func (p *PlankReadOnly) UpsertPipelineUsingOrca(pipe plank.Pipeline, appName string, traceparent string) error { + // This is getting a little complex + // When a pipeline does not exists dinghy create it so it can be referenced + // Its a recursive call so it loops forever if this temp pipeline is not created + if p.tempPipes == nil { + p.tempPipes = &[]plank.Pipeline{} + } + // Auto generate a dummy id + pipe.ID = fmt.Sprintf("auto-generated-dummy-id-%v", uuid.New().String()) + (*p.tempPipes) = append(*p.tempPipes, pipe) + return nil +} + func (p *PlankReadOnly) UserRoles(username, traceparent string) ([]string, error) { return p.Plank.UserRoles(username, traceparent) } diff --git a/pkg/web/routes.go b/pkg/web/routes.go index 4fe01fbb..81aea5f1 100644 --- a/pkg/web/routes.go +++ b/pkg/web/routes.go @@ -650,6 +650,7 @@ func (wa *WebAPI) buildPipelines( Ignore: s.IgnoreUsersPermissions, Logger: l, }, + UpsertPipelineUsingOrcaTaskEnabled: s.UpsertPipelineUsingOrcaTaskEnabled, } if shouldRunValidation(p, s, l) {