Skip to content

Commit

Permalink
Dry-run for update command (Azure#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
bosesuneha authored and aamgayle committed Mar 23, 2023
1 parent b0bcb64 commit f5152f4
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 8 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/integration-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -250,6 +258,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -365,6 +381,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -480,6 +504,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -595,6 +627,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -710,6 +750,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -825,6 +873,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -940,6 +996,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -1055,6 +1119,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -1170,6 +1242,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down Expand Up @@ -1285,6 +1365,14 @@ jobs:
curl -m 3 $SERVICEIP:80
kill $tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down
48 changes: 40 additions & 8 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@ package cmd

import (
"embed"
"encoding/json"
"fmt"
"os"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/Azure/draft/pkg/addons"
"github.com/Azure/draft/pkg/config"
dryrunpkg "github.com/Azure/draft/pkg/dryrun"
"github.com/Azure/draft/pkg/templatewriter"
"github.com/Azure/draft/pkg/templatewriter/writers"
"github.com/Azure/draft/template"
)

type updateCmd struct {
dest string
provider string
addon string
flagVariables []string
userInputs map[string]string
templateWriter templatewriter.TemplateWriter
addonFS embed.FS
dest string
provider string
addon string
flagVariables []string
userInputs map[string]string
templateWriter templatewriter.TemplateWriter
addonFS embed.FS
templateVariableRecorder config.TemplateVariableRecorder
}

var dryRunRecorder *dryrunpkg.DryRunRecorder

func newUpdateCmd() *cobra.Command {
uc := &updateCmd{}
// updateCmd represents the update command
Expand Down Expand Up @@ -81,7 +88,32 @@ func (uc *updateCmd) run() error {
}
log.Debugf("addonInputs is: %s", uc.userInputs)

return addons.GenerateAddon(template.Addons, uc.provider, uc.addon, uc.dest, uc.userInputs, uc.templateWriter)
if dryRun {
dryRunRecorder = dryrunpkg.NewDryRunRecorder()
uc.templateVariableRecorder = dryRunRecorder
uc.templateWriter = dryRunRecorder
for k, v := range uc.userInputs {
uc.templateVariableRecorder.Record(k, v)
}
}

err = addons.GenerateAddon(template.Addons, uc.provider, uc.addon, uc.dest, uc.userInputs, uc.templateWriter)

if dryRun {
dryRunText, err := json.MarshalIndent(dryRunRecorder.DryRunInfo, "", TWO_SPACES)
if err != nil {
return err
}
fmt.Println(string(dryRunText))
if dryRunFile != "" {
log.Printf("writing dry run info to file %s", dryRunFile)
err = os.WriteFile(dryRunFile, dryRunText, 0644)
if err != nil {
return err
}
}
}
return err
}

func init() {
Expand Down
8 changes: 8 additions & 0 deletions test/gen_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ languageVariables:
curl -m 3 \$SERVICEIP:$serviceport
kill \$tunnelPID
- run: ./draft -b main -v generate-workflow -d ./langtest/ -c someAksCluster -r someRegistry -g someResourceGroup --container-name someContainer
- name: Execute dry run for update command
run: |
mkdir -p test/temp
./draft --dry-run --dry-run-file test/temp/update_dry_run.json update -d ./langtest/ $ingress_test_args
- name: Validate JSON
run: |
npm install -g ajv-cli@5.0.0
ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json
- run: ./draft -v update -d ./langtest/ $ingress_test_args
- name: Check default namespace
if: steps.deploy.outcome != 'success'
Expand Down
71 changes: 71 additions & 0 deletions test/update_dry_run_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/object1670282842.json",
"title": "Root",
"type": "object",
"properties": {
"variables": {
"$id": "#root/variables",
"title": "Variables",
"type": "object",
"properties": {
"ingress-host": {
"$id": "#root/variables/ingress-host",
"title": "IngressHost",
"type": "string",
"default": "",
"pattern": "^.*$"
},
"ingress-tls-cert-keyvault-uri": {
"$id": "#root/variables/ingress-tls-cert-keyvault-uri",
"title": "IngressTlsCertKeyvaultUri",
"type": "string",
"default": "",
"pattern": "^.*$"
},
"ingress-use-osm-mtls": {
"$id": "#root/variables/ingress-use-osm-mtls",
"title": "IngressUseOsmMtls",
"type": "string",
"default": "",
"pattern": "^.*$"
},
"service-name": {
"$id": "#root/variables/service-name",
"title": "ServiceName",
"type": "string",
"default": "",
"pattern": "^.*$"
},
"service-namespace": {
"$id": "#root/variables/service-namespace",
"title": "ServiceNamespace",
"type": "string",
"default": "",
"pattern": "^.*$"
},
"service-port": {
"$id": "#root/variables/service-port",
"title": "ServicePort",
"type": "string",
"default": "",
"pattern": "^.*$"
}
}
},
"filesToWrite": {
"$id": "#root/filesToWrite",
"title": "FilesToWrite",
"type": "array",
"default": [],
"items": {
"$id": "#root/filesToWrite/items",
"title": "Items",
"type": "string",
"default": "",
"pattern": "^.*$"
}
}
}
}

0 comments on commit f5152f4

Please sign in to comment.