Skip to content

Commit

Permalink
new types
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Dec 18, 2024
1 parent ae92c51 commit 9a4bf76
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 2 deletions.
114 changes: 113 additions & 1 deletion tooling/templatize/pkg/pipeline/pipeline.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,50 @@
"title": "pipeline.schema.v1",
"type": "object",
"definitions": {
"variableRef": {
"type": "object",
"properties": {
"input": {
"type": "object",
"additionalProperties": false,
"properties": {
"step": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"step",
"name"
]
},
"configRef": {
"type": "string"
},
"value": {
"type": "string"
}
},
"oneOf": [
{
"required": [
"input"
]
},
{
"required": [
"configRef"
]
},
{
"required": [
"value"
]
}
]
},
"variable": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -86,7 +130,7 @@
},
"action": {
"type": "string",
"enum": ["ARM", "Shell"]
"enum": ["ARM", "Shell", "DelegateChildZoneExtension", "SetCertificateIssuer"]
},
"template": {
"type": "string"
Expand Down Expand Up @@ -115,6 +159,18 @@
},
"dryRun": {
"type": "object"
},
"vaultBaseUrl": {
"$ref": "#/definitions/variableRef"
},
"provider": {
"$ref": "#/definitions/variableRef"
},
"parentZoneName": {
"$ref": "#/definitions/variableRef"
},
"childZoneName": {
"$ref": "#/definitions/variableRef"
}
},
"oneOf": [
Expand Down Expand Up @@ -200,6 +256,62 @@
"required": [
"command"
]
},
{
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"action": {
"type": "string",
"enum": ["DelegateChildZoneExtension"]
},
"parentZoneName": {
"$ref": "#/definitions/variableRef"
},
"childZoneName": {
"$ref": "#/definitions/variableRef"
},
"dependsOn": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"parentZoneName",
"childZoneName"
]
},
{
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"action": {
"type": "string",
"enum": ["SetCertificateIssuer"]
},
"vaultBaseUrl": {
"$ref": "#/definitions/variableRef"
},
"provider": {
"$ref": "#/definitions/variableRef"
},
"dependsOn": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"vaultBaseUrl",
"provider"
]
}
],
"required": [
Expand Down
3 changes: 2 additions & 1 deletion tooling/templatize/pkg/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func RunStep(s Step, ctx context.Context, kubeconfigFile string, executionTarget
}
return output, nil
default:
return nil, fmt.Errorf("unsupported action type %q", s.ActionType())
fmt.Println("No implementation for action type - skip", s.ActionType())
return nil, nil
}
}

Expand Down
31 changes: 31 additions & 0 deletions tooling/templatize/pkg/pipeline/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func NewPlainPipelineFromBytes(filepath string, bytes []byte) (*Pipeline, error)
rg.Steps[i] = &ShellStep{}
case "ARM":
rg.Steps[i] = &ARMStep{}
case "DelegateChildZoneExtension":
rg.Steps[i] = &DelegateChildZoneStep{}
case "SetCertificateIssuer":
rg.Steps[i] = &SetCertificateIssuerStep{}
default:
return nil, fmt.Errorf("unknown action type %s", stepMeta.Action)
}
Expand All @@ -85,6 +89,7 @@ func mapToStruct(m any, s interface{}) error {
}
if err := yaml.Unmarshal(bytes, s); err != nil {
return err

}
return nil
}
Expand Down Expand Up @@ -200,6 +205,26 @@ func (s *ARMStep) Description() string {
return fmt.Sprintf("Step %s\n Kind: %s\n %s", s.Name, s.Action, strings.Join(details, "\n "))
}

type DelegateChildZoneStep struct {
StepMeta `yaml:",inline"`
ParentZoneName VariableRef `yaml:"parentZoneName"`
ChildZoneName VariableRef `yaml:"childZoneName"`
}

func (s *DelegateChildZoneStep) Description() string {
return fmt.Sprintf("Step %s\n Kind: %s", s.Name, s.Action)
}

type SetCertificateIssuerStep struct {
StepMeta `yaml:",inline"`
VaultBaseUrl VariableRef `yaml:"vaultBaseUrl"`
Provider VariableRef `yaml:"provider"`
}

func (s *SetCertificateIssuerStep) Description() string {
return fmt.Sprintf("Step %s\n Kind: %s", s.Name, s.Action)
}

type DryRun struct {
Variables []Variable `yaml:"variables,omitempty"`
Command string `yaml:"command,omitempty"`
Expand All @@ -212,6 +237,12 @@ type Variable struct {
Input *Input `yaml:"input,omitempty"`
}

type VariableRef struct {
ConfigRef string `yaml:"configRef,omitempty"`
Value string `yaml:"value,omitempty"`
Input *Input `yaml:"input,omitempty"`
}

type Input struct {
Name string `yaml:"name"`
Step string `yaml:"step"`
Expand Down
16 changes: 16 additions & 0 deletions tooling/templatize/testdata/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ resourceGroups:
action: ARM
template: templates/svc-cluster.bicep
parameters: test.bicepparam
- name: DelegateChildZoneBase
action: DelegateChildZoneExtension
parentZoneName:
value: bla
childZoneName:
value: blub
dependsOn:
- deploy
- name: issuerTest
action: SetCertificateIssuer
vaultBaseUrl:
value: bla
provider:
value: blub
dependsOn:
- deploy
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ resourceGroups:
action: ARM
template: templates/svc-cluster.bicep
parameters: ev2-precompiled-test.bicepparam
- name: DelegateChildZoneBase
action: DelegateChildZoneExtension
dependsOn:
- deploy
parentZoneName:
value: bla
childZoneName:
value: blub
- name: issuerTest
action: SetCertificateIssuer
dependsOn:
- deploy
vaultBaseUrl:
value: bla
provider:
value: blub
16 changes: 16 additions & 0 deletions tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ resourceGroups:
action: ARM
template: templates/svc-cluster.bicep
parameters: test.bicepparam
- name: DelegateChildZoneBase
action: DelegateChildZoneExtension
parentZoneName:
value: bla
childZoneName:
value: blub
dependsOn:
- deploy
- name: issuerTest
action: SetCertificateIssuer
vaultBaseUrl:
value: bla
provider:
value: blub
dependsOn:
- deploy

0 comments on commit 9a4bf76

Please sign in to comment.