8000 🐛 Fix disabled control-plane startup panic by abahmed · Pull Request #507 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions internal/app/monitor_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/abahmed/kwatch/internal/clock"
"github.com/abahmed/kwatch/internal/config"
"github.com/abahmed/kwatch/internal/controller"
"github.com/abahmed/kwatch/internal/controlplane"
"github.com/abahmed/kwatch/internal/delivery"
"github.com/abahmed/kwatch/internal/health"
"github.com/abahmed/kwatch/internal/incident"
Expand Down Expand Up @@ -89,6 +90,9 @@ func composeMonitorComponents(
runtime, clientset, clients.REST, clients.Resolver,
incidentEngine, now,
)
integrationRuntime, controlPlaneStatus := composeIntegrationRuntime(
controlPlaneRuntime, tlsProcessor, tlsConfig, eventRuntime,
)
deploymentRuntime := workload.NewDeploymentRuntimeWithRuntimeConfig(
runtime, incidentEngine, now,
)
Expand Down Expand Up @@ -144,17 +148,11 @@ func composeMonitorComponents(
Cluster: controller.ClusterRuntime{
Processor: clusterRuntime, Config: clusterRuntime,
},
Integration: controller.IntegrationRuntime{
ControlPlane: controlPlaneRuntime,
ControlPlaneConfig: controlPlaneRuntime,
TLS: tlsProcessor,
TLSConfig: tlsConfig,
Events: eventRuntime,
},
Baseline: podRuntime,
Integration: integrationRuntime,
Baseline: podRuntime,
},
controlPlaneRun: controlPlaneRun,
controlPlane: controlPlaneRuntime,
controlPlane: controlPlaneStatus,
tlsProcessor: tlsProcessor,
tlsConfig: tlsConfig,
startupSummary: func(suppressed map[string]int) {
Expand All @@ -169,6 +167,25 @@ func composeMonitorComponents(
}
}

func composeIntegrationRuntime(
controlPlane *controlplane.Monitor,
tlsProcessor controller.TLSProcessor,
tlsConfig controller.TLSConfig,
eventRuntime controller.EventProcessor,
) (controller.IntegrationRuntime, health.StatusProvider) {
integration := controller.IntegrationRuntime{
TLS: tlsProcessor,
TLSConfig: tlsConfig,
Events: eventRuntime,
}
if controlPlane == nil {
return integration, nil
}
integration.ControlPlane = controlPlane
integration.ControlPlaneConfig = controlPlane
return integration, controlPlane
}

func composeTLSRuntime(
runtime config.RuntimeConfig,
incidentEngine *incident.Engine,
Expand Down
14 changes: 14 additions & 0 deletions internal/app/monitors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ func TestNewMonitorRegistryContainsRuntimeModules(t *testing.T) {
}
}
}

func TestComposeIntegrationRuntimeDisablesControlPlane(t *testing.T) {
integration, status := composeIntegrationRuntime(nil, nil, nil, nil)

if integration.ControlPlane != nil {
t.Fatal("disabled control-plane processor should remain nil")
}
if integration.ControlPlaneConfig != nil {
t.Fatal("disabled control-plane configuration should remain nil")
}
if status != nil {
t.Fatal("disabled control-plane status provider should remain nil")
}
}
Loading
0