Skip to content

Conversation

@viktor-karpochev
Copy link

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
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 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
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
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
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


// Create destination directory
if err := os.MkdirAll(destDir, 0755); err != nil {
return fmt.Errorf("failed to create DRBD build directory: %v", err)
Copy link
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 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
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")

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
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
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

Copy link

@sklyarevsky sklyarevsky left a comment

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 {

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{

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{

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))

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())

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) {

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 {

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")

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 {

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() {

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
@sklyarevsky sklyarevsky force-pushed the vkarpochev-drbd-build-server branch 6 times, most recently from ad023a5 to 49fc3d5 Compare November 25, 2025 15:47
@sklyarevsky sklyarevsky force-pushed the vkarpochev-drbd-build-server branch from 49fc3d5 to c6f2207 Compare November 25, 2025 15:55
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.

5 participants