Skip to content

Commit ad026ef

Browse files
authored
Add shfmt linter (#308)
1 parent 7c8b3c6 commit ad026ef

30 files changed

+318
-355
lines changed

.github/workflows/pre-main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
SHELLCHECK_OPTS: --external-sources
4040
with:
4141
ignore_names: mo
42+
- uses: mfinelli/setup-shfmt@v2
43+
- run: shfmt -d scripts/*.sh
4244
- uses: crate-ci/typos@master
4345
- uses: ibiqlik/action-yamllint@v3
4446
with:

scripts/create-local-registry.sh

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
23
# TODO: needs refactoring to work with kind
34
# Initialization
45
# shellcheck disable=SC1001,SC2215
@@ -16,70 +17,62 @@ CONTAINER_CLIENT="${CONTAINER_EXECUTABLE:-$TNF_CONTAINER_CLIENT}"
1617
CERT_EXE_UBUNTU=update-ca-certificates
1718
CERT_EXE_REDHAT=update-ca-trust
1819
echo "$(which $CERT_EXE_UBUNTU 2>/dev/null)"]
19-
if [[ -n "$(which $CERT_EXE_UBUNTU 2>/dev/null)" ]];
20-
then
21-
echo "Running on Ubuntu Linux"
22-
CERT_UPDATER=$CERT_EXE_UBUNTU
23-
CERT_PATH=/usr/local/share/ca-certificates/$REGISTRY_NAME.crt
24-
25-
elif [[ -n "$(which $CERT_EXE_REDHAT 2>/dev/null)" ]];
26-
then
27-
echo "Running on Redhat/Fedora Linux"
28-
CERT_UPDATER=$CERT_EXE_REDHAT
29-
CERT_PATH=/etc/pki/ca-trust/source/anchors/$REGISTRY_NAME.crt
20+
if [[ -n "$(which $CERT_EXE_UBUNTU 2>/dev/null)" ]]; then
21+
echo "Running on Ubuntu Linux"
22+
CERT_UPDATER=$CERT_EXE_UBUNTU
23+
CERT_PATH=/usr/local/share/ca-certificates/$REGISTRY_NAME.crt
24+
elif [[ -n "$(which $CERT_EXE_REDHAT 2>/dev/null)" ]]; then
25+
echo "Running on Redhat/Fedora Linux"
26+
CERT_UPDATER=$CERT_EXE_REDHAT
27+
CERT_PATH=/etc/pki/ca-trust/source/anchors/$REGISTRY_NAME.crt
3028
else
31-
echo "OS unknown, don't know how to update certificates"
32-
exit 1
29+
echo "OS unknown, don't know how to update certificates"
30+
exit 1
3331
fi
34-
32+
3533
# Create certificates for registry authentication
3634
rm -rf "$SCRIPT_DIR"/certs
3735
mkdir "$SCRIPT_DIR"/certs
38-
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout "$SCRIPT_DIR"/certs/registry.key -out "$SCRIPT_DIR"/certs/registry.crt -subj "/CN=registry" -addext "subjectAltName=DNS:${REGISTRY_NAME},IP:127.0.0.1"
36+
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout "$SCRIPT_DIR"/certs/registry.key -out "$SCRIPT_DIR"/certs/registry.crt -subj "/CN=registry" -addext "subjectAltName=DNS:${REGISTRY_NAME},IP:127.0.0.1"
3937
openssl x509 -in "$SCRIPT_DIR"/certs/registry.crt -out "$SCRIPT_DIR"/certs/registry.pem -outform PEM
4038
chmod 666 "$SCRIPT_DIR"/certs/*
4139

4240
# Enable the new certificates for use in the current host
43-
sudo cp "$SCRIPT_DIR"/certs/registry.crt "$CERT_PATH"
41+
sudo cp "$SCRIPT_DIR"/certs/registry.crt "$CERT_PATH"
4442
sudo $CERT_UPDATER
4543

46-
4744
# Add the hostname to /etc/hosts
4845
# shellcheck disable=SC2143 # Use grep -q.
49-
if [ -z "$( grep "$REGISTRY_NAME" /etc/hosts)" ]
50-
then
51-
REGISTRY_ADDRESS=$(hostname -I|awk '{print $1}')
52-
echo REGISTRY_ADDRESS= "$REGISTRY_ADDRESS"
53-
sudo REGISTRY_ADDRESS1="$REGISTRY_ADDRESS" REGISTRY1="$REGISTRY_NAME" sh -c 'echo "$REGISTRY_ADDRESS1 $REGISTRY1" >> /etc/hosts'
46+
if [ -z "$(grep "$REGISTRY_NAME" /etc/hosts)" ]; then
47+
REGISTRY_ADDRESS=$(hostname -I | awk '{print $1}')
48+
echo REGISTRY_ADDRESS= "$REGISTRY_ADDRESS"
49+
sudo REGISTRY_ADDRESS1="$REGISTRY_ADDRESS" REGISTRY1="$REGISTRY_NAME" sh -c 'echo "$REGISTRY_ADDRESS1 $REGISTRY1" >> /etc/hosts'
5450
else
55-
echo "entry already present"
51+
echo "entry already present"
5652
fi
5753
cat /etc/hosts
5854

59-
6055
# Delete previous Registry
6156
${CONTAINER_CLIENT} rm -f registry
6257

6358
# Copy the certificate to the minikube directory for use by minikube
6459
mkdir -p "$HOME"/.minikube/certs
65-
cp "$SCRIPT_DIR"/certs/registry.pem "$HOME"/.minikube/certs/.
60+
cp "$SCRIPT_DIR"/certs/registry.pem "$HOME"/.minikube/certs/.
6661

67-
# Remove the docker registry
62+
# Remove the docker registry
6863
${CONTAINER_CLIENT} rm -f registry
6964

7065
# Create the docker registry
71-
${CONTAINER_CLIENT} run -d \Linux
72-
-v "$(pwd)"/"$SCRIPT_DIR"/certs:/certs:Z \
73-
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
74-
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.crt \
75-
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.key \
76-
-p 443:443 \
77-
registry:2
66+
${CONTAINER_CLIENT} run -d Linux \
67+
-v "$(pwd)"/"$SCRIPT_DIR"/certs:/certs:Z \
68+
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
69+
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.crt \
70+
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.key \
71+
-p 443:443 \
72+
registry:2
7873

79-
# Restart docker
80-
if [ "${CONTAINER_CLIENT}" = "docker" ];
81-
then
82-
sudo systemctl restart docker
74+
# Restart docker
75+
if [ "${CONTAINER_CLIENT}" = "docker" ]; then
76+
sudo systemctl restart docker
8377
fi
84-
8578
echo "Created local registry at: ${REGISTRY_NAME}:443"

scripts/create-operator-bundle.sh

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,50 @@ mkdir -p config/manifests/bases
2929

3030
# Create configuration.
3131
cat >config/manifests/bases/nginx-operator.clusterserviceversion.yaml <<-'EOF'
32-
apiVersion: operators.coreos.com/v1alpha1
33-
kind: ClusterServiceVersion
34-
metadata:
35-
annotations:
36-
alm-examples: '[]'
37-
capabilities: Basic Install
38-
test-network-function.com/subscription_name: '["nginx-operator-v0-0-1-sub"]'
39-
name: nginx-operator.v0.0.0
40-
namespace: placeholder
41-
labels:
42-
test-network-function.com/operator: target
43-
spec:
44-
apiservicedefinitions: {}
45-
customresourcedefinitions: {}
46-
description: cnftest
47-
displayName: test-operator
48-
icon:
49-
- base64data: ""
50-
mediatype: ""
51-
install:
52-
spec:
53-
deployments: null
54-
strategy: ""
55-
installModes:
56-
- supported: false
57-
type: OwnNamespace
58-
- supported: false
59-
type: SingleNamespace
60-
- supported: false
61-
type: MultiNamespace
62-
- supported: true
63-
type: AllNamespaces
64-
keywords:
65-
- cnftest
66-
links:
67-
- name: Nginx Operator
68-
url: https://nginx-operator.domain
69-
maintainers:
70-
71-
name: david
72-
maturity: alpha
73-
provider:
74-
name: redhat
75-
version: 0.0.0
32+
apiVersion: operators.coreos.com/v1alpha1
33+
kind: ClusterServiceVersion
34+
metadata:
35+
annotations:
36+
alm-examples: '[]'
37+
capabilities: Basic Install
38+
test-network-function.com/subscription_name: '["nginx-operator-v0-0-1-sub"]'
39+
name: nginx-operator.v0.0.0
40+
namespace: placeholder
41+
labels:
42+
test-network-function.com/operator: target
43+
spec:
44+
apiservicedefinitions: {}
45+
customresourcedefinitions: {}
46+
description: cnftest
47+
displayName: test-operator
48+
icon:
49+
- base64data: ""
50+
mediatype: ""
51+
install:
52+
spec:
53+
deployments: null
54+
strategy: ""
55+
installModes:
56+
- supported: false
57+
type: OwnNamespace
58+
- supported: false
59+
type: SingleNamespace
60+
- supported: false
61+
type: MultiNamespace
62+
- supported: true
63+
type: AllNamespaces
64+
keywords:
65+
- cnftest
66+
links:
67+
- name: Nginx Operator
68+
url: https://nginx-operator.domain
69+
maintainers:
70+
71+
name: david
72+
maturity: alpha
73+
provider:
74+
name: redhat
75+
version: 0.0.0
7676
EOF
7777

7878
# Make and push the operator bundle

scripts/create-redhat-registry-secrets.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ SCRIPT_DIR=$(dirname "$0")
55

66
# shellcheck disable=SC1091 # Not following.
77
source "$SCRIPT_DIR"/init-env.sh
8-
98
oc create secret docker-registry redhat-registry-secret \
10-
--docker-server=registry.redhat.io \
11-
--docker-username="$LOGIN_REGISTRY" \
12-
--docker-password="$PASSWORD_REGISTRY" \
13-
[email protected] -n "$TNF_EXAMPLE_CNF_NAMESPACE"
14-
9+
--docker-server=registry.redhat.io \
10+
--docker-username="$LOGIN_REGISTRY" \
11+
--docker-password="$PASSWORD_REGISTRY" \
12+
[email protected] -n "$TNF_EXAMPLE_CNF_NAMESPACE"
1513
oc create secret docker-registry redhat-connect-registry-secret \
16-
--docker-server=registry.connect.redhat.com \
17-
--docker-username="$LOGIN_REGISTRY" \
18-
--docker-password="$PASSWORD_REGISTRY" \
19-
[email protected] -n "$TNF_EXAMPLE_CNF_NAMESPACE"
14+
--docker-server=registry.connect.redhat.com \
15+
--docker-username="$LOGIN_REGISTRY" \
16+
--docker-password="$PASSWORD_REGISTRY" \
17+
[email protected] -n "$TNF_EXAMPLE_CNF_NAMESPACE"

scripts/delete-debug-ds.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ SCRIPT_DIR=$(dirname "$0")
77
source "$SCRIPT_DIR"/init-env.sh
88

99
# Delete debug daemonset
10-
oc delete daemonsets.apps/debug -n "${DEFAULT_NAMESPACE}" --ignore-not-found=true
11-
until [[ -z "$(oc get ds debug -n "${DEFAULT_NAMESPACE}" 2>/dev/null)" ]]; do sleep 5; done
10+
oc delete daemonsets.apps/debug -n "${DEFAULT_NAMESPACE}" --ignore-not-found=true
11+
until [[ -z "$(oc get ds debug -n "${DEFAULT_NAMESPACE}" 2>/dev/null)" ]]; do
12+
sleep 5
13+
done

scripts/delete-istio.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
# Initialization
44
SCRIPT_DIR=$(dirname "$0")
5-
# shellcheck source=scripts/init-env.sh
6-
source "$SCRIPT_DIR"/init-env.sh
75

6+
# shellcheck disable=SC1091 # Not following.
7+
source "$SCRIPT_DIR"/init-env.sh
88
ISTIO_DIR=istio-1.18.0
9-
109
if [ ! -d "$ISTIO_DIR" ]; then
11-
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.18.0 sh -
10+
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.18.0 sh -
1211
fi
13-
1412
./$ISTIO_DIR/bin/istioctl uninstall -y --purge
1513
oc label namespace "$TNF_EXAMPLE_CNF_NAMESPACE" istio-injection-
1614
if ! $TNF_NON_OCP_CLUSTER; then
17-
oc adm policy remove-scc-from-group anyuid system:serviceaccounts:"$TNF_EXAMPLE_CNF_NAMESPACE"
18-
oc -n "$TNF_EXAMPLE_CNF_NAMESPACE" delete network-attachment-definition istio-cni
15+
oc adm policy remove-scc-from-group anyuid system:serviceaccounts:"$TNF_EXAMPLE_CNF_NAMESPACE"
16+
oc -n "$TNF_EXAMPLE_CNF_NAMESPACE" delete network-attachment-definition istio-cni
1917
fi
2018
oc delete namespace istio-system

scripts/delete-network-policies.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ SCRIPT_DIR=$(dirname "$0")
55

66
# shellcheck disable=SC1091 # Not following.
77
source "$SCRIPT_DIR"/init-env.sh
8-
98
oc delete --filename ./test-target/ingress-deny-all-np.yaml --namespace "$TNF_EXAMPLE_CNF_NAMESPACE" --ignore-not-found
109
oc delete --filename ./test-target/egress-deny-all-np.yaml --namespace "$TNF_EXAMPLE_CNF_NAMESPACE" --ignore-not-found
1110

1211
# Render the script with vars
1312
mkdir -p ./temp
1413

1514
# shellcheck disable=SC2002 # Useless cat.
16-
cat ./test-target/pod-to-pod-np.yaml | TNF_EXAMPLE_CNF_NAMESPACE=$TNF_EXAMPLE_CNF_NAMESPACE "$SCRIPT_DIR"/mo > ./temp/rendered-pod-to-pod-np.yaml
15+
cat ./test-target/pod-to-pod-np.yaml | TNF_EXAMPLE_CNF_NAMESPACE=$TNF_EXAMPLE_CNF_NAMESPACE "$SCRIPT_DIR"/mo >./temp/rendered-pod-to-pod-np.yaml
1716
oc delete --filename ./temp/rendered-pod-to-pod-np.yaml --namespace "$TNF_EXAMPLE_CNF_NAMESPACE" --ignore-not-found
1817
rm ./temp/rendered-pod-to-pod-np.yaml

scripts/delete-operator-crd-scaling.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ source "$SCRIPT_DIR"/init-env.sh
77

88
# Skip the delete if MacOS
99
if [[ "$(uname -s)" == "Darwin"* ]]; then
10-
echo "Skipping operator crd scaling delete on MacOS"
11-
exit 0
10+
echo "Skipping operator crd scaling delete on MacOS"
11+
exit 0
1212
fi
1313

1414
# clone the repo

scripts/delete-pod-disruption-budget.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ source "$SCRIPT_DIR"/init-env.sh
1010
mkdir -p ./temp
1111

1212
# shellcheck disable=SC2002 # Useless cat.
13-
cat ./test-target/pod-disruption-budget.yaml | APP_1="testdp" APP_2="testss" "$SCRIPT_DIR"/mo > ./temp/rendered-pod-disruption-budget-template.yaml
13+
cat ./test-target/pod-disruption-budget.yaml | APP_1="testdp" APP_2="testss" "$SCRIPT_DIR"/mo >./temp/rendered-pod-disruption-budget-template.yaml
1414
oc delete --filename ./temp/rendered-pod-disruption-budget-template.yaml --namespace "$TNF_EXAMPLE_CNF_NAMESPACE" --ignore-not-found=true
1515
rm ./temp/rendered-pod-disruption-budget-template.yaml

scripts/delete-prometheus-operator.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ SCRIPT_DIR=$(dirname "$0")
55

66
# shellcheck disable=SC1091 # Not following.
77
source "$SCRIPT_DIR"/init-env.sh
8-
9-
if ! $TNF_NON_OCP_CLUSTER;then
8+
if ! $TNF_NON_OCP_CLUSTER; then
109
echo "OCP cluster detected, skipping prometheus operator deletion"
1110
exit 0
1211
fi
13-
14-
oc delete --filename ./kube-prometheus -n "monitoring" --ignore-not-found=true
12+
oc delete --filename ./kube-prometheus -n "monitoring" --ignore-not-found=true

0 commit comments

Comments
 (0)