fix: do not probe kernel args in dashboard if not needed
If the dashboard is run without the "Config URL" screen, do not initialize it, and do not probe the kernel args for the code parameter. Refactor the dashboard to do not construct the unused screens at all. Closes siderolabs/talos#7300. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
This commit is contained in:
parent
8c071b5796
commit
196dfb99b0
@ -119,7 +119,13 @@ func NewConfigURLGrid(ctx context.Context, dashboard *Dashboard) *ConfigURLGrid
|
||||
return grid
|
||||
}
|
||||
|
||||
func (widget *ConfigURLGrid) readTemplateFromKernelArgs() string {
|
||||
func (widget *ConfigURLGrid) readTemplateFromKernelArgs() (val string) {
|
||||
defer func() { // catch potential panic from procfs.ProcCmdline()
|
||||
if r := recover(); r != nil {
|
||||
val = "error reading kernel args"
|
||||
}
|
||||
}()
|
||||
|
||||
option := procfs.ProcCmdline().Get(constants.KernelParamConfig).First()
|
||||
if option == nil {
|
||||
return unset
|
||||
|
@ -114,11 +114,6 @@ type Dashboard struct {
|
||||
|
||||
pages *tview.Pages
|
||||
|
||||
summaryGrid *SummaryGrid
|
||||
monitorGrid *MonitorGrid
|
||||
networkConfigGrid *NetworkConfigGrid
|
||||
configURLGrid *ConfigURLGrid
|
||||
|
||||
selectedScreenConfig *screenConfig
|
||||
screenConfigs []screenConfig
|
||||
footer *components.Footer
|
||||
@ -157,12 +152,7 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D
|
||||
header := components.NewHeader()
|
||||
dashboard.mainGrid.AddItem(header, 0, 0, 1, 1, 0, 0, false)
|
||||
|
||||
dashboard.summaryGrid = NewSummaryGrid(dashboard.app)
|
||||
dashboard.monitorGrid = NewMonitorGrid(dashboard.app)
|
||||
dashboard.networkConfigGrid = NewNetworkConfigGrid(ctx, dashboard)
|
||||
dashboard.configURLGrid = NewConfigURLGrid(ctx, dashboard)
|
||||
|
||||
err := dashboard.initScreenConfigs(defOptions.screens)
|
||||
err := dashboard.initScreenConfigs(ctx, defOptions.screens)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -208,26 +198,16 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D
|
||||
|
||||
dashboard.apiDataListeners = []APIDataListener{
|
||||
header,
|
||||
dashboard.summaryGrid,
|
||||
dashboard.monitorGrid,
|
||||
}
|
||||
|
||||
dashboard.resourceDataListeners = []ResourceDataListener{
|
||||
header,
|
||||
dashboard.summaryGrid,
|
||||
dashboard.networkConfigGrid,
|
||||
dashboard.configURLGrid,
|
||||
}
|
||||
|
||||
dashboard.logDataListeners = []LogDataListener{
|
||||
dashboard.summaryGrid,
|
||||
}
|
||||
dashboard.logDataListeners = []LogDataListener{}
|
||||
|
||||
dashboard.nodeSelectListeners = []NodeSelectListener{
|
||||
header,
|
||||
dashboard.summaryGrid,
|
||||
dashboard.networkConfigGrid,
|
||||
dashboard.configURLGrid,
|
||||
dashboard.footer,
|
||||
}
|
||||
|
||||
@ -235,6 +215,35 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D
|
||||
dashboard.footer,
|
||||
}
|
||||
|
||||
for _, config := range dashboard.screenConfigs {
|
||||
screenPrimitive := config.primitive
|
||||
|
||||
apiDataListener, ok := screenPrimitive.(APIDataListener)
|
||||
if ok {
|
||||
dashboard.apiDataListeners = append(dashboard.apiDataListeners, apiDataListener)
|
||||
}
|
||||
|
||||
resourceDataListener, ok := screenPrimitive.(ResourceDataListener)
|
||||
if ok {
|
||||
dashboard.resourceDataListeners = append(dashboard.resourceDataListeners, resourceDataListener)
|
||||
}
|
||||
|
||||
logDataListener, ok := screenPrimitive.(LogDataListener)
|
||||
if ok {
|
||||
dashboard.logDataListeners = append(dashboard.logDataListeners, logDataListener)
|
||||
}
|
||||
|
||||
nodeSelectListener, ok := screenPrimitive.(NodeSelectListener)
|
||||
if ok {
|
||||
dashboard.nodeSelectListeners = append(dashboard.nodeSelectListeners, nodeSelectListener)
|
||||
}
|
||||
|
||||
nodeSetListener, ok := screenPrimitive.(NodeSetListener)
|
||||
if ok {
|
||||
dashboard.nodeSetChangeListeners = append(dashboard.nodeSetChangeListeners, nodeSetListener)
|
||||
}
|
||||
}
|
||||
|
||||
dashboard.apiDataSource = &apidata.Source{
|
||||
Client: cli,
|
||||
Interval: defOptions.interval,
|
||||
@ -249,17 +258,17 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D
|
||||
return dashboard, nil
|
||||
}
|
||||
|
||||
func (d *Dashboard) initScreenConfigs(screens []Screen) error {
|
||||
func (d *Dashboard) initScreenConfigs(ctx context.Context, screens []Screen) error {
|
||||
primitiveForScreen := func(screen Screen) screenSelectListener {
|
||||
switch screen {
|
||||
case ScreenSummary:
|
||||
return d.summaryGrid
|
||||
return NewSummaryGrid(d.app)
|
||||
case ScreenMonitor:
|
||||
return d.monitorGrid
|
||||
return NewMonitorGrid(d.app)
|
||||
case ScreenNetworkConfig:
|
||||
return d.networkConfigGrid
|
||||
return NewNetworkConfigGrid(ctx, d)
|
||||
case ScreenConfigURL:
|
||||
return d.configURLGrid
|
||||
return NewConfigURLGrid(ctx, d)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user