Skip to content

Conversation

@mxschmitt
Copy link
Owner

@mxschmitt mxschmitt commented Jan 29, 2026

Summary

This PR addresses several Go code quality issues identified during a code review:

Deprecated APIs & Unmaintained Packages

  • Replace io/ioutil with io (deprecated since Go 1.16)
  • Remove math/rand.Seed (auto-seeded since Go 1.20)
  • Use crypto/rand for secure random string generation
  • Migrate from streadway/amqp to rabbitmq/amqp091-go (official fork)
  • Replace k8s.io/utils/pointer with k8s.io/utils/ptr
  • Fix AMQP heartbeat parameter format (heartbeat=5 not heartbeat=5s)

Resource Leaks

  • Extract file processing to helper functions so defer executes properly (defer in loop doesn't close until function returns)
  • Store and close AMQP connection on server shutdown

Context Propagation

  • Use c.Request().Context() instead of context.Background() in HTTP handlers
  • Ensures proper cancellation when clients disconnect

Concurrency Improvements

  • Replace manual mutex + map pattern with sync.Map for worker reply channels
  • Add defensive nil check in Subscribe() method

Code Quality & Modernization

  • Use slices.Contains for membership checks (file-service MIME types, workertypes.IsValid, worker-java forbidden lines)
  • Fix typo: WorkerExectionOptionsWorkerExecutionOptions
  • Fix typos in log messages: "could n ot" → "could not", "recursivelyt" → "recursively"

CI Improvements

  • Add debug step on failure with pod status, logs, and descriptions
  • Add timeout to health check wait
  • Restore explicit jsonpath filter for frontend port

Test plan

  • Build passes: go build ./...
  • Verify control-service starts and handles requests
  • Verify file-service handles uploads correctly
  • Verify workers can execute code and return results

🤖 Generated with Claude Code

mxschmitt and others added 12 commits January 29, 2026 14:14
- Replace io/ioutil with io (deprecated since Go 1.16)
- Remove math/rand.Seed (auto-seeded since Go 1.20)
- Use crypto/rand for secure random string generation
- Migrate from streadway/amqp to rabbitmq/amqp091-go (official fork)
- Replace k8s.io/utils/pointer with k8s.io/utils/ptr

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract file processing to helper functions so defer executes properly
  in file-service and worker packages
- Store and close AMQP connection on server shutdown in control-service

The defer statement inside a loop doesn't close resources until the
function returns, potentially exhausting file descriptors when processing
many files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use c.Request().Context() in HTTP handlers to properly propagate
cancellation signals. This ensures that when a client disconnects,
the server stops processing the request instead of continuing to
make etcd calls unnecessarily.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace manual mutex + map pattern with sync.Map for storing worker
reply channels. sync.Map is optimized for the concurrent access pattern
used here: many reads with relatively few writes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix typo in exported struct name (missing 'u' in Execution).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- "could n ot" -> "could not"
- "recursivelyt" -> "recursively"

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add defensive check to avoid panic if reply channel is not found
in sync.Map (shouldn't happen in normal flow, but prevents crash).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add 2 minute timeout to wait-on health check
- Add debug step that runs on failure to collect:
  - Pod status
  - Control service logs
  - Pod descriptions
  - RabbitMQ and etcd logs
  - Service status
  - Direct health endpoint check from within cluster

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Decrease timeout from 10 minutes to 3 minutes for waiting on worker pods to be ready in CI workflow.
- Use deploy/control instead of label selectors
- Add --previous flag to get logs from crashed container
- Fix label selector to io.kompose.service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The new library expects heartbeat as integer seconds (heartbeat=5),
not duration string (heartbeat=5s).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mxschmitt mxschmitt force-pushed the fix/go-code-improvements branch from 2684c2b to 9b94909 Compare January 29, 2026 22:14
mxschmitt and others added 2 commits January 29, 2026 14:17
Replace verbose chain of != comparisons with slices.Contains
for cleaner, more maintainable code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- workertypes.IsValid(): replace manual loop with slices.Contains
- worker-java transformOutput(): simplify forbidden line filtering

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mxschmitt mxschmitt force-pushed the fix/go-code-improvements branch from d59898b to 0da0d76 Compare January 29, 2026 22:59
@mxschmitt mxschmitt merged commit 10d5c8c into main Jan 29, 2026
19 checks passed
@mxschmitt mxschmitt deleted the fix/go-code-improvements branch January 29, 2026 22:59
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.

2 participants