Skip to content

Commit

Permalink
fix comment issues
Browse files Browse the repository at this point in the history
Signed-off-by: cezhang <c1zhang.dev@gmail.com>
  • Loading branch information
cezhang committed Jan 9, 2023
1 parent 3496c35 commit cc43d37
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 0 additions & 2 deletions pkg/appfile/dryrun/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ var _ = Describe("Test Live-Diff", func() {
Expect(k8sClient.Create(context.Background(), un)).Should(Succeed())
}
ctx := context.Background()
//Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "vela-system"}})).Should(Succeed())
applyFile("diff-input-app-with-externals.yaml", "default")
applyFile("diff-apprevision.yaml", "default")
app := &v1beta1.Application{}
Expand All @@ -188,7 +187,6 @@ var _ = Describe("Test Live-Diff", func() {
Expect(runDiff()).Should(ContainSubstring("\"myworker\" not found"))
applyFile("td-myingress.yaml", "vela-system")
applyFile("cd-myworker.yaml", "vela-system")
//applyFile("wd-deploy.yaml", "vela-system")
applyFile("wd-ref-objects.yaml", "vela-system")
Expect(runDiff()).Should(ContainSubstring("\"deploy-livediff-demo\" not found"))
applyFile("external-workflow.yaml", "default")
Expand Down
38 changes: 28 additions & 10 deletions references/cli/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ import (
// DryRunCmdOptions contains dry-run cmd options
type DryRunCmdOptions struct {
cmdutil.IOStreams
ApplicationFiles []string
DefinitionFile string
OfflineMode bool
MergeOrphanFiles bool
ApplicationFiles []string
DefinitionFile string
OfflineMode bool
MergeStandaloneFiles bool
}

// NewDryRunCommand creates `dry-run` command
Expand All @@ -70,8 +70,26 @@ func NewDryRunCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command
You can also specify a remote url for app:
vela dry-run -d /definition/directory/or/file/ -f https://remote-host/app.yaml
And more, you can specify policy and workflow with application file:
vela dry-run -d /definition/directory/or/file/ -f /path/to/app.yaml -f /path/to/policy.yaml -f /path/to/workflow.yaml, OR
vela dry-run -d /definition/directory/or/file/ -f /path/to/app.yaml,/path/to/policy.yaml,/path/to/workflow.yaml
Additionally, if the provided policy and workflow files are not referenced by application file, warning message will show up
and those files will be ignored. You can use "merge" flag to make those standalone files effective:
vela dry-run -d /definition/directory/or/file/ -f /path/to/app.yaml,/path/to/policy.yaml,/path/to/workflow.yaml --merge
Limitation:
1. Only support one object per file(yaml) for "-f" flag. More support will be added in the future improvement.
2. Dry Run with policy and workflow will only take override/topology policies and deploy workflow step into considerations. Other workflow step will be ignored.
`,
Example: `
# dry-run application
vela dry-run -f app.yaml
# dry-run application with policy and workflow
vela dry-run -f app.yaml -f policy.yaml -f workflow.yaml
`,
Example: "vela dry-run",
Annotations: map[string]string{
types.TagCommandType: types.TypeApp,
},
Expand All @@ -96,10 +114,10 @@ You can also specify a remote url for app:
},
}

cmd.Flags().StringSliceVarP(&o.ApplicationFiles, "files", "f", []string{"app.yaml"}, "application related file names")
cmd.Flags().StringSliceVarP(&o.ApplicationFiles, "file", "f", []string{"app.yaml"}, "application related file names")
cmd.Flags().StringVarP(&o.DefinitionFile, "definition", "d", "", "specify a definition file or directory, it will only be used in dry-run rather than applied to K8s cluster")
cmd.Flags().BoolVar(&o.OfflineMode, "offline", false, "Run `dry-run` in offline / local mode, all validation steps will be skipped")
cmd.Flags().BoolVar(&o.MergeOrphanFiles, "merge", false, "Merge orphan files to produce dry-run results")
cmd.Flags().BoolVar(&o.MergeStandaloneFiles, "merge", false, "Merge standalone files to produce dry-run results")
addNamespaceAndEnvArg(cmd)
cmd.SetOut(ioStreams.Out)
return cmd
Expand Down Expand Up @@ -316,7 +334,7 @@ func readApplicationFromFiles(cmdOption *DryRunCmdOptions, buff *bytes.Buffer) (
}

// workflow not referenced by application
if !cmdOption.MergeOrphanFiles {
if !cmdOption.MergeStandaloneFiles {
if wf != nil &&
((app.Spec.Workflow != nil && app.Spec.Workflow.Ref != wf.Name) || app.Spec.Workflow == nil) {
buff.WriteString(fmt.Sprintf("WARNING: workflow %s not referenced by application\n\n", wf.Name))
Expand All @@ -335,8 +353,8 @@ func readApplicationFromFiles(cmdOption *DryRunCmdOptions, buff *bytes.Buffer) (
}

for _, policy := range policies {
// check orphan policies
if _, exist := policyNameMap[policy.Name]; !exist && !cmdOption.MergeOrphanFiles {
// check standalone policies
if _, exist := policyNameMap[policy.Name]; !exist && !cmdOption.MergeStandaloneFiles {
buff.WriteString(fmt.Sprintf("WARNING: policy %s not referenced by application\n\n", policy.Name))
continue
}
Expand Down
10 changes: 5 additions & 5 deletions references/cli/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,33 +189,33 @@ var _ = Describe("Testing dry-run", func() {
c := common2.Args{}
c.SetConfig(cfg)
c.SetClient(k8sClient)
opt := DryRunCmdOptions{ApplicationFiles: []string{"test-data/dry-run/testing-dry-run-5.yaml", "test-data/dry-run/testing-wf.yaml", "test-data/dry-run/testing-policy.yaml"}, OfflineMode: false, MergeOrphanFiles: true}
opt := DryRunCmdOptions{ApplicationFiles: []string{"test-data/dry-run/testing-dry-run-5.yaml", "test-data/dry-run/testing-wf.yaml", "test-data/dry-run/testing-policy.yaml"}, OfflineMode: false, MergeStandaloneFiles: true}
buff, err := DryRunApplication(&opt, c, "")
Expect(err).Should(BeNil())
Expect(buff.String()).Should(ContainSubstring("# Application(testing-app with topology deploy-somewhere)"))
Expect(buff.String()).Should(ContainSubstring("name: testing-dryrun"))
Expect(buff.String()).Should(ContainSubstring("kind: Deployment"))
})

It("Testing dry-run with orphan policy", func() {
It("Testing dry-run with standalone policy", func() {

c := common2.Args{}
c.SetConfig(cfg)
c.SetClient(k8sClient)
opt := DryRunCmdOptions{ApplicationFiles: []string{"test-data/dry-run/testing-dry-run-5.yaml", "test-data/dry-run/testing-policy.yaml"}, OfflineMode: false, MergeOrphanFiles: false}
opt := DryRunCmdOptions{ApplicationFiles: []string{"test-data/dry-run/testing-dry-run-5.yaml", "test-data/dry-run/testing-policy.yaml"}, OfflineMode: false, MergeStandaloneFiles: false}
buff, err := DryRunApplication(&opt, c, "")
Expect(err).Should(BeNil())
Expect(buff.String()).Should(ContainSubstring("WARNING: policy deploy-somewhere not referenced by application"))
Expect(buff.String()).Should(ContainSubstring("name: testing-dryrun"))
Expect(buff.String()).Should(ContainSubstring("kind: Deployment"))
})

It("Testing dry-run with orphan workflow", func() {
It("Testing dry-run with standalone workflow", func() {

c := common2.Args{}
c.SetConfig(cfg)
c.SetClient(k8sClient)
opt := DryRunCmdOptions{ApplicationFiles: []string{"test-data/dry-run/testing-dry-run-5.yaml", "test-data/dry-run/testing-wf.yaml"}, OfflineMode: false, MergeOrphanFiles: false}
opt := DryRunCmdOptions{ApplicationFiles: []string{"test-data/dry-run/testing-dry-run-5.yaml", "test-data/dry-run/testing-wf.yaml"}, OfflineMode: false, MergeStandaloneFiles: false}
buff, err := DryRunApplication(&opt, c, "")
Expect(err).Should(BeNil())
Expect(buff.String()).Should(ContainSubstring("WARNING: workflow testing-wf not referenced by application"))
Expand Down

0 comments on commit cc43d37

Please sign in to comment.