Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
7 changes: 1 addition & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions apis/mssql/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions apis/postgresql/v1alpha1/grant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
94 changes: 53 additions & 41 deletions cluster/local/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 <<EOF
local config="$(
cat <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
Expand All @@ -120,7 +120,8 @@ EOF
chmod 644 "${cache_path}/${PACKAGE_NAME}-${VERSION}.gz"

echo_step "creating k8s cluster (with cache mount) using kind ${KIND_VERSION} and ${node_image}"
local config="$( cat <<EOF
local config="$(
cat <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
Expand All @@ -143,7 +144,8 @@ EOF
if [ "${USE_OCI}" != true ]; then
echo_step "create persistent volume for mounting package-cache"

local pv_yaml="$( cat <<EOF
local pv_yaml="$(
cat <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
Expand All @@ -165,7 +167,8 @@ EOF

echo_step "create persistent volume claim for mounting package-cache"

local pvc_yaml="$( cat <<EOF
local pvc_yaml="$(
cat <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand Down Expand Up @@ -209,7 +212,8 @@ setup_crossplane() {
setup_local_registry() {
[ "${USE_OCI}" = true ] || return 0
echo_step "deploy in-cluster OCI registry"
local reg_yaml="$( cat <<EOF
local reg_yaml="$(
cat <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -254,7 +258,10 @@ EOF

echo_step "port-forward registry for pushing xpkg"
mkdir -p "${projectdir}/.work"
( kubectl -n crossplane-system port-forward svc/registry 5000:5000 >/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
}

Expand All @@ -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 <<EOF
local yaml="$(
cat <<EOF
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
Expand Down Expand Up @@ -305,7 +313,8 @@ EOF
echo "${yaml}" | "${KUBECTL}" apply -f -
else
echo_sub_step "Provider package from local cache: ${PACKAGE_NAME}-${VERSION}.gz"
local yaml="$( cat <<EOF
local yaml="$(
cat <<EOF
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
Expand Down Expand Up @@ -362,7 +371,7 @@ cleanup_provider() {
if [[ $current -ge $timeout ]]; then
echo_error "timeout of ${timeout}s has been reached"
fi
sleep $step;
sleep $step
done
}

Expand All @@ -383,29 +392,30 @@ setup_tls_certs() {

echo_step "creating secret for the TLS certificates and keys"
"${KUBECTL}" create secret generic mariadb-server-tls \
--from-file=ca-cert.pem \
--from-file=server-cert.pem \
--from-file=server-key.pem
--from-file=ca-cert.pem \
--from-file=server-cert.pem \
--from-file=server-key.pem

echo_step "creating secret for the client TLS certificates and keys"
"${KUBECTL}" create secret generic mariadb-client-tls \
--from-file=ca-cert.pem \
--from-file=client-cert.pem \
--from-file=client-key.pem
--from-file=ca-cert.pem \
--from-file=client-cert.pem \
--from-file=client-key.pem
}

cleanup_tls_certs() {
echo_step "cleaning up TLS certificate files and secrets"
for file in *.pem *.srl; do
rm -f "$file"
rm -f "$file"
done
"${KUBECTL}" delete secret mariadb-server-tls
"${KUBECTL}" delete secret mariadb-client-tls
}

setup_provider_config_no_tls() {
echo_step "creating ProviderConfig with no TLS"
local yaml="$( cat <<EOF
local yaml="$(
cat <<EOF
apiVersion: mysql.sql.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
Expand All @@ -424,7 +434,8 @@ EOF

setup_provider_config_tls() {
echo_step "creating ProviderConfig with TLS"
local yaml="$( cat <<EOF
local yaml="$(
cat <<EOF
apiVersion: mysql.sql.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
Expand Down Expand Up @@ -467,17 +478,17 @@ cleanup_provider_config() {
setup_mariadb_no_tls() {
echo_step "installing MariaDB with no TLS"
"${KUBECTL}" create secret generic mariadb-creds \
--from-literal=username="root" \
--from-literal=password="${MARIADB_ROOT_PW}" \
--from-literal=endpoint="mariadb.default.svc.cluster.local" \
--from-literal=port="3306"
--from-literal=username="root" \
--from-literal=password="${MARIADB_ROOT_PW}" \
--from-literal=endpoint="mariadb.default.svc.cluster.local" \
--from-literal=port="3306"

"${HELM}" repo add bitnami https://charts.bitnami.com/bitnami >/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() {
Expand All @@ -491,7 +502,8 @@ setup_mariadb_tls() {
--from-file=client-cert.pem \
--from-file=client-key.pem

local values=$(cat <<EOF
local values=$(
cat <<EOF
auth:
rootPassword: ${MARIADB_ROOT_PW}
primary:
Expand All @@ -516,9 +528,9 @@ EOF
"${HELM}" repo add bitnami https://charts.bitnami.com/bitnami >/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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -629,4 +641,4 @@ echo_step "--- TESTING POSTGRESDB ---"
integration_tests_postgres
echo_step "--- INTEGRATION TESTS FOR POSTGRESDB ACCOMPLISHED SUCCESSFULLY ---"

integration_tests_end
integration_tests_end
Loading
Loading