[GitHub Actions] Add missing files.
This commit is contained in:
25
scripts/add-roles.sh
Executable file
25
scripts/add-roles.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
function add_role() {
|
||||
ROLE=$1
|
||||
ROLE_NAME=$(echo "rolebinding-$NS-default-$ROLE" | sed 's/:/-/g')
|
||||
echo "ROLE_NAME=$ROLE_NAME into $NS"
|
||||
set +e
|
||||
kubectl create rolebinding "$ROLE_NAME" \
|
||||
--namespace $NS \
|
||||
"--clusterrole=$ROLE" \
|
||||
"--user=system:serviceaccount:$NS:default"
|
||||
|
||||
CROLE_NAME=$(echo "cluster-$NS-$ROLE" | sed 's/:/-/g')
|
||||
echo "CROLE_NAME=$CROLE_NAME into $NS"
|
||||
kubectl create clusterrolebinding "$CROLE_NAME" \
|
||||
--clusterrole=$ROLE \
|
||||
--group=system:authenticated --namespace $NS
|
||||
}
|
||||
if [ "$NS" == "" ]; then
|
||||
echo "NS not defined"
|
||||
exit 1
|
||||
fi
|
||||
for role in "$@"; do
|
||||
echo "Adding Role: $role"
|
||||
add_role "$role"
|
||||
done
|
||||
26
scripts/ensure-ns.sh
Executable file
26
scripts/ensure-ns.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
(return 0 2>/dev/null) && sourced=1 || sourced=0
|
||||
if [ "$1" == "" ]; then
|
||||
echo "Usage: ensure-ns.sh <namespace>"
|
||||
if ((sourced != 0)); then
|
||||
return 1
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
NS=$1
|
||||
set +e
|
||||
FOUND=$(kubectl get namespaces --output=json | jq --arg namespace $NS '.items | map(select(.metadata.name == $namespace)) | .[] | .metadata.name')
|
||||
if [ "$FOUND" == "" ]; then
|
||||
echo "Creating namespace $NS"
|
||||
kubectl create namespace "$NS"
|
||||
set +e
|
||||
COUNT=$(kubectl get namespaces 2>/dev/null | grep -c -F "$NS")
|
||||
while ((COUNT == 0)); do
|
||||
echo "Waiting for Namespace:$NS"
|
||||
sleep 3
|
||||
COUNT=$(kubectl get namespaces 2>/dev/null | grep -c -F "$NS")
|
||||
done
|
||||
else
|
||||
echo "Namespace $NS exists"
|
||||
fi
|
||||
Reference in New Issue
Block a user