-
Notifications
You must be signed in to change notification settings - Fork 4
Add drbd builder #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add drbd builder #312
Conversation
| for i, koFile := range koFiles { | ||
| s.logger.Debug("Found .ko file", "job_id", jobID, "index", i+1, "file", koFile) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) |
images/drbd-build-server/main.go
Outdated
| 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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") |
| 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) | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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
| 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) |
There was a problem hiding this comment.
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
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 | |||
There was a problem hiding this comment.
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
| package main | |
| package main_test |
sklyarevsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionally need:
- make readme
- examples
- make templates for deploy
| DownloadURL string `json:"download_url,omitempty"` | ||
| } | ||
|
|
||
| type server struct { |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
Signed-off-by: v.oleynikov <[email protected]>
ad023a5 to
49fc3d5
Compare
49fc3d5 to
c6f2207
Compare
Description
Why do we need it, and what problem does it solve?
What is the expected result?
Checklist