Skip to content

Replace string matching with JSON parsing in isRemoteWorkload #2941

@jhrozek

Description

@jhrozek

Summary

The isRemoteWorkload function in pkg/workloads/statuses/file_status.go uses string matching instead of proper JSON parsing to detect if a workload is remote.

Current Behavior

// Check if the JSON contains "remote_url" field
return strings.Contains(string(data), `"remote_url"`), nil

This approach could incorrectly identify non-remote workloads as remote if the JSON happens to contain "remote_url" as part of a string value (not a field name).

Example of false positive:

{"description": "Set \"remote_url\" in config to enable remote mode"}

Expected Behavior

Use proper JSON parsing to check if the remote_url field is set:

var config struct {
    RemoteURL string `json:"remote_url"`
}
decoder := json.NewDecoder(reader)
if err := decoder.Decode(&config); err != nil {
    return false, err
}
return config.RemoteURL != "", nil

Location

  • File: pkg/workloads/statuses/file_status.go
  • Function: isRemoteWorkload (around line 79-104)

Additional Context

The function already has a TODO comment acknowledging this is a temporary solution:

// TODO: This is a temporary solution to check if a workload is remote
// because of the import cycle between this package and the runconfig package.

The proposed fix would resolve this TODO while also fixing the edge case.

Acceptance Criteria

  • Replace strings.Contains with proper JSON decoding
  • Add unit test for the edge case (JSON containing "remote_url" in a string value)
  • Ensure existing tests still pass

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggoPull requests that update go codegood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions