Skip to content

Commit e6cd380

Browse files
init
Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent b1fe5bd commit e6cd380

File tree

38 files changed

+2957
-0
lines changed

38 files changed

+2957
-0
lines changed

Taskfile.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,37 @@ tasks:
285285
}'
286286
kubectl -n d8-virtualization port-forward deploy/vit-api 2345:2345
287287
EOF
288+
289+
dlv:virtualization-dra-plugin:build:
290+
desc: "Build image virtualization-dra-plugin with dlv"
291+
cmds:
292+
- docker build --build-arg BRANCH=$BRANCH -f ./images/virtualization-dra-plugin/debug/dlv.Dockerfile -t "{{ .DLV_IMAGE }}" --platform linux/amd64 .
293+
294+
dlv:virtualization-dra-plugin:build-push:
295+
desc: "Build and Push image virtualization-dra-plugin with dlv"
296+
cmds:
297+
- task: dlv:virtualization-dra-plugin:build
298+
- docker push "{{ .DLV_IMAGE }}"
299+
- task: dlv:virtualization-dra-plugin:print
300+
301+
dlv:virtualization-dra-plugin:print:
302+
desc: "Print commands for debug"
303+
env:
304+
IMAGE: "{{ .DLV_IMAGE }}"
305+
cmd: |
306+
cat <<EOF
307+
kubectl -n d8-virtualization patch ds virtualization-dra --type='strategic' -p '{
308+
"spec": {
309+
"template": {
310+
"spec": {
311+
"containers": [ {
312+
"name": "virtualization-dra",
313+
"image": "${IMAGE}",
314+
"ports": [ { "containerPort": 2345, "name": "dlv" } ]
315+
}]
316+
}
317+
}
318+
}
319+
}'
320+
kubectl -n d8-virtualization port-forward deploy/virtualization-dra 2345:2345
321+
EOF
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package logger
18+
19+
import (
20+
"github.com/deckhouse/deckhouse/pkg/log"
21+
"github.com/spf13/pflag"
22+
)
23+
24+
type Options struct {
25+
Level string
26+
Output string
27+
DebugVerbosity int
28+
}
29+
30+
func (o *Options) AddFlags(fs *pflag.FlagSet) {
31+
fs.StringVar(&o.Level, "log-level", o.Level, "Log level")
32+
fs.StringVar(&o.Output, "log-output", o.Output, "Log output")
33+
fs.IntVar(&o.DebugVerbosity, "log-debug-verbosity", o.DebugVerbosity, "Log debug verbosity")
34+
}
35+
36+
func (o *Options) Complete() *log.Logger {
37+
return NewLogger(o.Level, o.Output, o.DebugVerbosity)
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM golang:1.24.7-bookworm@sha256:2c5f7a0c252a17cf6aa30ddee15caa0f485ee29410a6ea64cddb62eea2b07bdf AS builder
2+
ARG TARGETOS
3+
ARG TARGETARCH
4+
5+
WORKDIR /app/images/virtualization-dra
6+
RUN go install github.com/go-delve/delve/cmd/dlv@latest
7+
8+
COPY ./images/virtualization-dra/go.mod /app/images/virtualization-dra/
9+
COPY ./images/virtualization-dra/go.sum /app/images/virtualization-dra/
10+
11+
RUN go mod download
12+
13+
COPY ./images/virtualization-dra/cmd /app/images/virtualization-dra/cmd
14+
COPY ./images/virtualization-dra/internal /app/images/virtualization-dra/internal
15+
COPY ./images/virtualization-dra/pkg /app/images/virtualization-dra/pkg
16+
17+
ENV GO111MODULE=on
18+
ENV GOOS=${TARGETOS:-linux}
19+
ENV GOARCH=${TARGETARCH:-amd64}
20+
ENV CGO_ENABLED=0
21+
22+
RUN go build -tags EE -gcflags "all=-N -l" -a -o virtualization-dra-plugin ./cmd/virtualization-dra-plugin
23+
24+
FROM busybox:1.36.1-glibc
25+
26+
WORKDIR /app
27+
COPY --from=builder /go/bin/dlv /app/dlv
28+
COPY --from=builder /app/images/virtualization-dra/virtualization-dra-plugin /app/virtualization-dra-plugin
29+
USER 65532:65532
30+
31+
ENTRYPOINT ["./dlv", "--listen=:2345", "--headless=true", "--continue", "--log=true", "--log-output=debugger,debuglineerr,gdbwire,lldbout,rpc", "--accept-multiclient", "--api-version=2", "exec", "./virtualization-dra-plugin", "--"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# A list of pre-created mount points for containerd strict mode.
2+
3+
dirs:
4+
- /var/run/dbus
5+
- /var/run/cdi
6+
# - /sys/bus/usb/devices
7+
- /var/lib/kubelet/plugins_registry
8+
- /var/lib/kubelet/plugins
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
image: {{ .ModuleNamePrefix }}{{ .ImageName }}
3+
fromImage: {{ .ModuleNamePrefix }}distroless
4+
git:
5+
{{- include "image mount points" . }}
6+
import:
7+
- image: {{ .ModuleNamePrefix }}virtualization-dra-builder
8+
add: /out/virtualization-dra-plugin
9+
to: /app/virtualization-dra-plugin
10+
after: install
11+
{{- if eq $.DEBUG_COMPONENT "delve/virtualization-dra-plugin" }}
12+
- image: debugger
13+
add: /app/dlv
14+
to: /app/dlv
15+
after: install
16+
{{- end }}
17+
imageSpec:
18+
config:
19+
user: 64535
20+
workingDir: "/app"
21+
{{- if eq $.DEBUG_COMPONENT "delve/virtualization-dra-plugin" }}
22+
env:
23+
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/dlv"
24+
XDG_CONFIG_HOME: "/tmp"
25+
entrypoint: ["/app/dlv", "--listen=:2345", "--headless=true", "--continue", "--log=true", "--log-output=debugger,debuglineerr,gdbwire,lldbout,rpc", "--accept-multiclient", "--api-version=2", "exec", "/app/virtualization-dra-plugin", "--", "--leader-election=false"]
26+
{{- else }}
27+
entrypoint: ["/app/virtualization-dra-plugin"]
28+
{{- end }}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
run:
2+
concurrency: 4
3+
timeout: 10m
4+
issues:
5+
# Show all errors.
6+
max-issues-per-linter: 0
7+
max-same-issues: 0
8+
exclude:
9+
- "don't use an underscore in package name"
10+
output:
11+
sort-results: true
12+
13+
exclude-files:
14+
- "^zz_generated.*"
15+
16+
linters-settings:
17+
gofumpt:
18+
extra-rules: true
19+
gci:
20+
sections:
21+
- standard
22+
- default
23+
- prefix(github.com/deckhouse/)
24+
goimports:
25+
local-prefixes: github.com/deckhouse/
26+
errcheck:
27+
exclude-functions: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy
28+
revive:
29+
rules:
30+
- name: dot-imports
31+
disabled: true
32+
nolintlint:
33+
# Exclude following linters from requiring an explanation.
34+
# Default: []
35+
allow-no-explanation: [funlen, gocognit, lll]
36+
# Enable to require an explanation of nonzero length after each nolint directive.
37+
# Default: false
38+
require-explanation: true
39+
# Enable to require nolint directives to mention the specific linter being suppressed.
40+
# Default: false
41+
require-specific: true
42+
importas:
43+
# Do not allow unaliased imports of aliased packages.
44+
# Default: false
45+
no-unaliased: true
46+
# Do not allow non-required aliases.
47+
# Default: false
48+
no-extra-aliases: false
49+
# List of aliases
50+
# Default: []
51+
alias:
52+
- pkg: github.com/deckhouse/virtualization/api/core/v1alpha2
53+
alias: ""
54+
- pkg: github.com/deckhouse/virtualization/api/subresources/v1alpha2
55+
alias: subv1alpha2
56+
- pkg: kubevirt.io/api/core/v1
57+
alias: virtv1
58+
- pkg: k8s.io/api/core/v1
59+
alias: corev1
60+
- pkg: k8s.io/api/authentication/v1
61+
alias: authnv1
62+
- pkg: k8s.io/api/storage/v1
63+
alias: storagev1
64+
- pkg: k8s.io/api/networking/v1
65+
alias: netv1
66+
- pkg: k8s.io/api/policy/v1
67+
alias: policyv1
68+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
69+
alias: metav1
70+
71+
linters:
72+
disable-all: true
73+
enable:
74+
- asciicheck # checks that your code does not contain non-ASCII identifiers
75+
- bidichk # checks for dangerous unicode character sequences
76+
- bodyclose # checks whether HTTP response body is closed successfully
77+
- contextcheck # [maby too many false positives] checks the function whether use a non-inherited context
78+
- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
79+
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
80+
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
81+
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
82+
- copyloopvar # detects places where loop variables are copied (Go 1.22+)
83+
- gci # controls golang package import order and makes it always deterministic
84+
- gocritic # provides diagnostics that check for bugs, performance and style issues
85+
- gofmt # [replaced by goimports] checks whether code was gofmt-ed
86+
- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
87+
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
88+
- gosimple # specializes in simplifying a code
89+
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
90+
- ineffassign # detects when assignments to existing variables are not used
91+
- misspell # finds commonly misspelled English words in comments
92+
- nolintlint # reports ill-formed or insufficient nolint directives
93+
- reassign # Checks that package variables are not reassigned.
94+
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
95+
- stylecheck # is a replacement for golint
96+
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
97+
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
98+
- testifylint # checks usage of github.com/stretchr/testify
99+
- unconvert # removes unnecessary type conversions
100+
- unparam # reports unused function parameters
101+
- unused # checks for unused constants, variables, functions and types
102+
- usetesting # reports uses of functions with replacement inside the testing package
103+
- testableexamples # checks if examples are testable (have an expected output)
104+
- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
105+
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
106+
- whitespace # detects leading and trailing whitespace
107+
- wastedassign # Finds wasted assignment statements.
108+
- importas # checks import aliases against the configured convention
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: "3"
2+
3+
silent: true
4+
5+
tasks:
6+
fmt:
7+
desc: "Run formatters locally"
8+
cmds:
9+
- task: fmt:gci
10+
- task: fmt:gofumpt
11+
12+
fmt:gci:
13+
desc: "Format code with gci, important vars: paths."
14+
cmds:
15+
- |
16+
gci write --skip-generated -s standard,default,prefix\(github.com/deckhouse/\) {{.CLI_ARGS}} {{.paths | default "pkg/ cmd/"}}
17+
18+
fmt:gofumpt:
19+
desc: "Format code with gofumpt, important vars: paths"
20+
cmds:
21+
- |
22+
gofumpt -extra -w {{.CLI_ARGS}} {{.paths | default "cmd/ pkg/"}}
23+
24+
dev:gogenerate:
25+
desc: |-
26+
Run go generate for all packages.
27+
cmds:
28+
- |
29+
go generate ./...
30+
31+
dev:addlicense:
32+
desc: |-
33+
Add Flant CE license to files sh,go,py. Default directory is root of project, custom directory path can be passed like: "task dev:addlicense -- <somedir>"
34+
cmds:
35+
- |
36+
{{if .CLI_ARGS}}
37+
go run ../../tools/addlicense/{main,variables,msg,utils}.go -directory {{ .CLI_ARGS }}
38+
{{else}}
39+
go run ../../tools/addlicense/{main,variables,msg,utils}.go -directory ./
40+
{{end}}
41+
42+
test:unit:
43+
desc: "Run go unit tests"
44+
cmds:
45+
- |
46+
go tool ginkgo -v -r pkg/
47+
48+
lint:
49+
desc: "Run linters locally"
50+
cmds:
51+
- task: lint:go
52+
53+
lint:go:
54+
desc: "Run golangci-lint"
55+
deps:
56+
- _ensure:golangci-lint
57+
cmds:
58+
- |
59+
golangci-lint run

0 commit comments

Comments
 (0)