Skip to content

Commit ee672c4

Browse files
authored
Merge branch 'main' into add-labels
Signed-off-by: Aleksandr Zimin <[email protected]>
2 parents 74564d6 + 265acbb commit ee672c4

Some content is hidden

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

51 files changed

+2600
-2452
lines changed

.github/scripts/fetch_prs.mjs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2024 Flant JSC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { Octokit } from '@octokit/core';
16+
import axios from 'axios';
17+
import moment from 'moment';
18+
19+
const owner = 'deckhouse';
20+
const repo = 'sds-node-configurator';
21+
const project = 'SNC'
22+
23+
const octokit = new Octokit({ auth: process.env.PR_SUMMARY_TOKEN });
24+
25+
26+
async function fetchPullRequests() {
27+
const pulls = await octokit.request('GET /repos/{owner}/{repo}/pulls', {
28+
owner,
29+
repo,
30+
state: 'all'
31+
});
32+
return pulls.data.filter(pr => !pr.draft);
33+
}
34+
35+
const recentDays = 2;
36+
37+
function generateSummary(prs) {
38+
const now = moment();
39+
const reviewRequired = prs.filter(pr => pr.state === 'open' && pr.requested_reviewers.length > 0);
40+
const recent = reviewRequired.filter(pr => moment().diff(moment(pr.created_at), 'days') <= recentDays);
41+
const lasting = reviewRequired.filter(pr => moment().diff(moment(pr.created_at), 'days') > recentDays);
42+
43+
let summary = `## ${project} PRs ${now.format('YYYY-MM-DD')}\n\n`;
44+
45+
if (reviewRequired.length == 0) {
46+
summary += `:tada: No review required for today\n`;
47+
return summary;
48+
}
49+
50+
if (recent.length > 0) {
51+
summary += `### Recent PRs requiring review
52+
${recent.map(pr => `- [${pr.title}](${pr.html_url}) (Created: ${moment(pr.created_at).fromNow()})`).join('\n')}
53+
`;
54+
}
55+
56+
if (lasting.length > 0) {
57+
summary += `### PRs requiring review
58+
${lasting.map(pr => `- [${pr.title}](${pr.html_url}) (Created: ${moment(pr.created_at).fromNow()})`).join('\n')}
59+
`;
60+
}
61+
62+
return summary
63+
}
64+
65+
async function sendSummaryToLoop(summary) {
66+
const url = process.env.LOOP_WEBHOOK_URL;
67+
await axios.post(url, {
68+
text: summary
69+
});
70+
}
71+
72+
async function run() {
73+
try {
74+
const prs = await fetchPullRequests();
75+
const summary = generateSummary(prs);
76+
await sendSummaryToLoop(summary);
77+
} catch (error) {
78+
console.error(error);
79+
process.exit(1);
80+
}
81+
}
82+
83+
run();

.github/scripts/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "github-action-pr-summary",
3+
"version": "1.0.0",
4+
"main": ".github/scripts/fetch_prs.mjs",
5+
"dependencies": {
6+
"@octokit/core": "^3.2.5",
7+
"axios": "^0.24.0",
8+
"moment": "^2.29.1"
9+
},
10+
"type": "module"
11+
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Check Go modules version
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
name: Check Go modules version
12+
runs-on: [self-hosted, regular]
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Setup Go environment
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.22'
22+
23+
- name: Run Go modules version check
24+
run: |
25+
search_dir=$(pwd)"/images"
26+
27+
if [ ! -d "$search_dir" ]; then
28+
echo "Directory $search_dir does not exist."
29+
exit 1
30+
fi
31+
32+
temp_dir=$(mktemp -d)
33+
34+
trap 'rm -rf "$temp_dir"' EXIT
35+
36+
find "$search_dir" -name "go.mod" | while read -r go_mod_file; do
37+
echo "Processing $go_mod_file"
38+
39+
while IFS= read -r line; do
40+
if [[ "$line" == *github.com/deckhouse/sds-* || "$line" == *github.com/deckhouse/csi-* || "$line" == *github.com/deckhouse/virtualization ]]; then
41+
repository=$(echo "$line" | awk '{print $1}' | awk -F'/' '{ print "https://"$1"/"$2"/"$3".git" }')
42+
pseudo_tag=$(echo "$line" | awk '{print $2}')
43+
echo "Cloning repo $repository into $temp_dir"
44+
45+
git clone "$repository" "$temp_dir/$repository" >/dev/null 2>&1
46+
47+
if [ -d "$temp_dir/$repository/api" ]; then
48+
cd "$temp_dir/$repository" || continue
49+
50+
commit_info=$(git log -1 --pretty=format:"%H %cd" --date=iso-strict -- api/*)
51+
short_hash=$(echo "$commit_info" | awk '{print substr($1,1,12)}')
52+
commit_date=$(echo "$commit_info" | awk '{print $2}')
53+
commit_date=$(date -u -d "$commit_date" +"%Y%m%d%H%M%S")
54+
actual_pseudo_tag="v0.0.0-"$commit_date"-"$short_hash
55+
pseudo_tag_date=$(echo $pseudo_tag | awk -F'-' '{ print $2 }')
56+
echo "Latest commit in $repository: $short_hash $commit_date"
57+
58+
if [[ "$pseudo_tag_date" < "$commit_date" ]]; then
59+
echo "Incorrect pseudo tag for repo $repository in file "$go_mod_file" (current: "$pseudo_tag", actual:"$actual_pseudo_tag")"
60+
echo "Incorrect pseudo tag for repo $repository in file "$go_mod_file" (current: "$pseudo_tag", actual:"$actual_pseudo_tag")" >> $temp_dir"/incorrect_alert"
61+
fi
62+
63+
cd - >/dev/null 2>&1
64+
else
65+
echo "No api directory in $repository"
66+
fi
67+
68+
rm -rf "$temp_dir/$repository"
69+
fi
70+
done < "$go_mod_file"
71+
done
72+
73+
alert_lines_count=$(cat $temp_dir"/incorrect_alert" | wc -l)
74+
75+
if [ $alert_lines_count != 0 ]; then
76+
echo "We have non-actual pseudo-tags in repository's go.mod files"
77+
exit 1
78+
fi

.github/workflows/prs-summary.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2024 Flant JSC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: PR Summary
16+
17+
on:
18+
schedule:
19+
- cron: "0 7 * * 1-5" # Runs on every day-of-week from Monday through Friday at 7 AM UTC (10 AM MSK)
20+
workflow_dispatch:
21+
22+
defaults:
23+
run:
24+
shell: bash
25+
26+
jobs:
27+
pr_summary:
28+
runs-on: [self-hosted, regular]
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v2
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v2
36+
with:
37+
node-version: "18" # Use Node.js 18
38+
39+
- name: Install dependencies
40+
run: npm install -S .github/scripts
41+
42+
- name: Fetch PR Data and Send Summary
43+
run: |
44+
node ./.github/scripts/fetch_prs.mjs
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.PR_SUMMARY_TOKEN }}
47+
LOOP_WEBHOOK_URL: ${{ secrets.LOOP_WEBHOOK_URL }}

.golangci.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ issues:
77
- "should not use dot imports"
88
- "don't use an underscore in package name"
99
- "exported: .*"
10+
- "could not import"
1011

1112
linters-settings:
1213
gci:
1314
sections:
1415
- standard
1516
- default
17+
- prefix(agent)
18+
- prefix(sds-health-watcher-controller)
19+
- prefix(sds-utils-installer)
1620
errcheck:
1721
ignore: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy
1822

@@ -24,7 +28,7 @@ linters:
2428
- gci
2529
- gocritic
2630
- gofmt
27-
- goimports
31+
# - goimports
2832
- gosimple
2933
- govet
3034
- ineffassign

images/agent/src/cmd/main.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"agent/config"
21-
"agent/pkg/cache"
22-
"agent/pkg/controller"
23-
"agent/pkg/kubutils"
24-
"agent/pkg/logger"
25-
"agent/pkg/monitoring"
26-
"agent/pkg/scanner"
2720
"context"
2821
"fmt"
29-
"github.com/deckhouse/sds-node-configurator/api/v1alpha1"
3022
"os"
3123
goruntime "runtime"
32-
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3324

25+
"github.com/deckhouse/sds-node-configurator/api/v1alpha1"
3426
v1 "k8s.io/api/core/v1"
3527
sv1 "k8s.io/api/storage/v1"
3628
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -39,6 +31,15 @@ import (
3931
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
4032
"sigs.k8s.io/controller-runtime/pkg/healthz"
4133
"sigs.k8s.io/controller-runtime/pkg/manager"
34+
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
35+
36+
"agent/config"
37+
"agent/pkg/cache"
38+
"agent/pkg/controller"
39+
"agent/pkg/kubutils"
40+
"agent/pkg/logger"
41+
"agent/pkg/monitoring"
42+
"agent/pkg/scanner"
4243
)
4344

4445
var (
@@ -61,7 +62,7 @@ func main() {
6162

6263
log, err := logger.NewLogger(cfgParams.Loglevel)
6364
if err != nil {
64-
fmt.Println(fmt.Sprintf("unable to create NewLogger, err: %v", err))
65+
fmt.Printf("unable to create NewLogger, err: %v\n", err)
6566
os.Exit(1)
6667
}
6768

@@ -71,7 +72,7 @@ func main() {
7172
log.Info("[main] CfgParams has been successfully created")
7273
log.Info(fmt.Sprintf("[main] %s = %s", config.LogLevel, cfgParams.Loglevel))
7374
log.Info(fmt.Sprintf("[main] %s = %s", config.NodeName, cfgParams.NodeName))
74-
log.Info(fmt.Sprintf("[main] %s = %s", config.MachineID, cfgParams.MachineId))
75+
log.Info(fmt.Sprintf("[main] %s = %s", config.MachineID, cfgParams.MachineID))
7576
log.Info(fmt.Sprintf("[main] %s = %s", config.ScanInterval, cfgParams.BlockDeviceScanIntervalSec.String()))
7677
log.Info(fmt.Sprintf("[main] %s = %s", config.ThrottleInterval, cfgParams.ThrottleIntervalSec.String()))
7778
log.Info(fmt.Sprintf("[main] %s = %s", config.CmdDeadlineDuration, cfgParams.CmdDeadlineDurationSec.String()))

images/agent/src/config/config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
"agent/internal"
21-
"agent/pkg/logger"
2220
"bytes"
2321
"fmt"
2422
"os"
2523
"os/exec"
26-
2724
"strconv"
2825
"strings"
2926
"time"
27+
28+
"agent/internal"
29+
"agent/pkg/logger"
3030
)
3131

3232
const (
@@ -42,7 +42,7 @@ const (
4242
)
4343

4444
type Options struct {
45-
MachineId string
45+
MachineID string
4646
NodeName string
4747
Loglevel logger.Verbosity
4848
MetricsPort string
@@ -69,11 +69,11 @@ func NewConfig() (*Options, error) {
6969
opts.Loglevel = logger.Verbosity(loglevel)
7070
}
7171

72-
machId, err := getMachineId()
72+
machID, err := getMachineID()
7373
if err != nil {
7474
return nil, fmt.Errorf("[NewConfig] unable to get %s, error: %w", MachineID, err)
7575
}
76-
opts.MachineId = machId
76+
opts.MachineID = machID
7777

7878
opts.MetricsPort = os.Getenv(MetricsPort)
7979
if opts.MetricsPort == "" {
@@ -127,7 +127,7 @@ func NewConfig() (*Options, error) {
127127
return &opts, nil
128128
}
129129

130-
func getMachineId() (string, error) {
130+
func getMachineID() (string, error) {
131131
id := os.Getenv(MachineID)
132132
if id == "" {
133133
args := []string{"-m", "-u", "-i", "-n", "-p", "-t", "1", "cat", "/etc/machine-id"}

0 commit comments

Comments
 (0)