diff --git a/.github/create_bundle.sh b/.github/create_bundle.sh index 6fbe556b..d1eb74fc 100755 --- a/.github/create_bundle.sh +++ b/.github/create_bundle.sh @@ -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:" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa96c66c..67d8f721 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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: @@ -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 diff --git a/Makefile b/Makefile index 9acfb83b..199f7221 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/templates/galera/bin/detect_gcomm_and_start.sh b/templates/galera/bin/detect_gcomm_and_start.sh old mode 100644 new mode 100755 index 44150b29..e58ca7e0 --- a/templates/galera/bin/detect_gcomm_and_start.sh +++ b/templates/galera/bin/detect_gcomm_and_start.sh @@ -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 diff --git a/templates/galera/bin/detect_last_commit.sh b/templates/galera/bin/detect_last_commit.sh old mode 100644 new mode 100755 index 50331010..121b0bba --- a/templates/galera/bin/detect_last_commit.sh +++ b/templates/galera/bin/detect_last_commit.sh @@ -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' diff --git a/templates/galera/bin/mysql_bootstrap.sh b/templates/galera/bin/mysql_bootstrap.sh old mode 100644 new mode 100755 diff --git a/templates/galera/bin/mysql_probe.sh b/templates/galera/bin/mysql_probe.sh old mode 100644 new mode 100755 index c3bc1014..20705acc --- a/templates/galera/bin/mysql_probe.sh +++ b/templates/galera/bin/mysql_probe.sh @@ -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 diff --git a/templates/galera/config/galera.cnf.in b/templates/galera/config/galera.cnf.in index b6453c62..25d9c334 100644 --- a/templates/galera/config/galera.cnf.in +++ b/templates/galera/config/galera.cnf.in @@ -59,4 +59,3 @@ socket = /var/lib/mysql/mysql.sock max_allowed_packet = 16M quick quote-names -