-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: lb-with-vpc-backends | ||
labels: | ||
all: | ||
spec: | ||
namespace: "lb-with-vpc-backends" | ||
steps: | ||
- name: Create pods and services | ||
try: | ||
- apply: | ||
file: create-pods-services.yaml | ||
catch: | ||
- describe: | ||
apiVersion: v1 | ||
kind: Pod | ||
- describe: | ||
apiVersion: v1 | ||
kind: Service | ||
- name: Check endpoints exist | ||
try: | ||
- assert: | ||
resource: | ||
apiVersion: v1 | ||
kind: Endpoints | ||
metadata: | ||
name: svc-test | ||
(subsets[0].addresses != null): true | ||
(subsets[0].ports != null): true | ||
- name: Check that loadbalancer ip is assigned | ||
try: | ||
- assert: | ||
resource: | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: svc-test | ||
status: | ||
(loadBalancer.ingress[0].ip != null): true | ||
- name: Check NodeBalancerConfig for backend ips | ||
try: | ||
- script: | ||
content: | | ||
set -e | ||
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) | ||
nbconfig=$(curl -s \ | ||
-H "Authorization: Bearer $LINODE_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
"https://api.linode.com/v4/nodebalancers/$nbid/configs") | ||
config_id=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .id') | ||
# Get nodes from the config | ||
nodes=$(curl -s \ | ||
-H "Authorization: Bearer $LINODE_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
"https://api.linode.com/v4/nodebalancers/$nbid/configs/$config_id/nodes") | ||
# Extract all addresses and remove ports | ||
addresses=$(echo "$json_data" | jq -r '.data[].address' | sed 's/:[0-9]*$//') | ||
for ip in $addresses; do | ||
if [[ $ip =~ ^10\.0\.0\.[0-9]+$ ]]; then | ||
echo "$ip is in the 10.0.0.0/8 subnet" | ||
else | ||
echo "$ip is NOT in the 10.0.0.0/8 subnet" | ||
fi | ||
done | ||
check: | ||
($error): ~ | ||
(contains($stdout, 'is NOT in the 10.0.0.0/8 subnet')): 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,49 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: vpc-backends | ||
name: test | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: vpc-backends | ||
template: | ||
metadata: | ||
labels: | ||
app: vpc-backends | ||
spec: | ||
containers: | ||
- image: appscode/test-server:2.3 | ||
name: test | ||
ports: | ||
- name: http-1 | ||
containerPort: 80 | ||
protocol: TCP | ||
env: | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: metadata.name | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: svc-test | ||
annotations: | ||
service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range: "10.100.0.0/30" | ||
labels: | ||
app: vpc-backends | ||
spec: | ||
type: LoadBalancer | ||
selector: | ||
app: vpc-backends | ||
ports: | ||
- name: http-1 | ||
protocol: TCP | ||
port: 80 | ||
targetPort: 80 | ||
sessionAffinity: None |