Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move JSON/YAML precheck into Documentation target #10952

Merged
merged 3 commits into from Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions Documentation/Makefile
Expand Up @@ -7,7 +7,7 @@ default: html
clean:
-$(QUIET)rm -rf _build

builder-image:
builder-image: Dockerfile requirements.txt
$(QUIET)tar c requirements.txt Dockerfile \
| docker build --tag cilium/docs-builder -

Expand All @@ -22,9 +22,11 @@ update-cmdref: builder-image
-$(QUIET)rm -rf cmdref/cilium*.md
$(QUIET)$(DOCKER_RUN) ./update-cmdref.sh

check-cmdref: builder-image update-cmdref
check: builder-image update-cmdref
@$(ECHO_CHECK) cmdref
$(QUIET)$(DOCKER_RUN) ./check-cmdref.sh
@$(ECHO_CHECK) examples
$(QUIET)$(DOCKER_RUN) ./check-examples.sh

ifeq ($(V),0)
SPHINX_OPTS += -q
Expand Down
23 changes: 23 additions & 0 deletions Documentation/check-examples.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source_dir="$(cd "${script_dir}/.." && pwd)"
examples_dir="${source_dir}/examples"
cilium="${source_dir}/cilium/cilium"

JSON_FILES=$(find ${examples_dir} \
-wholename "*/policies/*.json" \
-o -wholename "*/demo/*.json")
YAML_FILES=$(find ${examples_dir}/policies -name "*.yaml")

for f in $JSON_FILES; do
${cilium} policy validate --verbose=false "$f"
done

for f in $YAML_FILES; do
yamllint -c "$script_dir/yaml.config" "$f"
done
5 changes: 3 additions & 2 deletions Documentation/cmdref/cilium_policy_validate.md
Expand Up @@ -15,8 +15,9 @@ cilium policy validate <path> [flags]
### Options

```
-h, --help help for validate
--print Print policy after validation
-h, --help help for validate
--print Print policy after validation
-v, --verbose Enable verbose output (default true)
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions Documentation/requirements.txt
Expand Up @@ -27,3 +27,4 @@ recommonmark==0.4.0
sphinxcontrib-spelling==4.2.0
sphinx-version-warning==1.1.2
semver==2.9.0
yamllint==1.22.0
File renamed without changes.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -471,7 +471,7 @@ install-manpages:
mandb

postcheck: build
$(QUIET)$(MAKE) $(SUBMAKEOPTS) -C Documentation update-cmdref check-cmdref
$(QUIET)$(MAKE) $(SUBMAKEOPTS) -C Documentation update-cmdref check
@$(ECHO_CHECK) contrib/scripts/lock-check.sh
$(QUIET) contrib/scripts/lock-check.sh

Expand Down
14 changes: 9 additions & 5 deletions cilium/cmd/policy_validate.go
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/spf13/cobra"
)

var policyVerbose bool

// policyValidateCmd represents the policy_validate command
var policyValidateCmd = &cobra.Command{
Use: "validate <path>",
Expand All @@ -29,19 +31,21 @@ var policyValidateCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
path := args[0]
if ruleList, err := loadPolicy(path); err != nil {
Fatalf("Validation of policy has failed: %s\n", err)
Fatalf("Validation of policy %s has failed: %s\n", path, err)
} else {
for _, r := range ruleList {
if err := r.Sanitize(); err != nil {
Fatalf("Validation of policy has failed: %s\n", err)
Fatalf("Validation of policy %s has failed: %s\n", path, err)
}
}
fmt.Printf("All policy elements are valid.\n")
if policyVerbose {
fmt.Printf("All policy elements in %s are valid.\n", path)
}

if printPolicy {
jsonPolicy, err := json.MarshalIndent(ruleList, "", " ")
if err != nil {
Fatalf("Cannot marshal policy: %s\n", err)
Fatalf("Cannot marshal policy %s: %s\n", path, err)
}
fmt.Printf("%s", string(jsonPolicy))
}
Expand All @@ -52,5 +56,5 @@ var policyValidateCmd = &cobra.Command{
func init() {
policyCmd.AddCommand(policyValidateCmd)
policyValidateCmd.Flags().BoolVarP(&printPolicy, "print", "", false, "Print policy after validation")

policyValidateCmd.Flags().BoolVarP(&policyVerbose, "verbose", "v", true, "Enable verbose output")
}
123 changes: 0 additions & 123 deletions test/runtime/examples.go

This file was deleted.