feat(bladectl)!: add more bladectl commands (#91)

This PR introduces a comprehensive set of new subcommands to bladectl, expanding its capabilities for querying and managing compute blade state. It also includes an internal refactor to simplify interface management across the gRPC API.

* `get`
	* `fan`: Returns current fan speed.
	* `identify`: Indicates whether the identify mode is active.
	* `stealth`: Shows if stealth mode is currently enabled.
	* `status`: Prints a full blade status report.
	* `temperature`: Retrieves current SoC temperature.
	* `critical`: Shows whether critical mode is active.
	* `power`: Reports the current power source (e.g., PoE+ or USB).
* `set`
	* `stealth`: Enables stealth mode.
* `remove`
	* `stealth`: Disables stealth mode.
* `describe`
	* `fan`: Outputs the current fan curve configuration.
* `monitor`: plot some charts about the state of the compute-blade-agent

* **gRPC API refactor**: The gRPC service definitions previously located in `internal/api` have been folded into `internal/agent`. This eliminates redundant interface declarations and ensures that all ComputeBladeAgent implementations are directly compatible with the gRPC API.
This reduces duplication and improves long-term maintainability and clarity of the interface contract.

```bash
bladectl set fan --percent 90 --blade 1 --blade 2
bladectl unset identify --blade 1 --blade 2 --blade 3 --blade 4
bladectl set stealth --blade 1 --blade 2 --blade 3 --blade 4
bladectl get status --blade 1 --blade 2 --blade 3 --blade 4
┌───────┬─────────────┬────────────────────┬───────────────┬──────────────┬──────────┬───────────────┬──────────────┐
│ BLADE │ TEMPERATURE │ FAN SPEED OVERRIDE │ FAN SPEED     │ STEALTH MODE │ IDENTIFY │ CRITICAL MODE │ POWER STATUS │
├───────┼─────────────┼────────────────────┼───────────────┼──────────────┼──────────┼───────────────┼──────────────┤
│ 1     │ 50°C        │ 90%                │ 5825 RPM(90%) │ Active       │ Off      │ Off           │ poe+         │
│ 2     │ 48°C        │ 90%                │ 5825 RPM(90%) │ Active       │ Off      │ Off           │ poe+         │
│ 3     │ 49°C        │ Not set            │ 4643 RPM(56%) │ Active       │ Off      │ Off           │ poe+         │
│ 4     │ 49°C        │ Not set            │ 4774 RPM(58%) │ Active       │ Off      │ Off           │ poe+         │
└───────┴─────────────┴────────────────────┴───────────────┴──────────────┴──────────┴───────────────┴──────────────┘
bladectl rm stealth --blade 1 --blade 2 --blade 3 --blade 4
bladectl rm fan --blade 1 --blade 2 --blade 3 --blade 4
bladectl get status --blade 1 --blade 2 --blade 3 --blade 4
┌───────┬─────────────┬────────────────────┬───────────────┬──────────────┬──────────┬───────────────┬──────────────┐
│ BLADE │ TEMPERATURE │ FAN SPEED OVERRIDE │ FAN SPEED     │ STEALTH MODE │ IDENTIFY │ CRITICAL MODE │ POWER STATUS │
├───────┼─────────────┼────────────────────┼───────────────┼──────────────┼──────────┼───────────────┼──────────────┤
│ 1     │ 51°C        │ Not set            │ 5177 RPM(66%) │ Off          │ Off      │ Off           │ poe+         │
│ 2     │ 49°C        │ Not set            │ 5177 RPM(58%) │ Off          │ Off      │ Off           │ poe+         │
│ 3     │ 50°C        │ Not set            │ 4659 RPM(60%) │ Off          │ Off      │ Off           │ poe+         │
│ 4     │ 48°C        │ Not set            │ 4659 RPM(54%) │ Off          │ Off      │ Off           │ poe+         │
└───────┴─────────────┴────────────────────┴───────────────┴──────────────┴──────────┴───────────────┴──────────────┘
```

when having multiple compute-blades in your bladeconfig:

```yaml
blades:
    - name: 1
      blade:
        server: blade-pi1:8081
        cert:
            certificate-authority-data: <redacted>
            client-certificate-data: <redacted>
            client-key-data: <redacted>
    - name: 2
      blade:
        server: blade-pi2:8081
        cert:
            certificate-authority-data: <redacted>
            client-certificate-data: <redacted>
            client-key-data: <redacted>
    - name: 3
      blade:
        server: blade-pi3:8081
        cert:
            certificate-authority-data: <redacted>
            client-certificate-data: <redacted>
            client-key-data: <redacted>
    - name: 4
      blade:
        server: blade-pi4:8081
        cert:
            certificate-authority-data: <redacted>
            client-certificate-data: <redacted>
            client-key-data: <redacted>
    - name: 4
      blade:
        server: blade-pi4:8081
        cert:
            certificate-authority-data: <redacted>
            client-certificate-data: <redacted>
            client-key-data: <redacted>
current-blade: 1
```

Fixes #4, #9 (partially), should help with #5

* test: improve unit-testing

* fix: pin github.com/warthog618/gpiod

---------

Co-authored-by: Cedric Kienzler <cedric@specht-labs.de>
This commit is contained in:
Cedric Kienzler
2025-06-06 23:03:22 +02:00
committed by Cedric Kienzler
parent 7ec49ce05c
commit 781ded8e43
41 changed files with 1949 additions and 750 deletions

View File

@@ -3,21 +3,17 @@ package agent
import (
"context"
"github.com/compute-blade-community/compute-blade-agent/pkg/events"
bladeapiv1alpha1 "github.com/compute-blade-community/compute-blade-agent/api/bladeapi/v1alpha1"
)
// ComputeBladeAgent implements the core-logic of the agent. It is responsible for handling events and interfacing with the hardware.
// any ComputeBladeAgent must also be a bladeapiv1alpha1.BladeAgentServiceServer to handle the gRPC API requests.
type ComputeBladeAgent interface {
bladeapiv1alpha1.BladeAgentServiceServer
// RunAsync dispatches the agent until the context is canceled or an error occurs
RunAsync(ctx context.Context, cancel context.CancelCauseFunc)
// Run dispatches the agent and blocks until the context is canceled or an error occurs
Run(ctx context.Context) error
// EmitEvent emits an event to the agent
EmitEvent(ctx context.Context, event events.Event) error
// SetFanSpeed sets the fan speed in percent
SetFanSpeed(_ context.Context, speed uint8) error
// SetStealthMode sets the stealth mode
SetStealthMode(_ context.Context, enabled bool) error
// WaitForIdentifyConfirm blocks until the user confirms the identify mode
WaitForIdentifyConfirm(ctx context.Context) error
// GracefulStop gracefully stops the gRPC server, ensuring all in-progress RPCs are completed before shutting down.
GracefulStop(ctx context.Context) error
}

53
pkg/agent/config.go Normal file
View File

@@ -0,0 +1,53 @@
package agent
import (
"github.com/compute-blade-community/compute-blade-agent/pkg/fancontroller"
"github.com/compute-blade-community/compute-blade-agent/pkg/hal"
"github.com/compute-blade-community/compute-blade-agent/pkg/hal/led"
)
type LogConfiguration struct {
Mode string `mapstructure:"mode"`
}
type ApiConfig struct {
Metrics string `mapstructure:"metrics"`
Grpc string `mapstructure:"grpc"`
GrpcAuthenticated bool `mapstructure:"authenticated"`
GrpcListenMode string `mapstructure:"mode"`
}
type ComputeBladeAgentConfig struct {
// Log is the logging configuration
Log LogConfiguration `mapstructure:"log"`
// Listen is the listen configuration for the server
Listen ApiConfig `mapstructure:"listen"`
// Hal is the hardware abstraction layer configuration
Hal hal.Config `mapstructure:"hal"`
// IdleLedColor is the color of the edge LED when the blade is idle mode
IdleLedColor led.Color `mapstructure:"idle_led_color"`
// IdentifyLedColor is the color of the edge LED when the blade is in identify mode
IdentifyLedColor led.Color `mapstructure:"identify_led_color"`
// CriticalLedColor is the color of the top(!) LED when the blade is in critical mode.
// In the circumstance when >1 blades are in critical mode, the identify function can be used to find the right blade
CriticalLedColor led.Color `mapstructure:"critical_led_color"`
// StealthModeEnabled indicates whether stealth mode is enabled
StealthModeEnabled bool `mapstructure:"stealth_mode"`
// Critical temperature of the compute blade (used to trigger critical mode)
CriticalTemperatureThreshold uint `mapstructure:"critical_temperature_threshold"`
// FanSpeed allows to set a fixed fan speed (in percent)
FanSpeed *fancontroller.FanOverrideOpts `mapstructure:"fan_speed"`
// FanControllerConfig is the configuration of the fan controller
FanControllerConfig fancontroller.Config `mapstructure:"fan_controller"`
ComputeBladeHalOpts hal.ComputeBladeHalOpts `mapstructure:"hal"`
}