-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: retries for policies cm comprised of multiple dependent files
Signed-off-by: Ievgenii Shepeliuk <[email protected]>
- Loading branch information
1 parent
7cf023a
commit 2ae02bd
Showing
9 changed files
with
155 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
kind: ConfigMap | ||
metadata: | ||
name: multi-file-fail-policy | ||
labels: | ||
kube-mgmt/e2e: "true" | ||
openpolicyagent.org/policy: rego | ||
apiVersion: v1 | ||
data: | ||
f.rego: | | ||
package my_pkg_fail | ||
import data.my_pkg_fail.functions.my_func | ||
default my_rule := false | ||
my_rule { | ||
my_func(input.hello) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
kind: ConfigMap | ||
metadata: | ||
name: multi-file-policy | ||
labels: | ||
kube-mgmt/e2e: "true" | ||
openpolicyagent.org/policy: rego | ||
apiVersion: v1 | ||
data: | ||
a.rego: | | ||
package my_pkg | ||
import data.my_pkg.functions.my_func | ||
default my_rule := false | ||
my_rule { | ||
my_func(input.hello) | ||
} | ||
b.rego: | | ||
package my_pkg.functions | ||
my_func(str) := startswith("world", str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
OPA="http --ignore-stdin :8080/v1" | ||
FX_OK="$(dirname $0)/../fixture-multi.yaml" | ||
FX_KO="$(dirname $0)/../fixture-multi-fail.yaml" | ||
|
||
${OPA}/data/my_pkg/my_rule | jq -e '.result==null' | ||
|
||
kubectl apply -f ${FX_OK} | ||
sleep 3 | ||
|
||
${OPA}/policies | jq -e '.result|any(.id=="default/multi-file-policy/a.rego")==true' | ||
${OPA}/policies | jq -e '.result|any(.id=="default/multi-file-policy/b.rego")==true' | ||
|
||
kubectl get cm multi-file-policy -ojson | \ | ||
jq -e '.metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="ok"' | ||
kubectl get cm multi-file-policy -ojson | \ | ||
jq -e '.metadata.annotations["openpolicyagent.org/kube-mgmt-retries"]=="0"' | ||
|
||
${OPA}/data/my_pkg/my_rule input[hello]=world | jq -e '.result==true' | ||
${OPA}/data/my_pkg/my_rule input[hello]=incorrect | jq -e '.result==false' | ||
|
||
###### | ||
# | ||
###### | ||
|
||
kubectl apply -f ${FX_KO} | ||
sleep 3 | ||
|
||
${OPA}/policies | jq -e '.result|length==2' | ||
|
||
kubectl get cm multi-file-fail-policy -ojson | \ | ||
jq -e '.metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="error"' | ||
kubectl get cm multi-file-fail-policy -ojson | \ | ||
jq -e '.metadata.annotations["openpolicyagent.org/kube-mgmt-retries"]=="0"' | ||
|
||
###### | ||
# | ||
###### | ||
|
||
cat ${FX_OK} | \ | ||
yq '.metadata.labels["openpolicyagent.org/policy"]=""' | \ | ||
yq '.metadata.annotations["openpolicyagent.org/kube-mgmt-retries"]="0"' | \ | ||
kubectl apply -f - | ||
sleep 3 | ||
|
||
${OPA}/data/my_pkg/my_rule | jq -e '.result==null' | ||
|
||
kubectl label --overwrite cm multi-file-policy openpolicyagent.org/policy=rego | ||
sleep 3 | ||
|
||
${OPA}/policies | jq -e '.result|any(.id=="default/multi-file-policy/a.rego")==true' | ||
${OPA}/policies | jq -e '.result|any(.id=="default/multi-file-policy/b.rego")==true' | ||
|
||
kubectl get cm multi-file-policy -ojson | \ | ||
jq -e '.metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="ok"' | ||
kubectl get cm multi-file-policy -ojson | \ | ||
jq -e '.metadata.annotations["openpolicyagent.org/kube-mgmt-retries"]=="0"' | ||
|
||
${OPA}/data/my_pkg/my_rule input[hello]=world | jq -e '.result==true' | ||
${OPA}/data/my_pkg/my_rule input[hello]=incorrect | jq -e '.result==false' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
useHttps: false | ||
|
||
opa: null | ||
|
||
authz: | ||
enabled: false | ||
|
||
mgmt: | ||
extraArgs: | ||
- "--log-level=debug" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters