Skip to content

Commit 1af42db

Browse files
authored
Merge branch 'main' into K8SPSMDB-1445
2 parents 939b068 + 3b79001 commit 1af42db

File tree

326 files changed

+8308
-1037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+8308
-1037
lines changed

.e2eignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ operator.png
99
kubernetes.svg
1010
release_versions
1111
.github/**
12-
.snyk
1312
.e2eignore

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* @hors @egegunes @pooknull @nmarukovich @gkech
2-
/e2e-tests/ @jvpasinatto @eleo007 @valmiranogueira
3-
Jenkinsfile @jvpasinatto @eleo007 @valmiranogueira
1+
* @hors @egegunes @pooknull @nmarukovich @gkech @mayankshah1607 @oksana-grishchenko
2+
/e2e-tests/ @jvpasinatto @eleo007 @valmiranogueira @bogdanjeler-ev
3+
Jenkinsfile @jvpasinatto @eleo007 @valmiranogueira @bogdanjeler-ev
44

.github/workflows/scan.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,10 @@ jobs:
3030
export DOCKER_DEFAULT_PLATFORM='linux/arm64'
3131
./e2e-tests/build
3232
33-
- name: Run Snyk vulnerability scanner image (linux/arm64)
34-
uses: snyk/actions/docker@master
35-
env:
36-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
37-
with:
38-
image: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64'
39-
args: --platform=linux/arm64 --severity-threshold=high --exclude-base-image-vulns --file=./build/Dockerfile -fail-on=upgradable
40-
4133
- name: Build an image from Dockerfile (linux/amd64)
4234
run: |
4335
export IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64
4436
export DOCKER_PUSH=0
4537
export DOCKER_SQUASH=0
4638
export DOCKER_DEFAULT_PLATFORM='linux/amd64'
4739
./e2e-tests/build
48-
49-
- name: Run Snyk vulnerability scanner image (linux/amd64)
50-
uses: snyk/actions/docker@master
51-
env:
52-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
53-
with:
54-
image: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64'
55-
args: --platform=linux/amd64 --severity-threshold=high --exclude-base-image-vulns --file=./build/Dockerfile -fail-on=upgradable
56-

.snyk

Lines changed: 0 additions & 9 deletions
This file was deleted.

Jenkinsfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void pushLogFile(String FILE_NAME) {
9292
def LOG_FILE_PATH="e2e-tests/logs/${FILE_NAME}.log"
9393
def LOG_FILE_NAME="${FILE_NAME}.log"
9494
echo "Push logfile $LOG_FILE_NAME file to S3!"
95-
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AMI/OVF', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
95+
withCredentials([aws(credentialsId: 'AMI/OVF', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) {
9696
sh """
9797
S3_PATH=s3://percona-jenkins-artifactory-public/\$JOB_NAME/\$(git rev-parse --short HEAD)
9898
aws s3 ls \$S3_PATH/${LOG_FILE_NAME} || :
@@ -104,7 +104,7 @@ void pushLogFile(String FILE_NAME) {
104104
void pushArtifactFile(String FILE_NAME) {
105105
echo "Push $FILE_NAME file to S3!"
106106

107-
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AMI/OVF', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
107+
withCredentials([aws(credentialsId: 'AMI/OVF', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) {
108108
sh """
109109
touch ${FILE_NAME}
110110
S3_PATH=s3://percona-jenkins-artifactory/\$JOB_NAME/\$(git rev-parse --short HEAD)
@@ -129,7 +129,7 @@ void initTests() {
129129
void markPassedTests() {
130130
echo "Marking passed tests in the tests map!"
131131

132-
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AMI/OVF', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
132+
withCredentials([aws(credentialsId: 'AMI/OVF', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) {
133133
sh """
134134
aws s3 ls "s3://percona-jenkins-artifactory/${JOB_NAME}/${env.GIT_SHORT_COMMIT}/" || :
135135
"""
@@ -290,9 +290,9 @@ void prepareNode() {
290290
sudo curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl
291291
kubectl version --client --output=yaml
292292
293-
curl -fsSL https://get.helm.sh/helm-v3.18.3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm
293+
curl -fsSL https://get.helm.sh/helm-v3.19.0-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm
294294
295-
sudo curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq
295+
sudo curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.48.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq
296296
sudo curl -fsSL https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux64 -o /usr/local/bin/jq && sudo chmod +x /usr/local/bin/jq
297297
298298
sudo tee /etc/yum.repos.d/google-cloud-sdk.repo << EOF
@@ -490,7 +490,7 @@ pipeline {
490490
mkdir -p $(dirname ${docker_tag_file})
491491
echo ${DOCKER_TAG} > "${docker_tag_file}"
492492
sg docker -c "
493-
docker login -u '${USER}' -p '${PASS}'
493+
echo '\$PASS' | docker login -u '\$USER' --password-stdin
494494
export RELEASE=0
495495
export IMAGE=\$DOCKER_TAG
496496
./e2e-tests/build
@@ -650,7 +650,7 @@ pipeline {
650650
}
651651
}
652652
makeReport()
653-
step([$class: 'JUnitResultArchiver', testResults: '*.xml', healthScaleFactor: 1.0])
653+
junit testResults: '*.xml', healthScaleFactor: 1.0
654654
archiveArtifacts '*.xml'
655655

656656
unstash 'IMAGE'

build/logcollector/entrypoint.sh

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,100 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
3-
set -o xtrace
43

5-
export PATH="$PATH":/opt/fluent-bit/bin
4+
export PATH="$PATH:/opt/fluent-bit/bin"
65

7-
if [ "$1" = 'logrotate' ]; then
6+
LOGROTATE_SCHEDULE="${LOGROTATE_SCHEDULE:-0 0 * * *}"
7+
8+
is_logrotate_config_invalid() {
9+
local config_file="$1"
10+
if [ -z "$config_file" ] || [ ! -f "$config_file" ]; then
11+
return 1
12+
fi
13+
# Specifying -d runs in debug mode, so even in case of errors, it will exit with 0.
14+
# We need to check the output for "error" but skip those lines that are related to the missing logrotate.status file.
15+
# Filter out logrotate.status lines first, then check for remaining errors
16+
(
17+
set +e
18+
logrotate -d "$config_file" 2>&1 | grep -v "logrotate.status" | grep -qi "error"
19+
)
20+
return $?
21+
}
22+
23+
run_logrotate() {
24+
local logrotate_status_file="/data/db/logs/logrotate.status"
25+
local logrotate_conf_file="/opt/percona/logcollector/logrotate/logrotate.conf"
26+
local logrotate_additional_conf_files=()
27+
local conf_d_dir="/opt/percona/logcollector/logrotate/conf.d"
28+
29+
# Check if mongodb.conf exists and validate it
30+
if [ -f "$conf_d_dir/mongodb.conf" ]; then
31+
logrotate_conf_file="$conf_d_dir/mongodb.conf"
32+
if is_logrotate_config_invalid "$logrotate_conf_file"; then
33+
echo "ERROR: Logrotate configuration is invalid, fallback to default configuration"
34+
logrotate_conf_file="/opt/percona/logcollector/logrotate/logrotate.conf"
35+
fi
36+
fi
37+
38+
# Process all .conf files in conf.d directory (excluding mongodb.conf which is already handled)
39+
if [ -d "$conf_d_dir" ]; then
40+
for conf_file in "$conf_d_dir"/*.conf; do
41+
# Check if glob matched any files (if no .conf files exist, the glob returns itself)
42+
[ -f "$conf_file" ] || continue
43+
# Skip mongodb.conf as it's already processed above
44+
[ "$(basename "$conf_file")" = "mongodb.conf" ] && continue
45+
if is_logrotate_config_invalid "$conf_file"; then
46+
echo "ERROR: Logrotate configuration file $conf_file is invalid, it will be ignored"
47+
else
48+
logrotate_additional_conf_files+=("$conf_file")
49+
fi
50+
done
51+
fi
52+
# Ensure logrotate can run with current UID
853
if [[ $EUID != 1001 ]]; then
954
# logrotate requires UID in /etc/passwd
1055
sed -e "s^x:1001:^x:$EUID:^" /etc/passwd >/tmp/passwd
1156
cat /tmp/passwd >/etc/passwd
1257
rm -rf /tmp/passwd
1358
fi
14-
exec go-cron "0 0 * * *" sh -c "logrotate -s /data/db/logs/logrotate.status /opt/percona/logcollector/logrotate/logrotate.conf;"
15-
else
16-
if [ "$1" = 'fluent-bit' ]; then
17-
fluentbit_opt+='-c /opt/percona/logcollector/fluentbit/fluentbit.conf'
18-
fi
1959

20-
exec "$@" $fluentbit_opt
21-
fi
60+
local logrotate_cmd="logrotate -s \"$logrotate_status_file\" \"$logrotate_conf_file\""
61+
for additional_conf in "${logrotate_additional_conf_files[@]}"; do
62+
logrotate_cmd="$logrotate_cmd \"$additional_conf\""
63+
done
64+
65+
set -o xtrace
66+
exec go-cron "$LOGROTATE_SCHEDULE" sh -c "$logrotate_cmd"
67+
}
68+
69+
run_fluentbit() {
70+
local fluentbit_opt=(-c /opt/percona/logcollector/fluentbit/fluentbit.conf)
71+
mkdir -p /tmp/fluentbit/custom
72+
set +e
73+
local fluentbit_conf_dir="/opt/percona/logcollector/fluentbit/custom"
74+
for conf_file in $fluentbit_conf_dir/*.conf; do
75+
[ -f "$conf_file" ] || continue
76+
if ! fluent-bit --dry-run -c "$conf_file" >/dev/null 2>&1; then
77+
echo "ERROR: Fluentbit configuration file $conf_file is invalid, it will be ignored"
78+
else
79+
cp "$conf_file" /tmp/fluentbit/custom/
80+
fi
81+
done
82+
touch /tmp/fluentbit/custom/default.conf || true
83+
84+
set -e
85+
set -o xtrace
86+
exec "$@" "${fluentbit_opt[@]}"
87+
}
88+
89+
case "$1" in
90+
logrotate)
91+
run_logrotate
92+
;;
93+
fluent-bit)
94+
run_fluentbit "$@"
95+
;;
96+
*)
97+
echo "Invalid argument: $1"
98+
exit 1
99+
;;
100+
esac
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@INCLUDE fluentbit_*.conf
2-
@INCLUDE custom/*.conf
2+
@INCLUDE /tmp/fluentbit/custom/*.conf

build/pbm-entry.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ if [[ -z ${PBM_AGENT_TLS_ENABLED} ]] || [[ ${PBM_AGENT_TLS_ENABLED} == "true" ]]
77
fi
88
fi
99

10+
# shellcheck disable=SC1091
11+
test -e /opt/percona/pbm-hookscript/hook.sh && source /opt/percona/pbm-hookscript/hook.sh
12+
1013
exec "$@"

build/ps-entry.sh

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ _mongod_hack_have_arg() {
6868
local arg
6969
for arg; do
7070
case "$arg" in
71-
"$checkArg" | "$checkArg"=*)
72-
return 0
73-
;;
71+
"$checkArg" | "$checkArg"=*)
72+
return 0
73+
;;
7474
esac
7575
done
7676
return 1
@@ -83,14 +83,14 @@ _mongod_hack_get_arg_val() {
8383
local arg="$1"
8484
shift
8585
case "$arg" in
86-
"$checkArg")
87-
echo "$1"
88-
return 0
89-
;;
90-
"$checkArg"=*)
91-
echo "${arg#"$checkArg"=}"
92-
return 0
93-
;;
86+
"$checkArg")
87+
echo "$1"
88+
return 0
89+
;;
90+
"$checkArg"=*)
91+
echo "${arg#"$checkArg"=}"
92+
return 0
93+
;;
9494
esac
9595
done
9696
return 1
@@ -131,14 +131,14 @@ _mongod_hack_ensure_no_arg_val() {
131131
local arg="$1"
132132
shift
133133
case "$arg" in
134-
"$ensureNoArg")
135-
shift # also skip the value
136-
continue
137-
;;
138-
"$ensureNoArg"=*)
139-
# value is already included
140-
continue
141-
;;
134+
"$ensureNoArg")
135+
shift # also skip the value
136+
continue
137+
;;
138+
"$ensureNoArg"=*)
139+
# value is already included
140+
continue
141+
;;
142142
esac
143143
mongodHackedArgs+=("$arg")
144144
done
@@ -174,7 +174,7 @@ _mongod_hack_rename_arg_save_val() {
174174
val="$1"
175175
shift
176176
continue
177-
elif [[ $arg =~ "$oldArg"=(.*) ]]; then
177+
elif [[ $arg =~ ^${oldArg}=(.*)$ ]]; then
178178
val=${BASH_REMATCH[1]}
179179
continue
180180
fi
@@ -282,10 +282,10 @@ if [ "$originalArgOne" = 'mongod' ]; then
282282
# if we've got any /docker-entrypoint-initdb.d/* files to parse later, we should initdb
283283
for f in /docker-entrypoint-initdb.d/*; do
284284
case "$f" in
285-
*.sh | *.js) # this should match the set of files we check for below
286-
shouldPerformInitdb="$f"
287-
break
288-
;;
285+
*.sh | *.js) # this should match the set of files we check for below
286+
shouldPerformInitdb="$f"
287+
break
288+
;;
289289
esac
290290
done
291291
fi
@@ -387,17 +387,17 @@ if [ "$originalArgOne" = 'mongod' ]; then
387387
echo
388388
for f in /docker-entrypoint-initdb.d/*; do
389389
case "$f" in
390-
*.sh)
391-
echo "$0: running $f"
392-
# shellcheck source=/dev/null
393-
. "$f"
394-
;;
395-
*.js)
396-
echo "$0: running $f"
397-
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"
398-
echo
399-
;;
400-
*) echo "$0: ignoring $f" ;;
390+
*.sh)
391+
echo "$0: running $f"
392+
# shellcheck source=/dev/null
393+
. "$f"
394+
;;
395+
*.js)
396+
echo "$0: running $f"
397+
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"
398+
echo
399+
;;
400+
*) echo "$0: ignoring $f" ;;
401401
esac
402402
echo
403403
done
@@ -509,5 +509,8 @@ fi
509509

510510
rm -f "$jsonConfigFile" "$tempConfigFile"
511511

512+
# shellcheck disable=SC1091
513+
test -e /opt/percona/hookscript/hook.sh && source /opt/percona/hookscript/hook.sh
514+
512515
set -o xtrace
513516
exec "$@"

cmd/mongodb-healthcheck/db/db.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,27 @@ var (
2929
)
3030

3131
func Dial(ctx context.Context, conf *Config) (mongo.Client, error) {
32-
if err := conf.configureTLS(); err != nil {
32+
log := logf.FromContext(ctx).WithName("Dial")
33+
ctx = logf.IntoContext(ctx, log)
34+
35+
if err := conf.configureTLS(ctx); err != nil {
3336
return nil, errors.Wrap(err, "configure TLS")
3437
}
3538

36-
log := logf.FromContext(ctx)
3739
log.V(1).Info("Connecting to mongodb", "hosts", conf.Hosts, "ssl", conf.SSL.Enabled, "ssl_insecure", conf.SSL.Insecure)
3840

3941
if conf.Username != "" && conf.Password != "" {
4042
log.V(1).Info("Enabling authentication for session", "user", conf.Username)
4143
}
4244

43-
cl, err := mongo.Dial(&conf.Config)
45+
cl, err := mongo.Dial(ctx, &conf.Config)
4446
if err != nil {
4547
cfg := conf.Config
4648
cfg.Direct = true
4749
cfg.ReplSetName = ""
48-
cl, err = mongo.Dial(&cfg)
50+
cl, err = mongo.Dial(ctx, &cfg)
4951
if err != nil {
50-
return nil, errors.Wrap(err, "filed to dial mongo")
52+
return nil, errors.Wrap(err, "failed to dial mongo")
5153
}
5254
}
5355

0 commit comments

Comments
 (0)