Skip to content

Commit

Permalink
add v3 validation and --ignore-validation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gunjan5 committed Dec 8, 2017
1 parent 473769a commit e08dd2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
13 changes: 12 additions & 1 deletion calicoctl/commands/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
"github.com/projectcalico/calicoctl/calicoctl/commands/v1resourceloader"
"github.com/projectcalico/libcalico-go/lib/apis/v1/unversioned"
conversion "github.com/projectcalico/libcalico-go/lib/upgrade/etcd/conversionv1v3"
validator "github.com/projectcalico/libcalico-go/lib/validator/v3"
)

func Convert(args []string) {
doc := constants.DatastoreIntro + `Usage:
calicoctl convert --filename=<FILENAME>
[--output=<OUTPUT>]
[--output=<OUTPUT>] [--ignore-validation]
Examples:
# Convert the contents of policy.yaml to v3 policy.
Expand All @@ -49,6 +50,7 @@ Options:
"-" loads from stdin.
-o --output=<OUTPUT FORMAT> Output format. One of: yaml or json.
[Default: yaml]
--ignore-validation Skip validation on the converted manifest.
Description:
Expand Down Expand Up @@ -106,6 +108,15 @@ Description:
rom.SetDeletionGracePeriodSeconds(nil)
rom.SetClusterName("")

ignoreValidation := argutils.ArgBoolOrFalse(parsedArgs, "--ignore-validation")
if !ignoreValidation {
if err := validator.Validate(v3Resource); err != nil {
fmt.Printf("Converted manifest resource(s) failed validation: %s\n", err)
fmt.Printf("Re-run the command with '--ignore-validation' flag to see the converted output.")
os.Exit(1)
}
}

results = append(results, v3Resource)
}

Expand Down
10 changes: 5 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import:
- ssh/terminal
- package: github.com/projectcalico/go-yaml-wrapper
- package: github.com/projectcalico/libcalico-go
version: e102717dbcf5e66fd539363b53be5f0fe3635526
version: 7fdfaa3a86b1f6de47000ae4772b87e8979cde6f
subpackages:
- lib/apis/v3
- lib/clientv3
Expand Down

0 comments on commit e08dd2d

Please sign in to comment.