Skip to content

Commit

Permalink
Fix exit code handling (#508)
Browse files Browse the repository at this point in the history
* Fix exit code handling

* fix test. Update venom

* update the version of kube

* fix venom command
  • Loading branch information
sudermanjr authored Sep 6, 2023
1 parent 82c63f6 commit 5fd911d
Show file tree
Hide file tree
Showing 7 changed files with 14,677 additions and 22 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

orbs:
orb-tools: circleci/orb-tools@10.1.0
rok8s: fairwinds/rok8s-scripts@11
rok8s: fairwinds/rok8s-scripts@12
oss-docs: fairwinds/oss-docs@0

executors:
Expand All @@ -12,11 +12,11 @@ executors:

references:
e2e_config: &e2e_config
command_runner_image: quay.io/reactiveops/ci-images:v11-buster
kind_node_image: "kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6"
command_runner_image: quay.io/reactiveops/ci-images:v12-buster
kind_node_image: "kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb"
executor: golang-exec
pre_script: e2e/pre.sh
store-test-results: /tmp/test-results
store-test-results: /tmp/test-results/
script: e2e/test.sh
requires:
- test
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
publish-dev-orb:
working_directory: /go/src/github.com/fairwindsops/pluto
docker:
- image: quay.io/reactiveops/ci-images:v11-alpine
- image: quay.io/reactiveops/ci-images:v12-alpine
shell: /bin/bash
steps:
- checkout
Expand All @@ -105,7 +105,7 @@ jobs:
token-variable: CIRCLECI_DEV_API_TOKEN
request-orb-publish:
docker:
- image: quay.io/reactiveops/ci-images:v11-alpine
- image: quay.io/reactiveops/ci-images:v12-alpine
steps:
- *install_vault_alpine
- rok8s/get_vault_env:
Expand Down
29 changes: 15 additions & 14 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ var rootCmd = &cobra.Command{
PersistentPostRun: func(cmd *cobra.Command, args []string) {

if noFooter, err := cmd.Flags().GetBool("no-footer"); err == nil && noFooter {
klog.V(5).Infof("exiting with code %d", exitCode)
os.Exit(exitCode)
}

os.Stderr.WriteString("\n\nWant more? Automate Pluto for free with Fairwinds Insights!\n 🚀 https://fairwinds.com/insights-signup/pluto 🚀 \n")
klog.V(5).Infof("exiting with code %d", exitCode)
os.Exit(exitCode)
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -333,9 +335,9 @@ var detectHelmCmd = &cobra.Command{
fmt.Printf("Error Parsing Output: %v\n", err)
os.Exit(1)
}
exitCode := apiInstance.GetReturnCode()
klog.V(5).Infof("retCode: %d", exitCode)
os.Exit(exitCode)
exitCode = apiInstance.GetReturnCode()
klog.V(5).Infof("exitCode: %d", exitCode)
return
},
}

Expand All @@ -354,9 +356,9 @@ var detectApiResourceCmd = &cobra.Command{
fmt.Printf("Error Parsing Output: %v\n", err)
os.Exit(1)
}
exitCode := apiInstance.GetReturnCode()
klog.V(5).Infof("retCode: %d", exitCode)
os.Exit(exitCode)
exitCode = apiInstance.GetReturnCode()
klog.V(5).Infof("exitCode: %d", exitCode)
return
},
}

Expand All @@ -383,9 +385,8 @@ var detectAllInClusterCmd = &cobra.Command{
fmt.Printf("Error Parsing Output: %v\n", err)
os.Exit(1)
}
exitCode := apiInstance.GetReturnCode()
klog.V(5).Infof("retCode: %d", exitCode)
os.Exit(exitCode)
exitCode = apiInstance.GetReturnCode()
klog.V(5).Infof("exitCode: %d", exitCode)
},
}

Expand Down Expand Up @@ -425,9 +426,9 @@ var detectCmd = &cobra.Command{
fmt.Println("Error parsing output:", err)
os.Exit(1)
}
retCode := apiInstance.GetReturnCode()
klog.V(5).Infof("retCode: %d", retCode)
os.Exit(retCode)
exitCode = apiInstance.GetReturnCode()
klog.V(5).Infof("exitCode: %d", exitCode)
return
}

// File input
Expand All @@ -445,8 +446,8 @@ var detectCmd = &cobra.Command{
fmt.Println("Error parsing output:", err)
os.Exit(1)
}
retCode := apiInstance.GetReturnCode()
klog.V(5).Infof("retCode: %d", retCode)
exitCode = apiInstance.GetReturnCode()
klog.V(5).Infof("exitCode: %d", exitCode)
},
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ echo "** Install and Run Venom **"
echo "***************************"
printf "\n\n"

curl -LO https://github.com/ovh/venom/releases/download/v0.27.0/venom.linux-amd64
curl -LO https://github.com/ovh/venom/releases/download/v1.1.0/venom.linux-amd64
mv venom.linux-amd64 /usr/local/bin/venom
chmod +x /usr/local/bin/venom

Expand All @@ -18,5 +18,5 @@ cp /pluto/pluto /usr/local/bin/pluto
cd /pluto/e2e
mkdir -p /tmp/test-results
helm delete -n kube-system hostpath-provisioner || true
venom run tests/* --log debug --output-dir=/tmp/test-results --strict
venom run tests/* --output-dir=/tmp/test-results
exit $?
7 changes: 7 additions & 0 deletions e2e/tests/00_static_files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ testcases:
- result.systemout ShouldContainSubstring "NAME KIND VERSION REPLACEMENT REMOVED DEPRECATED"
- result.systemout ShouldContainSubstring "utilities Deployment extensions/v1beta1 apps/v1 false true"
- result.systemout ShouldNotContainSubstring "utilities Deployment apps/v1 false false"

- name: exit code three for single file
steps:
- script: pluto detect assets/deprecated116/deployment-extensions-v1beta1.yaml
assertions:
- result.code ShouldEqual 3
- result.systemout ShouldContainSubstring "extensions/v1beta1"
Loading

0 comments on commit 5fd911d

Please sign in to comment.