Skip to content

Commit

Permalink
depends on validation and pipeline fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Nov 21, 2024
1 parent 3f4ce25 commit 964d492
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dev-infrastructure/region-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ serviceGroup: Microsoft.Azure.ARO.Test
rolloutName: Region Rollout
resourceGroups:
- name: {{ .regionRG }}
subscription: {{ .serviceClusterSubscription }}
subscription: {{ .svc.subscription }}
steps:
- name: region
action: ARM
Expand Down
4 changes: 2 additions & 2 deletions dev-infrastructure/svc-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
serviceGroup: Microsoft.Azure.ARO.Test
rolloutName: Service Cluster Rollout
resourceGroups:
- name: {{ .serviceClusterRG }}
subscription: {{ .serviceClusterSubscription }}
- name: {{ .svc.rg }}
subscription: {{ .svc.subscription }}
aksCluster: {{ .aksName }}
steps:
- name: svc
Expand Down
2 changes: 1 addition & 1 deletion tooling/templatize/cmd/pipeline/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (o *ValidatedPipelineOptions) Complete() (*PipelineOptions, error) {

pipeline, err := pipeline.NewPipelineFromFile(o.PipelineFile, completed.Config)
if err != nil {
return nil, fmt.Errorf("failed to load pipeline file %s: %w", o.PipelineFile, err)
return nil, fmt.Errorf("failed to load pipeline %s: %w", o.PipelineFile, err)
}

return &PipelineOptions{
Expand Down
2 changes: 1 addition & 1 deletion tooling/templatize/cmd/pipeline/run/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (o *RawRunOptions) Validate() (*ValidatedRunOptions, error) {
if err != nil {
return nil, err
}
// todo validate

return &ValidatedRunOptions{
validatedRunOptions: &validatedRunOptions{
RawRunOptions: o,
Expand Down
38 changes: 38 additions & 0 deletions tooling/templatize/pkg/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func NewPipelineFromFile(pipelineFilePath string, vars config.Variables) (*Pipel
if err != nil {
return nil, err
}
err = pipeline.Validate()
if err != nil {
return nil, err
}
return pipeline, nil
}

Expand Down Expand Up @@ -139,3 +143,37 @@ func (s *step) description() string {
}
return fmt.Sprintf("Step %s\n Kind: %s\n %s", s.Name, s.Action, strings.Join(details, "\n "))
}

func (p *Pipeline) Validate() error {
for _, rg := range p.ResourceGroups {
err := rg.Validate()
if err != nil {
return err
}
}
return nil
}

func (rg *resourceGroup) Validate() error {
if rg.Name == "" {
return fmt.Errorf("resource group name is required")
}
if rg.Subscription == "" {
return fmt.Errorf("subscription is required")
}

// validate step dependencies
// todo - check for circular dependencies
stepMap := make(map[string]bool)
for _, step := range rg.Steps {
stepMap[step.Name] = true
}
for _, step := range rg.Steps {
for _, dep := range step.DependsOn {
if !stepMap[dep] {
return fmt.Errorf("invalid dependency from step %s to %s", step.Name, dep)
}
}
}
return nil
}
1 change: 1 addition & 0 deletions tooling/templatize/pkg/pipeline/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type step struct {
Env []EnvVar `yaml:"env"`
Template string `yaml:"template"`
Parameters string `yaml:"parameters"`
DependsOn []string `yaml:"dependsOn"`
}

type EnvVar struct {
Expand Down

0 comments on commit 964d492

Please sign in to comment.