From fa21349f472b23dcd9c1f68be60057b5d5c9b5ea Mon Sep 17 00:00:00 2001 From: Artem Chernyshev Date: Tue, 11 Jun 2024 21:52:55 +0300 Subject: [PATCH] fix: properly generate maintenance config patches Accidentally hardcoded `8090` there :facepalm: Fixes: https://github.com/siderolabs/omni/issues/310 Signed-off-by: Artem Chernyshev --- .../omni/data/maintenance-config-patch.yaml | 2 +- .../controllers/omni/maintenance_config_patch.go | 12 +++++++----- .../omni/maintenance_config_patch_test.go | 4 ++-- .../backend/runtime/omni/migration/migration_test.go | 2 +- .../backend/runtime/omni/migration/migrations.go | 5 +++-- internal/backend/runtime/omni/omni.go | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/internal/backend/runtime/omni/controllers/omni/data/maintenance-config-patch.yaml b/internal/backend/runtime/omni/controllers/omni/data/maintenance-config-patch.yaml index 97449bc64..43826f292 100644 --- a/internal/backend/runtime/omni/controllers/omni/data/maintenance-config-patch.yaml +++ b/internal/backend/runtime/omni/controllers/omni/data/maintenance-config-patch.yaml @@ -4,7 +4,7 @@ apiUrl: {{ .APIURL }} --- apiVersion: v1alpha1 kind: EventSinkConfig -endpoint: '[fdae:41e4:649b:9303::1]:8090' +endpoint: '[fdae:41e4:649b:9303::1]:{{ .EventSinkPort }}' --- apiVersion: v1alpha1 kind: KmsgLogConfig diff --git a/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch.go b/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch.go index 925b67262..96ec098dd 100644 --- a/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch.go +++ b/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch.go @@ -35,7 +35,7 @@ const MaintenanceConfigPatchPrefix = "950-maintenance-config-" type MaintenanceConfigPatchController = qtransform.QController[*omni.MachineStatus, *omni.ConfigPatch] // NewMaintenanceConfigPatchController initializes MaintenanceConfigPatchController. -func NewMaintenanceConfigPatchController() *MaintenanceConfigPatchController { +func NewMaintenanceConfigPatchController(eventSinkPort int) *MaintenanceConfigPatchController { return qtransform.NewQController( qtransform.Settings[*omni.MachineStatus, *omni.ConfigPatch]{ Name: "MaintenanceConfigPatchController", @@ -62,7 +62,7 @@ func NewMaintenanceConfigPatchController() *MaintenanceConfigPatchController { return err } - return UpdateMaintenanceConfigPatch(configPatch, machineStatus, connectionParams) + return UpdateMaintenanceConfigPatch(configPatch, machineStatus, connectionParams, eventSinkPort) }, }, qtransform.WithExtraMappedInput( @@ -74,7 +74,7 @@ func NewMaintenanceConfigPatchController() *MaintenanceConfigPatchController { } // UpdateMaintenanceConfigPatch generates the siderolink connection config patch from the machine status and connection params. -func UpdateMaintenanceConfigPatch(configPatch *omni.ConfigPatch, machineStatus *omni.MachineStatus, connectionParams *siderolink.ConnectionParams) error { +func UpdateMaintenanceConfigPatch(configPatch *omni.ConfigPatch, machineStatus *omni.MachineStatus, connectionParams *siderolink.ConnectionParams, eventSinkPort int) error { configPatch.Metadata().Labels().Set(omni.LabelSystemPatch, "") configPatch.Metadata().Labels().Set(omni.LabelMachine, machineStatus.Metadata().ID()) @@ -91,9 +91,11 @@ func UpdateMaintenanceConfigPatch(configPatch *omni.ConfigPatch, machineStatus * var buffer bytes.Buffer if err = template.Execute(&buffer, struct { - APIURL string + APIURL string + EventSinkPort int }{ - APIURL: url, + APIURL: url, + EventSinkPort: eventSinkPort, }); err != nil { return err } diff --git a/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch_test.go b/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch_test.go index 9a412b3b9..e4e4032cc 100644 --- a/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch_test.go +++ b/internal/backend/runtime/omni/controllers/omni/maintenance_config_patch_test.go @@ -32,7 +32,7 @@ func (suite *MaintenanceConfigPatchSuite) TestReconcile() { ctx, cancel := context.WithTimeout(suite.ctx, time.Second*5) defer cancel() - suite.Require().NoError(suite.runtime.RegisterQController(omnictrl.NewMaintenanceConfigPatchController())) + suite.Require().NoError(suite.runtime.RegisterQController(omnictrl.NewMaintenanceConfigPatchController(9999))) machineID := "test-machine" @@ -55,7 +55,7 @@ apiUrl: grpc://127.0.0.1:8080?grpc_tunnel=false&jointoken=tttt --- apiVersion: v1alpha1 kind: EventSinkConfig -endpoint: '[fdae:41e4:649b:9303::1]:8090' +endpoint: '[fdae:41e4:649b:9303::1]:9999' --- apiVersion: v1alpha1 kind: KmsgLogConfig diff --git a/internal/backend/runtime/omni/migration/migration_test.go b/internal/backend/runtime/omni/migration/migration_test.go index 3f6da8ebf..8a2310ff3 100644 --- a/internal/backend/runtime/omni/migration/migration_test.go +++ b/internal/backend/runtime/omni/migration/migration_test.go @@ -1449,7 +1449,7 @@ func (suite *MigrationSuite) TestGenerateAllMaintenanceConfigs() { runtime, err := runtime.NewRuntime(suite.state, suite.logger) suite.Require().NoError(err) - suite.Require().NoError(runtime.RegisterQController(omnictrl.NewMaintenanceConfigPatchController())) + suite.Require().NoError(runtime.RegisterQController(omnictrl.NewMaintenanceConfigPatchController(8090))) suite.Require().NoError(runtime.RegisterQController(omnictrl.NewClusterMachineConfigController(nil))) runCtx, cancel := context.WithTimeout(ctx, time.Second) diff --git a/internal/backend/runtime/omni/migration/migrations.go b/internal/backend/runtime/omni/migration/migrations.go index 18d0dcf25..8836f9015 100644 --- a/internal/backend/runtime/omni/migration/migrations.go +++ b/internal/backend/runtime/omni/migration/migrations.go @@ -31,6 +31,7 @@ import ( omnictrl "github.com/siderolabs/omni/internal/backend/runtime/omni/controllers/omni" "github.com/siderolabs/omni/internal/pkg/auth/role" "github.com/siderolabs/omni/internal/pkg/auth/scope" + "github.com/siderolabs/omni/internal/pkg/config" "github.com/siderolabs/omni/internal/pkg/image" ) @@ -1203,8 +1204,8 @@ func generateAllMaintenanceConfigs(ctx context.Context, st state.State, _ *zap.L configPatch := omni.NewConfigPatch(resources.DefaultNamespace, omnictrl.MaintenanceConfigPatchPrefix+machineStatus.Metadata().ID()) if err = createOrUpdate(ctx, st, configPatch, func(res *omni.ConfigPatch) error { - return omnictrl.UpdateMaintenanceConfigPatch(res, machineStatus, connectionParams) - }, omnictrl.NewMaintenanceConfigPatchController().Name()); err != nil { + return omnictrl.UpdateMaintenanceConfigPatch(res, machineStatus, connectionParams, config.Config.EventSinkPort) + }, omnictrl.NewMaintenanceConfigPatchController(0).Name()); err != nil { return err } diff --git a/internal/backend/runtime/omni/omni.go b/internal/backend/runtime/omni/omni.go index dfcd7299b..395031835 100644 --- a/internal/backend/runtime/omni/omni.go +++ b/internal/backend/runtime/omni/omni.go @@ -213,7 +213,7 @@ func New(talosClientFactory *talos.ClientFactory, dnsService *dns.Service, workl omnictrl.NewMachineExtensionsController(), omnictrl.NewMachineSetStatusController(), omnictrl.NewMachineSetEtcdAuditController(talosClientFactory, time.Minute), - omnictrl.NewMaintenanceConfigPatchController(), + omnictrl.NewMaintenanceConfigPatchController(config.Config.EventSinkPort), omnictrl.NewRedactedClusterMachineConfigController(), omnictrl.NewSchematicConfigurationController(imageFactoryClient), omnictrl.NewSecretsController(storeFactory),