MCPcopy Create free account
hub / github.com/cloudbase/garm / GetControllerInfo

Method GetControllerInfo

runner/runner.go:319–360  ·  view source on GitHub ↗

GetControllerInfo returns the controller id and the hostname. This data might be used in metrics and logging.

(ctx context.Context)

Source from the content-addressed store, hash-verified

317// GetControllerInfo returns the controller id and the hostname.
318// This data might be used in metrics and logging.
319func (r *Runner) GetControllerInfo(ctx context.Context) (params.ControllerInfo, error) {
320 if !auth.IsAdmin(ctx) {
321 return params.ControllerInfo{}, runnerErrors.ErrUnauthorized
322 }
323 // It is unlikely that fetching the hostname will encounter an error on a standard
324 // linux (or Windows) system, but if os.Hostname() can fail, we need to at least retry
325 // a few times before giving up.
326 // This retries 10 times within one second. While it has the potential to give us a
327 // one second delay before returning either the hostname or an error, I expect this
328 // to succeed on the first try.
329 // As a side note, Windows requires a reboot for the hostname change to take effect,
330 // so if we'll ever support Windows as a target system, the hostname can be cached.
331 var hostname string
332 var err error
333 for range 10 {
334 hostname, err = os.Hostname()
335 if err != nil {
336 select {
337 case <-time.After(10 * time.Millisecond):
338 continue
339 case <-ctx.Done():
340 }
341 return params.ControllerInfo{}, fmt.Errorf("error fetching hostname: %w", err)
342 }
343 break
344 }
345 if err != nil {
346 return params.ControllerInfo{}, fmt.Errorf("error fetching hostname: %w", err)
347 }
348
349 info, err := r.store.ControllerInfo()
350 if err != nil {
351 return params.ControllerInfo{}, fmt.Errorf("error fetching controller info: %w", err)
352 }
353
354 // This is temporary. Right now, GARM is a single-instance deployment. When we add the
355 // ability to scale out, the hostname field will be moved form here to a dedicated node
356 // object. As a single controller will be made up of multiple nodes, we will need to model
357 // that aspect of GARM.
358 info.Hostname = hostname
359 return info, nil
360}
361
362func (r *Runner) ListProviders(ctx context.Context) ([]params.Provider, error) {
363 if !auth.IsAdmin(ctx) {

Callers

nothing calls this directly

Calls 3

IsAdminFunction · 0.92
ControllerInfoMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected