Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
adce620
chore(core): cdi-cloner cloner_startup.sh to go
universal-itengineer Mar 24, 2025
4bbe7fa
refactor install bins
universal-itengineer Mar 24, 2025
88ffb6c
rm unnecessary code
universal-itengineer Mar 24, 2025
23d61db
refactor code
universal-itengineer Mar 24, 2025
10f00c4
add bash
universal-itengineer Mar 24, 2025
a2e7b54
remove unnecessary binaries
universal-itengineer Mar 25, 2025
84b7dc7
refactor cloner-startup
universal-itengineer Mar 25, 2025
5d8b6d9
remove install libnbd-dev
universal-itengineer Mar 25, 2025
3d3dee7
rm bins
universal-itengineer Mar 25, 2025
2e221f7
fix missing bins
universal-itengineer Mar 25, 2025
8633432
refactor build static binariess, move cbuilder to cdi-artifact
universal-itengineer Mar 25, 2025
07bc58c
add slog to cloner-startup
universal-itengineer Mar 25, 2025
caf3b52
Update images/cdi-cloner/cloner-startup/internal/helpers/size.go
universal-itengineer Mar 25, 2025
549f420
Update images/cdi-cloner/cloner-startup/internal/helpers/size.go
universal-itengineer Mar 25, 2025
83fe91e
Update images/cdi-cloner/cloner-startup/internal/helpers/size.go
universal-itengineer Mar 25, 2025
126c089
Update images/cdi-cloner/cloner-startup/internal/helpers/size.go
universal-itengineer Mar 25, 2025
a841479
refactor change dir, add golint
universal-itengineer Mar 25, 2025
15c830f
test: add var ioctlcmd for getting dev block size or device block size
universal-itengineer Mar 25, 2025
5257d3a
rm const file and fix calc total directory size
universal-itengineer Mar 25, 2025
0660497
update patch 024
universal-itengineer Mar 26, 2025
d319ed5
refactor GetDirectorySize and upload bytes
universal-itengineer Mar 26, 2025
418a5df
refacrot GetDirectorySize and preallocation
universal-itengineer Mar 26, 2025
35e276d
resolve comments
universal-itengineer Mar 26, 2025
8aa956d
fix log messages
universal-itengineer Mar 26, 2025
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
diff --git a/pkg/controller/clone/prep-claim.go b/pkg/controller/clone/prep-claim.go
index 68a249b77..5e96feee0 100644
index 68a249b77..3c7e96959 100644
--- a/pkg/controller/clone/prep-claim.go
+++ b/pkg/controller/clone/prep-claim.go
@@ -162,8 +162,8 @@ func (p *PrepClaimPhase) createPod(ctx context.Context, name string, pvc *corev1
@@ -162,8 +162,7 @@ func (p *PrepClaimPhase) createPod(ctx context.Context, name string, pvc *corev1
Name: "dummy",
Image: p.Image,
ImagePullPolicy: p.PullPolicy,
- Command: []string{"/bin/bash"},
- Args: []string{"-c", "echo", "'hello cdi'"},
+ Command: []string{"/bin/hello"},
+ // Args: []string{"-c", "echo", "'hello cdi'"},
},
},
ImagePullSecrets: imagePullSecrets,
Expand Down
23 changes: 23 additions & 0 deletions images/cdi-artifact/werf.inc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,26 @@ shell:
- chmod +x /cdi-binaries/*
- chown -R 64535:64535 /cdi-binaries/*
- ls -la /cdi-binaries

---
image: {{ $.ImageName }}-cbuilder
final: false
from: {{ .Images.BASE_DEBIAN_BOOKWORM_SLIM }}
git:
- add: /images/{{ $.ImageName }}/static_binaries
to: /
stageDependencies:
install:
- '*.c'
shell:
install:
- |
apt-get update && apt-get install --yes gcc musl-dev musl-tools
apt-get clean

echo "Building simple app that prints hello cdi"
mkdir -p /bins
musl-gcc -static -Os -o /bins/hello hello.c
musl-gcc -static -Os -o /bins/printFile print_file_context.c
strip /bins/hello
strip /bins/printFile
60 changes: 60 additions & 0 deletions images/cdi-cloner/cloner-startup/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
run:
timeout: 10m
# skip-dirs:
# this code has been copied from kubectl cli. No need to lint external code.
# - go_lib/dependency/k8s/drain
# this code has been copied from kubernetes vertical-pod-autoscaler. No need to lint external code.
# - modules/302-vertical-pod-autoscaler/hooks/internal/vertical-pod-autoscaler/v1
issues:
# Show all errors.
max-issues-per-linter: 0
max-same-issues: 0
exclude:
# - ST1005.*
- "don't use an underscore in package name"
# - "exported: .*"

linters-settings:
gofumpt:
extra-rules: true
gci:
sections:
- standard
- default
- prefix(github.com/deckhouse/)
goimports:
local-prefixes: github.com/deckhouse/
errcheck:
exclude-functions: fmt:.*,[rR]ead|[wW]rite|[cC]lose,io:Copy
revive:
rules:
- name: dot-imports
disabled: true

linters:
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- dogsled
- errcheck
- errname
- errorlint
- gci
- gocritic
- gofmt
- gofumpt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
101 changes: 101 additions & 0 deletions images/cdi-cloner/cloner-startup/cmd/cloner-startup/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"fmt"
"log/slog"
"os"

"cloner-startup/internal/helpers"
)

func main() {
var uploadBytes uint64

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
slog.SetDefault(logger)

volumeMode, err := helpers.GetEnv("VOLUME_MODE")
if err != nil {
logger.Error("Failed to get env VOLUME_MODE", slog.String("error", err.Error()))
os.Exit(1)
}

mountPoint, err := helpers.GetEnv("MOUNT_POINT")
if err != nil {
logger.Error("Failed to get env MOUNT_POINT", slog.String("error", err.Error()))
os.Exit(1)
}

preallocation, err := helpers.GetBoolEnv("PREALLOCATION")
if err != nil {
logger.Error("Failed to get env PREALLOCATION", slog.String("error", err.Error()))
os.Exit(1)
}

logger.Info(fmt.Sprintf(
"VOLUME_MODE=%s\n"+
"MOUNT_POINT=%s\n"+
"PREALLOCATION=%v",
volumeMode,
mountPoint,
preallocation))

if volumeMode == "block" {
uploadBytes, err = helpers.GetBlockDeviceSize(mountPoint)
if err != nil {
logger.Error("Block size calculation failed", slog.String("error", err.Error()))
os.Exit(1)
}

logger.Info(fmt.Sprintf("Start clone block with %s", helpers.FormatBytes(float64(uploadBytes))))

if err = helpers.RunCloner("blockdevice-clone", uploadBytes, mountPoint); err != nil {
logger.Error("Error running cdi-cloner", slog.String("error", err.Error()))
os.Exit(1)
}
} else {
// Check if directory accesseble
if err := os.Chdir(mountPoint); err != nil {
logger.Error("Mount point access failed", slog.String("error", err.Error()))
os.Exit(1)
}

totalBytes, totalUsedBytes, err := helpers.GetDirectorySize(".")
if err != nil {
logger.Error("Directory size calculation failed", slog.String("error", err.Error()))
os.Exit(1)
}

if preallocation {
uploadBytes = totalBytes
logger.Info("Preallocating filesystem, uploading all bytes")
} else {
uploadBytes = totalUsedBytes
logger.Info("Not preallocating filesystem, get only used blocks in bytes")
}

logger.Info(fmt.Sprintf("Start clone with %d bytes", uploadBytes))
logger.Info(fmt.Sprintf("Start clone with %s", helpers.FormatBytes(float64(uploadBytes))))

if err = helpers.RunCloner("filesystem-clone", uploadBytes, mountPoint); err != nil {
logger.Error("Error running cdi-cloner", slog.String("error", err.Error()))
os.Exit(1)
}
}
}
5 changes: 5 additions & 0 deletions images/cdi-cloner/cloner-startup/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module cloner-startup

go 1.22.8

require golang.org/x/sys v0.30.0
2 changes: 2 additions & 0 deletions images/cdi-cloner/cloner-startup/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
39 changes: 39 additions & 0 deletions images/cdi-cloner/cloner-startup/internal/helpers/cloner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helpers

import (
"os"
"os/exec"
"strconv"
)

func RunCloner(contentType string, uploadBytes uint64, mountPoint string) error {
cmd := exec.Command("/usr/bin/cdi-cloner",
"-v=3",
"-alsologtostderr",
"-content-type="+contentType,
"-upload-bytes="+strconv.FormatUint(uploadBytes, 10),
"-mount="+mountPoint,
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helpers

import (
"fmt"
"os"
"strconv"
)

func GetEnv(key string) (string, error) {
value, ok := os.LookupEnv(key)
if !ok {
return "", fmt.Errorf("missing required environment variable: %s", key)
}
return value, nil
}

func GetBoolEnv(key string) (bool, error) {
value, err := GetEnv(key)
if err != nil {
return false, err
}
return strconv.ParseBool(value)
}
Loading
Loading