Skip to content

Commit

Permalink
chore(ff): add ff for upserting pipeline. (#179)
Browse files Browse the repository at this point in the history
* chore(ff): add ff for upserting pipeline.

* chore(ff): add ff for upserting pipeline.

* chore(ff): add ff for upserting pipeline.
  • Loading branch information
DanielaS12 authored Sep 18, 2023
1 parent 9e0f5bb commit 22ef6f7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
56 changes: 32 additions & 24 deletions pkg/dinghyfile/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/dinghyfile/plank_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/settings/global/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/util/plank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions pkg/util/plank_readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/web/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ func (wa *WebAPI) buildPipelines(
Ignore: s.IgnoreUsersPermissions,
Logger: l,
},
UpsertPipelineUsingOrcaTaskEnabled: s.UpsertPipelineUsingOrcaTaskEnabled,
}

if shouldRunValidation(p, s, l) {
Expand Down

0 comments on commit 22ef6f7

Please sign in to comment.