Skip to content

Commit 51cc84f

Browse files
committed
[drbd-build-svr]: fix linter
1 parent bbc0c02 commit 51cc84f

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

images/drbd-build-server/cmd/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const (
1616
Version string = "0.0.0" // Version TODO: inject version later (19/11/2025)
1717

1818
maxHeaderBytes int = 4 * 1024
19-
readTimeoutMs time.Duration = 30 * time.Minute
20-
writeTimeoutMs time.Duration = 30 * time.Minute
19+
readTimeout time.Duration = 30 * time.Minute
20+
writeTimeout time.Duration = 30 * time.Minute
2121
)
2222

2323
var (
@@ -100,8 +100,8 @@ func main() {
100100
Addr: *flagAddr,
101101
Handler: requestHandler,
102102
MaxHeaderBytes: maxHeaderBytes,
103-
ReadTimeout: readTimeoutMs,
104-
WriteTimeout: writeTimeoutMs,
103+
ReadTimeout: readTimeout,
104+
WriteTimeout: writeTimeout,
105105
}
106106

107107
if *flagCertFile != "" && *flagKeyFile != "" {

images/drbd-build-server/pkg/control/control.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func (s *BuildServer) replyAccepted(w http.ResponseWriter, resp *model.BuildResp
3636
if err := json.NewEncoder(w).Encode(resp); err != nil {
3737
s.logger.Error("Failed to encode response", "error", err)
3838
}
39-
return
4039
}
4140

4241
func (s *BuildServer) replyOk(w http.ResponseWriter, resp *model.BuildResponse) {
@@ -45,7 +44,6 @@ func (s *BuildServer) replyOk(w http.ResponseWriter, resp *model.BuildResponse)
4544
if err := json.NewEncoder(w).Encode(resp); err != nil {
4645
s.logger.Error("Failed to encode response", "error", err)
4746
}
48-
return
4947
}
5048

5149
type BuildServer struct {
@@ -91,7 +89,6 @@ func getKernelVersion(r *http.Request, s *BuildServer, remoteAddr string) (strin
9189
if !kernelVersionRegex.MatchString(kernelVersion) {
9290
s.logger.Error("Invalid kernel version format", "remote_addr", remoteAddr, "kernel_version", kernelVersion)
9391
return "", errors.New("Invalid kernel version format. Expected format: X.Y.Z[-flavor] or X.Y.Z[-flavor]-build")
94-
9592
}
9693

9794
return kernelVersion, nil
@@ -140,14 +137,14 @@ func (s *BuildServer) registerRoutes() {
140137
s.router.HandleFunc(helloPath, s.helloHandler()).Methods("GET")
141138
}
142139

143-
func (s *BuildServer) errorf(code int, remoteAddr string, w http.ResponseWriter, format string, a ...interface{}) {
140+
func (s *BuildServer) replyErrorFormated(code int, remoteAddr string, w http.ResponseWriter, format string, a ...interface{}) {
144141
w.WriteHeader(code)
145142
msg := fmt.Sprintf(format, a...)
146143
_, _ = fmt.Fprint(w, msg)
147144
s.logger.Error("HTTP error", "remote_addr", remoteAddr, "code", code, "error", msg)
148145
}
149146

150-
func (s *BuildServer) error(code int, remoteAddr string, w http.ResponseWriter, error error) {
147+
func (s *BuildServer) replyError(code int, remoteAddr string, w http.ResponseWriter, error error) {
151148
w.WriteHeader(code)
152149
s.logger.Error("HTTP error", "remote_addr", remoteAddr, "code", code, "error", error)
153150
}
@@ -168,20 +165,20 @@ func (s *BuildServer) buildModuleHandler() http.HandlerFunc {
168165

169166
kernelVersion, err := getKernelVersion(r, s, remoteAddr)
170167
if err != nil {
171-
s.error(http.StatusBadRequest, remoteAddr, w, err)
168+
s.replyError(http.StatusBadRequest, remoteAddr, w, err)
172169
return
173170
}
174171
headersData, err := s.readKernelHeadersFromBody(r, remoteAddr)
175172
if err != nil {
176-
s.error(http.StatusBadRequest, remoteAddr, w, err)
173+
s.replyError(http.StatusBadRequest, remoteAddr, w, err)
177174
return
178175
}
179176

180177
// Generate cache key
181178
cacheKey := utils.GenerateCacheKey(kernelVersion, headersData)
182179
s.logger.Debug("Generated cache key", "remote_addr", remoteAddr, "cache_key", cacheKey)
183180

184-
//check cache
181+
// check cache
185182
if cachePath := s.buildService.GetCached(cacheKey, kernelVersion, remoteAddr); cachePath != nil {
186183
s.logger.Debug("Serving cached module file", "remote_addr", remoteAddr)
187184
s.replyFile(*cachePath, &kernelVersion, w, r)
@@ -191,7 +188,7 @@ func (s *BuildServer) buildModuleHandler() http.HandlerFunc {
191188

192189
// Check if build is in progress
193190
s.logger.Debug("Checking for existing job", "remote_addr", remoteAddr, "cache_key", cacheKey[:16])
194-
//TODO check why active?
191+
// TODO check why active?
195192
info, activeJobsCount := s.buildService.JobInfo(cacheKey)
196193
s.logger.Debug("Total active jobsRepo", "remote_addr", remoteAddr, "count", activeJobsCount)
197194

@@ -226,23 +223,21 @@ func (s *BuildServer) buildModuleHandler() http.HandlerFunc {
226223
return
227224
case model.StatusCompleted:
228225
s.logger.Debug("Job completed, checking cache file", "remote_addr", remoteAddr, "cache_path", info.CachePath)
229-
buildError := ""
230226
if info.CachePath != "" {
231227
if statInfo, err := os.Stat(info.CachePath); err == nil {
232228
s.logger.Info("Serving completed build", "remote_addr", remoteAddr, "kernel_version", kernelVersion, "completed_at", info.CompletedAt, "size_bytes", statInfo.Size())
233229
s.replyOk(w, &model.BuildResponse{
234230
Status: info.Status,
235231
JobID: info.Key,
236-
DownloadURL: s.makeDownloadUrl(info.Key),
232+
DownloadURL: s.makeDownloadURL(info.Key),
237233
},
238234
)
239235
s.logger.Debug("Successfully sent completed build to client", "remote_addr", remoteAddr)
240236
return
241237
}
242-
buildError = "Cache file for completed job not found"
238+
s.logger.Error("Cache file for completed job not found", "remote_addr", remoteAddr, "error", err)
243239
}
244-
buildError = "Cache path blank or empty"
245-
s.logger.Error(buildError, "remote_addr", remoteAddr, "error", err)
240+
s.logger.Error("Cache path blank or empty", "remote_addr", remoteAddr, "error", err)
246241
s.buildService.CreateJob(cacheKey, kernelVersion, headersData, remoteAddr)
247242
s.logger.Debug("Returning job ID to client with status 202 Accepted", "remote_addr", remoteAddr, "job_id", cacheKey[:16])
248243
s.replyAccepted(w, &model.BuildResponse{
@@ -265,7 +260,7 @@ func (s *BuildServer) getStatusHandler() http.HandlerFunc {
265260

266261
if job.Status == model.StatusNotExist {
267262
s.logger.Debug("Job not found", "remote_addr", remoteAddr, "job_id", jobID)
268-
s.errorf(http.StatusNotFound, remoteAddr, w, "Job not found: %s", jobID)
263+
s.replyErrorFormated(http.StatusNotFound, remoteAddr, w, "Job not found: %s", jobID)
269264
return
270265
}
271266

@@ -295,7 +290,7 @@ func (s *BuildServer) getStatusHandler() http.HandlerFunc {
295290
w.Header().Set("Content-Type", "application/json")
296291
switch job.Status {
297292
case model.StatusCompleted:
298-
url := s.makeDownloadUrl(jobID)
293+
url := s.makeDownloadURL(jobID)
299294
rs.DownloadURL = url
300295
s.logger.Debug("Job completed", "remote_addr", remoteAddr, "download_url", url)
301296
w.WriteHeader(http.StatusOK)
@@ -312,7 +307,7 @@ func (s *BuildServer) getStatusHandler() http.HandlerFunc {
312307
}
313308
}
314309

315-
func (s *BuildServer) makeDownloadUrl(jobID string) string {
310+
func (s *BuildServer) makeDownloadURL(jobID string) string {
316311
return fmt.Sprintf("/api/v1/download/%s", jobID)
317312
}
318313

@@ -327,28 +322,28 @@ func (s *BuildServer) downloadModule() http.HandlerFunc {
327322

328323
if job.Status == model.StatusNotExist {
329324
s.logger.Debug("Job not found", "remote_addr", remoteAddr, "job_id", jobID)
330-
s.errorf(http.StatusNotFound, remoteAddr, w, "Job not found: %s", jobID)
325+
s.replyErrorFormated(http.StatusNotFound, remoteAddr, w, "Job not found: %s", jobID)
331326
return
332327
}
333328

334329
s.logger.Debug("Job status", "remote_addr", remoteAddr, "status", job.Status, "cache_path", job.CachePath)
335330

336331
if job.Status != model.StatusCompleted {
337332
s.logger.Debug("Job not completed", "remote_addr", remoteAddr, "status", job.Status)
338-
s.errorf(http.StatusBadRequest, remoteAddr, w, "Job is not completed yet. Status: %s", job.Status)
333+
s.replyErrorFormated(http.StatusBadRequest, remoteAddr, w, "Job is not completed yet. Status: %s", job.Status)
339334
return
340335
}
341336

342337
if job.CachePath == "" {
343338
s.logger.Debug("Cache path not set for completed job", "remote_addr", remoteAddr)
344-
s.errorf(http.StatusInternalServerError, remoteAddr, w, "Cache path not set for completed job")
339+
s.replyErrorFormated(http.StatusInternalServerError, remoteAddr, w, "Cache path not set for completed job")
345340
return
346341
}
347342

348343
cacheInfo, err := os.Stat(job.CachePath)
349344
if os.IsNotExist(err) {
350345
s.logger.Debug("Cache file not found", "remote_addr", remoteAddr, "cache_path", job.CachePath)
351-
s.errorf(http.StatusNotFound, remoteAddr, w, "Cache file not found: %s", job.CachePath)
346+
s.replyErrorFormated(http.StatusNotFound, remoteAddr, w, "Cache file not found: %s", job.CachePath)
352347
return
353348
}
354349

images/drbd-build-server/pkg/service/service.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ func (s *BuildService) GetJob(id string) JobInfo {
145145
}
146146

147147
func (s *BuildService) CreateJob(cacheKey string, kernelVersion string, headersData []byte, remoteAddr string) {
148-
149148
cachePath := s.createCachePath(cacheKey)
150-
151149
job := &BuildJob{
152150
JobInfo: JobInfo{
153151
Key: cacheKey,

0 commit comments

Comments
 (0)