From 9a4bf76a6195e363bf21859632e99a8f7620c3b6 Mon Sep 17 00:00:00 2001 From: Gerd Oberlechner Date: Wed, 18 Dec 2024 15:11:43 +0100 Subject: [PATCH] new types Signed-off-by: Gerd Oberlechner --- .../pkg/pipeline/pipeline.schema.v1.json | 114 +++++++++++++++++- tooling/templatize/pkg/pipeline/run.go | 3 +- tooling/templatize/pkg/pipeline/types.go | 31 +++++ tooling/templatize/testdata/pipeline.yaml | 16 +++ ...ure_TestProcessPipelineForEV2pipeline.yaml | 16 +++ .../testdata/zz_fixture_TestRawOptions.yaml | 16 +++ 6 files changed, 194 insertions(+), 2 deletions(-) diff --git a/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json b/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json index 3c1bb8225..25c20e238 100644 --- a/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json +++ b/tooling/templatize/pkg/pipeline/pipeline.schema.v1.json @@ -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": { @@ -86,7 +130,7 @@ }, "action": { "type": "string", - "enum": ["ARM", "Shell"] + "enum": ["ARM", "Shell", "DelegateChildZoneExtension", "SetCertificateIssuer"] }, "template": { "type": "string" @@ -115,6 +159,18 @@ }, "dryRun": { "type": "object" + }, + "vaultBaseUrl": { + "$ref": "#/definitions/variableRef" + }, + "provider": { + "$ref": "#/definitions/variableRef" + }, + "parentZoneName": { + "$ref": "#/definitions/variableRef" + }, + "childZoneName": { + "$ref": "#/definitions/variableRef" } }, "oneOf": [ @@ -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": [ diff --git a/tooling/templatize/pkg/pipeline/run.go b/tooling/templatize/pkg/pipeline/run.go index 0589f468a..279e4e682 100644 --- a/tooling/templatize/pkg/pipeline/run.go +++ b/tooling/templatize/pkg/pipeline/run.go @@ -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 } } diff --git a/tooling/templatize/pkg/pipeline/types.go b/tooling/templatize/pkg/pipeline/types.go index 30d6c50a5..5e04ee19b 100644 --- a/tooling/templatize/pkg/pipeline/types.go +++ b/tooling/templatize/pkg/pipeline/types.go @@ -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) } @@ -85,6 +89,7 @@ func mapToStruct(m any, s interface{}) error { } if err := yaml.Unmarshal(bytes, s); err != nil { return err + } return nil } @@ -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"` @@ -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"` diff --git a/tooling/templatize/testdata/pipeline.yaml b/tooling/templatize/testdata/pipeline.yaml index 6ac26dcbb..d1f7139a2 100644 --- a/tooling/templatize/testdata/pipeline.yaml +++ b/tooling/templatize/testdata/pipeline.yaml @@ -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 diff --git a/tooling/templatize/testdata/zz_fixture_TestProcessPipelineForEV2pipeline.yaml b/tooling/templatize/testdata/zz_fixture_TestProcessPipelineForEV2pipeline.yaml index 7448f9363..b77f958a3 100644 --- a/tooling/templatize/testdata/zz_fixture_TestProcessPipelineForEV2pipeline.yaml +++ b/tooling/templatize/testdata/zz_fixture_TestProcessPipelineForEV2pipeline.yaml @@ -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 diff --git a/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml b/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml index dbe5f20d8..80c3b541d 100644 --- a/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml +++ b/tooling/templatize/testdata/zz_fixture_TestRawOptions.yaml @@ -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