Skip to content

Add drbd builder#312

Draft
viktor-karpochev wants to merge 78 commits into
mainfrom
vkarpochev-drbd-build-server
Draft

Add drbd builder#312
viktor-karpochev wants to merge 78 commits into
mainfrom
vkarpochev-drbd-build-server

Conversation

@viktor-karpochev

Copy link
Copy Markdown
Contributor

Description

Why do we need it, and what problem does it solve?

What is the expected result?

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Comment on lines +530 to +532
for i, koFile := range koFiles {
s.logger.Debug("Found .ko file", "job_id", jobID, "index", i+1, "file", koFile)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i, koFile := range koFiles {
s.logger.Debug("Found .ko file", "job_id", jobID, "index", i+1, "file", koFile)
}
s.logger.Debug("Found .ko files", "job_id", jobID, "files", koFiles)

Comment thread images/drbd-build-server/main.go Outdated
Comment on lines +721 to +725
env := os.Environ()
env = append(env, fmt.Sprintf("KVER=%s", kernelVersion))
env = append(env, fmt.Sprintf("KDIR=%s", kernelBuildDir))
env = append(env, fmt.Sprintf("SPAAS_URL=%s", s.spaasURL))
env = append(env, "SPAAS=true")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
env := os.Environ()
env = append(env, fmt.Sprintf("KVER=%s", kernelVersion))
env = append(env, fmt.Sprintf("KDIR=%s", kernelBuildDir))
env = append(env, fmt.Sprintf("SPAAS_URL=%s", s.spaasURL))
env = append(env, "SPAAS=true")
env := append(os.Environ(),
fmt.Sprintf("KVER=%s", kernelVersion),
fmt.Sprintf("KDIR=%s", kernelBuildDir),
fmt.Sprintf("SPAAS_URL=%s", s.spaasURL),
"SPAAS=true")

Comment on lines +797 to +804
if info, err := os.Stat(buildDir); err == nil && info.IsDir() {
makefilePath := filepath.Join(buildDir, "Makefile")
if _, err := os.Stat(makefilePath); err == nil {
s.logger.Debug("Found build directory in standard location", "job_id", jobID)
return buildDir, nil
}
s.logger.Debug("Standard location exists but Makefile not found", "job_id", jobID)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err != nil is not handled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the only place

Comment thread images/drbd-build-server/cmd/main.go Outdated

// Create destination directory
if err := os.MkdirAll(destDir, 0755); err != nil {
return fmt.Errorf("failed to create DRBD build directory: %v", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to create DRBD build directory: %v", err)
return fmt.Errorf("failed to create DRBD build directory: %w", err)

This way original error will be wrapped

Comment thread images/drbd-build-server/cmd/main.go Outdated
Comment on lines +899 to +903
s.logger.Debug("Cloning DRBD repository", "job_id", jobID, "version", version, "repo", repoURL, "dest", destDir)

// Determine branch name (format: drbd-9.2.12)
branch := fmt.Sprintf("drbd-%s", version)
s.logger.Debug("Cloning branch", "job_id", jobID, "branch", branch)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put vars in logger just once

Suggested change
s.logger.Debug("Cloning DRBD repository", "job_id", jobID, "version", version, "repo", repoURL, "dest", destDir)
// Determine branch name (format: drbd-9.2.12)
branch := fmt.Sprintf("drbd-%s", version)
s.logger.Debug("Cloning branch", "job_id", jobID, "branch", branch)
logger := s.logger.With("job_id", jobID, "version", version, "repo", repoURL, "dest", destDir)
logger.Debug("Cloning DRBD repository")
// Determine branch name (format: drbd-9.2.12)
branch := fmt.Sprintf("drbd-%s", version)
logger = logger.With("branch", branch)
logger.Debug("Cloning branch")

Comment thread images/drbd-build-server/cmd/main.go Outdated
func extractTarGz(r io.Reader, destDir string) error {
gzReader, err := gzip.NewReader(r)
if err != nil {
return fmt.Errorf("failed to create gzip reader: %v", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to create gzip reader: %v", err)
return fmt.Errorf("failed to create gzip reader: %w", err)

It's everywhere. Please fix all of them

@@ -0,0 +1,537 @@
package main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's good practice to have test in special package

Suggested change
package main
package main_test

@sklyarevsky sklyarevsky left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additionally need:

  1. make readme
  2. examples
  3. make templates for deploy

DownloadURL string `json:"download_url,omitempty"`
}

type server struct {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server and methods need put in a separate file


s.routes()

server := http.Server{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need rename the variable; the name conflicts with the structure; it's cognitively difficult to understand what it does.

return
}

s := &server{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs rena, one letter in the variable name is bad practice, in principle it is acceptable in template code with little context.


if *flagCertFile != "" && *flagKeyFile != "" {
logger.Info("Starting TLS server", "addr", *flagAddr)
logger.Error("Server failed", "error", server.ListenAndServeTLS(*flagCertFile, *flagKeyFile))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server.ListenAndServeTLS(*flagCertFile, *flagKeyFile) need put on a separate line, in fact there are two actions now, and the main one is logging, not listening

logger.Error("Server failed", "error", server.ListenAndServeTLS(*flagCertFile, *flagKeyFile))
} else {
logger.Info("Starting HTTP server", "addr", *flagAddr, "note", "TLS not configured")
logger.Error("Server failed", "error", server.ListenAndServe())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server.ListenAndServe() similar to the above

}

func (s *server) buildModuleHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better divide request processing to service and controller layers. The simplest and most convenient architecture is when you have a controller (your server). Controller should receive traffic, get request variables, and pass it on to service layer for processing (another object with processing methods). If processing async - controller returns result immediately and after processing if it sync.

job.mu.RUnlock()
s.logger.Debug("Found existing job", "remote_addr", remoteAddr, "job_id", jobID[:16], "status", status, "created_at", createdAt.Format(time.RFC3339))

if status == StatusBuilding || status == StatusPending {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there need switch and handle functions

Status: StatusBuilding,
JobID: cacheKey,
}
w.Header().Set("Content-Type", "application/json")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its should be in controller layer

// Create temporary directory for kernel headers
s.logger.Debug("Creating temporary directory", "job_id", jobID)
tmpDir, err := os.MkdirTemp("", "drbd-build-server-*")
if err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there need function to fail job with message as variable and after return job (to check error we can check job.Error)


// Cleanup DRBD copy after build (unless keepTmpDir is set)
if !s.keepTmpDir {
defer func() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be moved to function

@duckhawk duckhawk self-requested a review November 20, 2025 08:13
viktor-karpochev and others added 17 commits November 24, 2025 23:00
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: viktor-karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
This reverts commit 24d07d0.

Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Signed-off-by: Viktor Karpochev <viktor.karpochev@flant.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants