-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathk8sgpt.sh
executable file
·57 lines (49 loc) · 1.55 KB
/
k8sgpt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2024
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o errexit
set -o nounset
set -o pipefail
# shellcheck source=tests/_functions.sh
source _functions.sh
# shellcheck source=tests/_assertions.sh
source _assertions.sh
function cleanup {
kubectl delete -f resources/gatekeeper
kubectl delete namespace opa-test
}
# Setup
kubectl apply -f resources/gatekeeper/template.yml
sleep 5
kubectl apply -f resources/gatekeeper/lb-constraint.yml
if ! kubectl get namespaces/opa-test --no-headers -o custom-columns=name:.metadata.name; then
kubectl create namespace opa-test
fi
trap cleanup EXIT
# Test
info "===== Test started ====="
# editorconfig-checker-disable
cat <<EOF >/tmp/restricted.yaml
kind: Service
apiVersion: v1
metadata:
name: lb-service
namespace: opa-test
spec:
type: LoadBalancer
selector:
app: opa-test
ports:
- protocol: TCP
port: 80
targetPort: 8080
EOF
# editorconfig-checker-enable
assert_contains "$(kubectl apply -f /tmp/restricted.yaml 2>&1 || :)" "Service type LoadBalancer are restricted" "OPA Gatekeeper didn't restrict the service creation using LoadBalancer type"
info "===== Test completed ====="