diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..fd50f920 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.sh] +indent_style = space +indent_size = 2 +switch_case_indent = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31d41bdb..5718e27e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -345,3 +345,25 @@ jobs: CHANNEL: master AWS_ACCESS_KEY_ID: ${{ secrets.AWS_USR }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }} + + shfmt: + runs-on: ubuntu-24.04 + needs: detect-noop + if: needs.detect-noop.outputs.noop != 'true' + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Setup Go + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install shfmt + run: | + go install mvdan.cc/sh/v3/cmd/shfmt@v3.13.1 + echo "$HOME/go/bin" >> "$GITHUB_PATH" + + - name: Check shell formatting + run: shfmt -d . diff --git a/.golangci.yml b/.golangci.yml index 5b6c12b7..b1174f4c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,17 +6,12 @@ formatters: # Enable specific formatter. # Default: [] (uses standard Go formatting) enable: - - gofmt + - gofumpt - goimports # - gci - # - gofumpt # - golines settings: - gofmt: - # simplify code: gofmt with `-s` option, true by default - simplify: true - goimports: # put imports beginning with prefix after 3rd-party packages local-prefixes: diff --git a/apis/mssql/v1alpha1/user_types.go b/apis/mssql/v1alpha1/user_types.go index eb74775e..b6a266c5 100644 --- a/apis/mssql/v1alpha1/user_types.go +++ b/apis/mssql/v1alpha1/user_types.go @@ -59,8 +59,7 @@ type UserParameters struct { } // A UserObservation represents the observed state of a MSSQL user. -type UserObservation struct { -} +type UserObservation struct{} // +kubebuilder:object:root=true diff --git a/apis/postgresql/v1alpha1/grant_types.go b/apis/postgresql/v1alpha1/grant_types.go index d9997438..d18221c2 100644 --- a/apis/postgresql/v1alpha1/grant_types.go +++ b/apis/postgresql/v1alpha1/grant_types.go @@ -65,10 +65,12 @@ const ( RoleForeignServer GrantType = "ROLE_FOREIGN_SERVER" ) -type marker struct{} -type stringSet struct { - elements map[string]marker -} +type ( + marker struct{} + stringSet struct { + elements map[string]marker + } +) func newStringSet() *stringSet { return &stringSet{ diff --git a/cluster/local/integration_tests.sh b/cluster/local/integration_tests.sh index a7dbc280..98d9bab2 100755 --- a/cluster/local/integration_tests.sh +++ b/cluster/local/integration_tests.sh @@ -8,32 +8,32 @@ GRN='\033[0;32m' RED='\033[0;31m' NOC='\033[0m' # No Color echo_info() { - printf "\n${BLU}%s${NOC}" "$1" + printf "\n${BLU}%s${NOC}" "$1" } echo_step() { - printf "\n${BLU}>>>>>>> %s${NOC}\n" "$1" + printf "\n${BLU}>>>>>>> %s${NOC}\n" "$1" } echo_sub_step() { - printf "\n${BLU}>>> %s${NOC}\n" "$1" + printf "\n${BLU}>>> %s${NOC}\n" "$1" } echo_step_completed() { - printf "${GRN} [✔]${NOC}" + printf "${GRN} [✔]${NOC}" } echo_success() { - printf "\n${GRN}%s${NOC}\n" "$1" + printf "\n${GRN}%s${NOC}\n" "$1" } echo_warn() { - printf "\n${YLW}%s${NOC}" "$1" + printf "\n${YLW}%s${NOC}" "$1" } echo_error() { - printf "\n${RED}%s${NOC}" "$1" - exit 1 + printf "\n${RED}%s${NOC}" "$1" + exit 1 } # ------------------------------ -projectdir="$( cd "$( dirname "${BASH_SOURCE[0]}")"/../.. && pwd )" +projectdir="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)" # get the build environment variables from the special build.vars target in the main makefile eval $(make --no-print-directory -C ${projectdir} build.vars) @@ -57,7 +57,6 @@ K8S_CLUSTER="${K8S_CLUSTER:-${BUILD_REGISTRY}-inttests}" # - USE_OCI=false => Extract .xpkg to .gz on host and mount as cache for Crossplane (offline local cache) USE_OCI=${USE_OCI:-true} - PACKAGE_NAME="provider-sql" MARIADB_ROOT_PW=$(openssl rand -base64 32) MARIADB_TEST_PW=$(openssl rand -base64 32) @@ -104,7 +103,8 @@ setup_cluster() { if [ "${USE_OCI}" = true ]; then echo_step "creating k8s cluster (no cache mount) using kind ${KIND_VERSION} and ${node_image}" - local config="$( cat </dev/null 2>&1 & echo $! >"${projectdir}/.work/registry-pf.pid" ) + ( + kubectl -n crossplane-system port-forward svc/registry 5000:5000 >/dev/null 2>&1 & + echo $! >"${projectdir}/.work/registry-pf.pid" + ) for i in {1..20}; do nc -z localhost 5000 && break || sleep 0.5; done } @@ -274,7 +281,8 @@ setup_provider() { if [ "${USE_OCI}" = true ]; then echo_sub_step "Provider package from OCI: registry.crossplane-system.svc.cluster.local:5000/${PACKAGE_NAME}:latest" - local yaml="$( cat </dev/null "${HELM}" repo update "${HELM}" install mariadb bitnami/mariadb \ - --version 24.0.2 \ - --set auth.rootPassword="${MARIADB_ROOT_PW}" \ - --wait + --version 24.0.2 \ + --set auth.rootPassword="${MARIADB_ROOT_PW}" \ + --wait } setup_mariadb_tls() { @@ -491,7 +502,8 @@ setup_mariadb_tls() { --from-file=client-cert.pem \ --from-file=client-key.pem - local values=$(cat </dev/null "${HELM}" repo update "${HELM}" install mariadb bitnami/mariadb \ - --version 24.0.2 \ - --values <(echo "$values") \ - --wait + --version 24.0.2 \ + --values <(echo "$values") \ + --wait } cleanup_mariadb() { @@ -555,7 +567,7 @@ test_create_user() { test_update_user_password() { echo_step "test updating MySQL User password" local user_pw="newpassword" - "${KUBECTL}" create secret generic example-pw --from-literal password="${user_pw}" --dry-run -oyaml | \ + "${KUBECTL}" create secret generic example-pw --from-literal password="${user_pw}" --dry-run -oyaml | "${KUBECTL}" apply -f - # trigger reconcile @@ -629,4 +641,4 @@ echo_step "--- TESTING POSTGRESDB ---" integration_tests_postgres echo_step "--- INTEGRATION TESTS FOR POSTGRESDB ACCOMPLISHED SUCCESSFULLY ---" -integration_tests_end \ No newline at end of file +integration_tests_end diff --git a/cluster/local/postgresdb_functions.sh b/cluster/local/postgresdb_functions.sh index 5d02bd85..a3828411 100644 --- a/cluster/local/postgresdb_functions.sh +++ b/cluster/local/postgresdb_functions.sh @@ -18,12 +18,12 @@ setup_postgresdb_no_tls() { echo_sub_step "Helm upgrade --install bitnami/postgresql (no persistence)" set +e "${HELM}" upgrade --install postgresdb bitnami/postgresql \ - --version 18.2.0 \ - --set auth.postgresPassword="${postgres_root_pw}" \ - --set primary.persistence.enabled=false \ - --wait \ - --timeout 10m \ - --debug + --version 18.2.0 \ + --set auth.postgresPassword="${postgres_root_pw}" \ + --set primary.persistence.enabled=false \ + --wait \ + --timeout 10m \ + --debug rc=$? set -e if [ $rc -ne 0 ]; then @@ -36,16 +36,16 @@ setup_postgresdb_no_tls() { echo_step_completed echo_sub_step "Create connection secret postgresdb-creds" - "${KUBECTL}" create secret generic postgresdb-creds \ - --from-literal=username="postgres" \ - --from-literal=password="${postgres_root_pw}" \ - --from-literal=endpoint="postgresdb-postgresql.default.svc.cluster.local" \ - --from-literal=port="5432" + "${KUBECTL}" create secret generic postgresdb-creds \ + --from-literal=username="postgres" \ + --from-literal=password="${postgres_root_pw}" \ + --from-literal=endpoint="postgresdb-postgresql.default.svc.cluster.local" \ + --from-literal=port="5432" echo_step_completed # Start port-forward; ignore output filtering failures under pipefail echo_sub_step "Start port-forward to svc/postgresdb-postgresql:5432" - ( "${KUBECTL}" port-forward --namespace default svc/postgresdb-postgresql 5432:5432 | grep -v "Handling connection for" || true ) & + ("${KUBECTL}" port-forward --namespace default svc/postgresdb-postgresql 5432:5432 | grep -v "Handling connection for" || true) & PORT_FORWARD_PID=$! # Wait for local port to be ready for i in {1..20}; do @@ -63,7 +63,8 @@ setup_postgresdb_no_tls() { setup_provider_config_postgres_no_tls() { echo_step "creating ProviderConfig for PostgresDb with no TLS" - local yaml="$( cat <