Skip to content

Commit

Permalink
Run pre-commit with make
Browse files Browse the repository at this point in the history
Updating pre-commit hook with make. pre-commit-golang
repo is no longer maintained. Instead of using
unmaintained repo we can use make to run pre-commit.

Signed-off-by: Amol Kahat <[email protected]>
  • Loading branch information
amolkahat committed Mar 27, 2023
1 parent 01a691f commit 7cc258d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 46 deletions.
42 changes: 21 additions & 21 deletions .github/create_bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ cat "${CLUSTER_BUNDLE_FILE}" | grep "image:"
# error will be reported to the console.
set +e
for csv_image in $(cat "${CLUSTER_BUNDLE_FILE}" | grep "image:" | sed -e "s|.*image:||" | sort -u); do
digest_image=""
echo "CSV line: ${csv_image}"
digest_image=""
echo "CSV line: ${csv_image}"

# case where @ is in the csv_image image
if [[ "$csv_image" =~ .*"@".* ]]; then
delimeter='@'
else
delimeter=':'
fi
# case where @ is in the csv_image image
if [[ "$csv_image" =~ .*"@".* ]]; then
delimeter='@'
else
delimeter=':'
fi

base_image=$(echo $csv_image | cut -f 1 -d${delimeter})
tag_image=$(echo $csv_image | cut -f 2 -d${delimeter})
base_image=$(echo $csv_image | cut -f 1 -d${delimeter})
tag_image=$(echo $csv_image | cut -f 2 -d${delimeter})

if [[ "$base_image:$tag_image" == "controller:latest" ]]; then
echo "$base_image:$tag_image becomes $OPERATOR_IMG_WITH_DIGEST"
sed -e "s|$base_image:$tag_image|$OPERATOR_IMG_WITH_DIGEST|g" -i "${CLUSTER_BUNDLE_FILE}"
else
digest_image=$(skopeo inspect docker://${base_image}${delimeter}${tag_image} | jq '.Digest' -r)
echo "Base image: $base_image"
if [ -n "$digest_image" ]; then
echo "$base_image${delimeter}$tag_image becomes $base_image@$digest_image"
sed -i "s|$base_image$delimeter$tag_image|$base_image@$digest_image|g" "${CLUSTER_BUNDLE_FILE}"
if [[ "$base_image:$tag_image" == "controller:latest" ]]; then
echo "$base_image:$tag_image becomes $OPERATOR_IMG_WITH_DIGEST"
sed -e "s|$base_image:$tag_image|$OPERATOR_IMG_WITH_DIGEST|g" -i "${CLUSTER_BUNDLE_FILE}"
else
echo "$base_image${delimeter}$tag_image not changed"
digest_image=$(skopeo inspect docker://${base_image}${delimeter}${tag_image} | jq '.Digest' -r)
echo "Base image: $base_image"
if [ -n "$digest_image" ]; then
echo "$base_image${delimeter}$tag_image becomes $base_image@$digest_image"
sed -i "s|$base_image$delimeter$tag_image|$base_image@$digest_image|g" "${CLUSTER_BUNDLE_FILE}"
else
echo "$base_image${delimeter}$tag_image not changed"
fi
fi
fi
done

echo "Resulting bundle file images:"
Expand Down
47 changes: 38 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
exclude: ^vendor
- id: go-vet
- id: go-mod-tidy
- id: go-lint

- repo: local
hooks:
- id: golangci-lint
name: golangci-lint
language: golang
types: [go]
entry: make
args: ["golangci-lint"]
pass_filenames: false
- id: golint
name: golint
language: system
entry: make
args: ["golint"]
pass_filenames: false
- id: gofmt
name: gofmt
language: system
entry: make
args: ["fmt"]
pass_filenames: false
- id: govet
name: govet
language: system
entry: make
args: ["vet"]
pass_filenames: false
- id: gotidy
name: gotidy
language: system
entry: make
args: ["tidy"]
pass_filenames: false
- id: make-manifests
name: make-manifests
language: system
Expand All @@ -29,6 +51,7 @@ repos:
args: ['operator-lint']
pass_filenames: false


- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
Expand All @@ -51,3 +74,9 @@ repos:
- id: no-commit-to-branch
- id: trailing-whitespace
exclude: ^vendor

- repo: https://github.com/openstack/bashate.git
rev: 2.1.1
hooks:
- id: bashate
entry: bashate --error . --ignore=E006,E040,E011,E020,E012
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: tidy
tidy:
go mod tidy; \
pushd "$(LOCALBIN)/../api"; \
go mod tidy; \
popd

.PHONY: golangci-lint
golangci-lint:
test -s $(LOCALBIN)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.2
$(LOCALBIN)/golangci-lint run --fix

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
Expand Down
12 changes: 6 additions & 6 deletions templates/galera/bin/detect_gcomm_and_start.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ rm -f $URI_FILE

echo "Waiting for gcomm URI to be configured for this POD"
while [ ! -f $URI_FILE ]; do
sleep 2
sleep 2
done

set -x
URI=$(cat $URI_FILE)
if [ "$URI" = "gcomm://" ]; then
echo "this POD will now bootstrap a new galera cluster"
if [ -f /var/lib/mysql/grastate.dat ]; then
sed -i -e 's/^\(safe_to_bootstrap\):.*/\1: 1/' /var/lib/mysql/grastate.dat
fi
echo "this POD will now bootstrap a new galera cluster"
if [ -f /var/lib/mysql/grastate.dat ]; then
sed -i -e 's/^\(safe_to_bootstrap\):.*/\1: 1/' /var/lib/mysql/grastate.dat
fi
else
echo "this POD will now join cluster $URI"
echo "this POD will now join cluster $URI"
fi

rm -f $URI_FILE
Expand Down
6 changes: 3 additions & 3 deletions templates/galera/bin/detect_last_commit.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -eu

# Adapted from clusterlab's galera resource agent
recover_args="--datadir=/var/lib/mysql \
--user=mysql \
--skip-networking \
--wsrep-cluster-address=gcomm://localhost"
--user=mysql \
--skip-networking \
--wsrep-cluster-address=gcomm://localhost"
recovery_file_regex='s/.*WSREP\:.*position\s*recovery.*--log_error='\''\([^'\'']*\)'\''.*/\1/p'
recovered_position_regex='s/.*WSREP\:\s*[R|r]ecovered\s*position.*\:\(.*\)\s*$/\1/p'

Expand Down
Empty file modified templates/galera/bin/mysql_bootstrap.sh
100644 → 100755
Empty file.
12 changes: 6 additions & 6 deletions templates/galera/bin/mysql_probe.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fi

case "$1" in
readiness)
# If the node is e.g. a donor, it cannot serve traffic
mysql -sNe "show status like 'wsrep_local_state_comment';" | grep -w -e Synced;;
# If the node is e.g. a donor, it cannot serve traffic
mysql -sNe "show status like 'wsrep_local_state_comment';" | grep -w -e Synced;;
liveness)
# If the node is not in the primary partition, restart it
mysql -sNe "show status like 'wsrep_cluster_status';" | grep -w -e Primary;;
# If the node is not in the primary partition, restart it
mysql -sNe "show status like 'wsrep_cluster_status';" | grep -w -e Primary;;
*)
echo "Invalid probe option '$1'"
exit 1;;
echo "Invalid probe option '$1'"
exit 1;;
esac
1 change: 0 additions & 1 deletion templates/galera/config/galera.cnf.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ socket = /var/lib/mysql/mysql.sock
max_allowed_packet = 16M
quick
quote-names

0 comments on commit 7cc258d

Please sign in to comment.