fixes for jumpstarter integration#90
Conversation
📝 WalkthroughWalkthroughAdds an operator-config API and client, exposes Jumpstarter target mappings via /v1/config, validates requested Jumpstarter flash targets in CLI flows, and updates controller/reconciler to use an APIReader and adjust registry-route handling. Changes
Sequence DiagramsequenceDiagram
participant CLI as CLI (cmd/caib)
participant Client as API Client (buildapi/client)
participant Server as API Server (buildapi/server)
participant K8s as Kubernetes API
CLI->>Client: GetOperatorConfig(ctx)
Client->>Server: GET /v1/config (auth)
Server->>K8s: Read OperatorConfig "config" in namespace
K8s-->>Server: OperatorConfig (or NotFound)
Server->>Server: Build OperatorConfigResponse{JumpstarterTargets}
Server-->>Client: 200 OperatorConfigResponse
Client-->>CLI: Decoded JumpstarterTargets
CLI->>CLI: validateFlashTargetMapping(target)
alt target present
CLI->>CLI: proceed with flash flow
else target missing
CLI->>CLI: error with available targets
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@cmd/caib/main.go`:
- Around line 1291-1308: Extract the Jumpstarter target validation into a shared
helper function e.g. validateFlashTargetMapping(ctx, api, target) that calls
api.GetOperatorConfig(ctx), checks config.JumpstarterTargets is non-empty,
verifies the given target exists, and constructs the same availableTargets slice
before calling handleError with the existing error messages; then replace the
inline validation in runBuildDev with a call to validateFlashTargetMapping and
add calls to validateFlashTargetMapping at the flash-after-build branches in
runBuild and runDisk so all three paths (runBuild, runDisk, runBuildDev) perform
the same early validation using api.GetOperatorConfig and
config.JumpstarterTargets.
In `@internal/buildapi/client/client.go`:
- Line 402: The Authorization header is being set unconditionally
(req.Header.Set("Authorization", "Bearer "+c.authToken)) which can send an empty
token; wrap that call in the same guard used elsewhere (if c.authToken != "") so
the header is only added when a token exists—locate the unconditional
req.Header.Set call in client.go and change it to set the header only inside if
c.authToken != "" to match GetBuild/ListBuilds/CreateFlash patterns.
🧹 Nitpick comments (2)
cmd/caib/main.go (1)
1293-1293: Variableconfigshadows the importedconfigpackage.Line 1293 declares
config, err := api.GetOperatorConfig(ctx)which shadows theconfigpackage imported at Line 33. Rename tooperatorCfgoropConfigto avoid confusion.Suggested fix
- config, err := api.GetOperatorConfig(ctx) + operatorCfg, err := api.GetOperatorConfig(ctx)And update the references on lines 1298, 1302, 1303, 1304 accordingly.
internal/buildapi/server.go (1)
2408-2412: Consider distinguishing NotFound from other errors when fetching OperatorConfig.If the
OperatorConfigCR doesn't exist (common in fresh installations), this returns HTTP 500. A more helpful response would be to return 200 with an emptyJumpstarterTargets(or 404), so the CLI can produce a clearer "no Jumpstarter target mappings configured" error rather than "failed to get operator configuration."Suggested differentiation
if err != nil { + if k8serrors.IsNotFound(err) { + // No OperatorConfig exists - return empty config + c.JSON(http.StatusOK, OperatorConfigResponse{}) + return + } a.log.Error(err, "failed to get OperatorConfig", "reqID", reqID, "namespace", namespace) c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get operator configuration"}) return }
edbdf68 to
2b2e801
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@internal/buildapi/server.go`:
- Around line 2386-2425: In handleGetOperatorConfig, k8sClient.Get currently
treats a NotFound as a 500; change the error handling after k8sClient.Get to
detect a NotFound (using k8serrors.IsNotFound(err) / apierrors.IsNotFound) and
return an empty OperatorConfigResponse with HTTP 200 (or HTTP 404 if you prefer)
instead of an InternalServerError; update the error branch that logs "failed to
get OperatorConfig" to only log and return 500 for non-NotFound errors, and for
the NotFound case log at Info/Debug and respond with an empty response so
validateFlashTargetMapping can surface "no Jumpstarter target mappings
configured".
🧹 Nitpick comments (1)
cmd/caib/main.go (1)
718-742: Variableconfigshadows the importedconfigpackage.On line 720,
configshadows theconfigpackage imported at line 33 ("github.com/centos-automotive-suite/automotive-dev-operator/cmd/caib/config"). While it doesn't cause a bug here since the package isn't used within this function, it's a readability concern and could lead to subtle issues if the function is later extended.Suggested rename
-func validateFlashTargetMapping(ctx context.Context, api *buildapiclient.Client, target string) { - config, err := api.GetOperatorConfig(ctx) +func validateFlashTargetMapping(ctx context.Context, api *buildapiclient.Client, target string) { + operatorCfg, err := api.GetOperatorConfig(ctx) if err != nil { handleError(fmt.Errorf("failed to get operator configuration for Jumpstarter validation: %w", err)) } - if len(config.JumpstarterTargets) == 0 { + if len(operatorCfg.JumpstarterTargets) == 0 { handleError(fmt.Errorf("flash enabled but no Jumpstarter target mappings configured in operator")) } - if _, exists := config.JumpstarterTargets[target]; !exists { - availableTargets := make([]string, 0, len(config.JumpstarterTargets)) - for t := range config.JumpstarterTargets { + if _, exists := operatorCfg.JumpstarterTargets[target]; !exists { + availableTargets := make([]string, 0, len(operatorCfg.JumpstarterTargets)) + for t := range operatorCfg.JumpstarterTargets { availableTargets = append(availableTargets, t) }
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
2b2e801 to
971d1a3
Compare
and fail if we do not have an accessible router url Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Summary by CodeRabbit
New Features
Behavior
Tests