getUpstreamToolsForGaps returns upstream cached tools for os/arch combinations not already covered by object store tools. If osType and osArch are non-nil, only the matching platform is considered (instance-scoped). If nil, all platforms are considered (admin-scoped).
(objectStoreTools []params.GARMAgentTool, osType *commonParams.OSType, osArch *commonParams.OSArch)
| 179 | // only the matching platform is considered (instance-scoped). If nil, all |
| 180 | // platforms are considered (admin-scoped). |
| 181 | func getUpstreamToolsForGaps(objectStoreTools []params.GARMAgentTool, osType *commonParams.OSType, osArch *commonParams.OSArch) []params.GARMAgentTool { |
| 182 | ctrlInfo := cache.ControllerInfo() |
| 183 | |
| 184 | // Check staleness - don't use cached data older than 24 hours |
| 185 | if ctrlInfo.CachedGARMAgentReleaseFetchedAt == nil { |
| 186 | return nil |
| 187 | } |
| 188 | if time.Since(*ctrlInfo.CachedGARMAgentReleaseFetchedAt) > 24*time.Hour { |
| 189 | return nil |
| 190 | } |
| 191 | if ctrlInfo.CachedGARMAgentTools == nil { |
| 192 | return nil |
| 193 | } |
| 194 | |
| 195 | // Build set of os_type/os_arch keys already covered by object store tools |
| 196 | covered := make(map[string]bool, len(objectStoreTools)) |
| 197 | for _, tool := range objectStoreTools { |
| 198 | covered[string(tool.OSType)+"/"+string(tool.OSArch)] = true |
| 199 | } |
| 200 | |
| 201 | var result []params.GARMAgentTool |
| 202 | for key, tool := range ctrlInfo.CachedGARMAgentTools { |
| 203 | if covered[key] { |
| 204 | continue |
| 205 | } |
| 206 | // For instance-scoped calls, only include matching os/arch |
| 207 | if osType != nil && osArch != nil { |
| 208 | if tool.OSType != *osType || tool.OSArch != *osArch { |
| 209 | continue |
| 210 | } |
| 211 | } |
| 212 | tool.Source = params.ToolSourceUpstream |
| 213 | result = append(result, tool) |
| 214 | } |
| 215 | return result |
| 216 | } |
| 217 | |
| 218 | // getInstanceAgentTool retrieves the GARM agent tool for the given instance. |
| 219 | // It first checks the local object store, then falls back to upstream cached tools. |
no test coverage detected