diff --git a/.drone.jsonnet b/.drone.jsonnet index 2819f8c807a..e0edf078ab6 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -547,7 +547,6 @@ local integration_kubespan = Step('e2e-kubespan', target='e2e-qemu', privileged= WITH_CLUSTER_DISCOVERY: 'true', WITH_KUBESPAN: 'true', IMAGE_REGISTRY: local_registry, - WITH_CONFIG_PATCH: '[{"op": "replace", "path": "/cluster/discovery/registries/kubernetes/disabled", "value": false}]', // use Kubernetes discovery backend }); local integration_default_hostname = Step('e2e-default-hostname', target='e2e-qemu', privileged=true, depends_on=[integration_kubespan], environment={ // regression test: make sure Talos works in maintenance mode when no hostname is set @@ -557,9 +556,10 @@ local integration_default_hostname = Step('e2e-default-hostname', target='e2e-qe DISABLE_DHCP_HOSTNAME: 'true', }); -local integration_qemu_encrypted_vip = Step('e2e-encrypted-vip', target='e2e-qemu', privileged=true, depends_on=[load_artifacts], environment={ +local integration_qemu_encrypted_vip = Step('e2e-encrypted-kubespan-vip', target='e2e-qemu', privileged=true, depends_on=[load_artifacts], environment={ WITH_DISK_ENCRYPTION: 'true', WITH_VIRTUAL_IP: 'true', + WITH_KUBESPAN: 'true', IMAGE_REGISTRY: local_registry, }); diff --git a/internal/app/machined/pkg/controllers/cluster/discovery_service.go b/internal/app/machined/pkg/controllers/cluster/discovery_service.go index 6963af5165f..4870da0a8b8 100644 --- a/internal/app/machined/pkg/controllers/cluster/discovery_service.go +++ b/internal/app/machined/pkg/controllers/cluster/discovery_service.go @@ -68,8 +68,8 @@ func (ctrl *DiscoveryServiceController) Inputs() []controller.Input { }, { Namespace: runtime.NamespaceName, - Type: runtime.MachineStatusType, - ID: optional.Some(runtime.MachineStatusID), + Type: runtime.MachineResetSignalType, + ID: optional.Some(runtime.MachineResetSignalID), Kind: controller.InputWeak, }, } @@ -218,9 +218,9 @@ func (ctrl *DiscoveryServiceController) Run(ctx context.Context, r controller.Ru return fmt.Errorf("error listing endpoints: %w", err) } - machineStatus, err := safe.ReaderGet[*runtime.MachineStatus](ctx, r, resource.NewMetadata(runtime.NamespaceName, runtime.MachineStatusType, runtime.MachineStatusID, resource.VersionUndefined)) + machineResetSginal, err := safe.ReaderGetByID[*runtime.MachineResetSignal](ctx, r, runtime.MachineResetSignalID) if err != nil && !state.IsNotFoundError(err) { - return fmt.Errorf("error getting machine status: %w", err) + return fmt.Errorf("error getting machine reset signal: %w", err) } if client == nil { @@ -257,9 +257,9 @@ func (ctrl *DiscoveryServiceController) Run(ctx context.Context, r controller.Ru // delete/update local affiliate // - // if the node enters resetting stage, cleanup the local affiliate + // if the node enters final resetting stage, cleanup the local affiliate // otherwise, update local affiliate data - if machineStatus != nil && machineStatus.TypedSpec().Stage == runtime.MachineStageResetting { + if machineResetSginal != nil { client.DeleteLocalAffiliate() } else { localData := pbAffiliate(affiliateSpec) diff --git a/internal/app/machined/pkg/controllers/cluster/discovery_service_test.go b/internal/app/machined/pkg/controllers/cluster/discovery_service_test.go index 37f94d2b660..f1307b4d3be 100644 --- a/internal/app/machined/pkg/controllers/cluster/discovery_service_test.go +++ b/internal/app/machined/pkg/controllers/cluster/discovery_service_test.go @@ -242,9 +242,8 @@ func (suite *DiscoveryServiceSuite) TestReconcile() { ) // pretend that machine is being reset - machineStatus := runtime.NewMachineStatus() - machineStatus.TypedSpec().Stage = runtime.MachineStageResetting - suite.Require().NoError(suite.state.Create(suite.ctx, machineStatus)) + machineResetSignal := runtime.NewMachineResetSignal() + suite.Require().NoError(suite.state.Create(suite.ctx, machineResetSignal)) // client should see the affiliate being deleted suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry( diff --git a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go index 77b2c88044d..712f18a9e12 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go @@ -342,6 +342,9 @@ func (*Sequencer) Reset(r runtime.Runtime, in runtime.ResetOptions) []runtime.Ph in.GetGraceful() && (r.Config().Machine().Type() != machine.TypeWorker), "leave", LeaveEtcd, + ).Append( + "preReset", + SendResetSignal, ).AppendList( phaseListErrorHandler(logError, stopAllPhaselist(r, withKexec)...), ).Append( diff --git a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go index d9f4b2ca492..53f2cdca532 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go @@ -2303,6 +2303,13 @@ func StoreShutdownEmergency(runtime.Sequence, any) (runtime.TaskExecutionFunc, s }, "storeShutdownEmergency" } +// SendResetSignal func represents the task to send the final reset signal. +func SendResetSignal(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) { + return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) { + return r.State().V1Alpha2().Resources().Create(ctx, resourceruntime.NewMachineResetSignal()) + }, "sendResetSignal" +} + func pauseOnFailure(callback func(runtime.Sequence, any) (runtime.TaskExecutionFunc, string), timeout time.Duration, ) func(seq runtime.Sequence, data any) (runtime.TaskExecutionFunc, string) { diff --git a/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go b/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go index 3258f4c2f24..4aca522a437 100644 --- a/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go +++ b/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go @@ -179,6 +179,7 @@ func NewState() (*State, error) { &runtime.KmsgLogConfig{}, &runtime.MaintenanceServiceConfig{}, &runtime.MaintenanceServiceRequest{}, + &runtime.MachineResetSignal{}, &runtime.MachineStatus{}, &runtime.MetaKey{}, &runtime.MetaLoaded{}, diff --git a/pkg/machinery/resources/runtime/deep_copy.generated.go b/pkg/machinery/resources/runtime/deep_copy.generated.go index 66724f67ca4..709abb1d65e 100644 --- a/pkg/machinery/resources/runtime/deep_copy.generated.go +++ b/pkg/machinery/resources/runtime/deep_copy.generated.go @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -// Code generated by "deep-copy -type DevicesStatusSpec -type EventSinkConfigSpec -type KernelModuleSpecSpec -type KernelParamSpecSpec -type KernelParamStatusSpec -type KmsgLogConfigSpec -type MaintenanceServiceConfigSpec -type MaintenanceServiceRequestSpec -type MachineStatusSpec -type MetaKeySpec -type MountStatusSpec -type PlatformMetadataSpec -type SecurityStateSpec -type MetaLoadedSpec -type UniqueMachineTokenSpec -header-file ../../../../hack/boilerplate.txt -o deep_copy.generated.go ."; DO NOT EDIT. +// Code generated by "deep-copy -type DevicesStatusSpec -type EventSinkConfigSpec -type KernelModuleSpecSpec -type KernelParamSpecSpec -type KernelParamStatusSpec -type KmsgLogConfigSpec -type MaintenanceServiceConfigSpec -type MaintenanceServiceRequestSpec -type MachineResetSignalSpec -type MachineStatusSpec -type MetaKeySpec -type MountStatusSpec -type PlatformMetadataSpec -type SecurityStateSpec -type MetaLoadedSpec -type UniqueMachineTokenSpec -header-file ../../../../hack/boilerplate.txt -o deep_copy.generated.go ."; DO NOT EDIT. package runtime @@ -81,6 +81,12 @@ func (o MaintenanceServiceRequestSpec) DeepCopy() MaintenanceServiceRequestSpec return cp } +// DeepCopy generates a deep copy of MachineResetSignalSpec. +func (o MachineResetSignalSpec) DeepCopy() MachineResetSignalSpec { + var cp MachineResetSignalSpec = o + return cp +} + // DeepCopy generates a deep copy of MachineStatusSpec. func (o MachineStatusSpec) DeepCopy() MachineStatusSpec { var cp MachineStatusSpec = o diff --git a/pkg/machinery/resources/runtime/machine_reset_signal.go b/pkg/machinery/resources/runtime/machine_reset_signal.go new file mode 100644 index 00000000000..58436a9c520 --- /dev/null +++ b/pkg/machinery/resources/runtime/machine_reset_signal.go @@ -0,0 +1,59 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package runtime + +import ( + "github.com/cosi-project/runtime/pkg/resource" + "github.com/cosi-project/runtime/pkg/resource/meta" + "github.com/cosi-project/runtime/pkg/resource/protobuf" + "github.com/cosi-project/runtime/pkg/resource/typed" + + "github.com/siderolabs/talos/pkg/machinery/proto" +) + +// MachineResetSignalType is type of MachineResetSignal resource. +const MachineResetSignalType = resource.Type("MachineResetSignals.runtime.talos.dev") + +// MachineResetSignalID is singleton MachineResetSignal resource ID. +const MachineResetSignalID = resource.ID("machine") + +// MachineResetSignal resource is created to signal that the machine is going to be reset soon. +// +// This resource is created when all remaining actions are local to the node, and network communication is not required. +type MachineResetSignal = typed.Resource[MachineResetSignalSpec, MachineResetSignalExtension] + +// MachineResetSignalSpec describes the spec of MachineResetSignal. +// +//gotagsrewrite:gen +type MachineResetSignalSpec struct{} + +// NewMachineResetSignal initializes a MachineResetSignal resource. +func NewMachineResetSignal() *MachineResetSignal { + return typed.NewResource[MachineResetSignalSpec, MachineResetSignalExtension]( + resource.NewMetadata(NamespaceName, MachineResetSignalType, MachineResetSignalID, resource.VersionUndefined), + MachineResetSignalSpec{}, + ) +} + +// MachineResetSignalExtension is auxiliary resource data for MachineResetSignal. +type MachineResetSignalExtension struct{} + +// ResourceDefinition implements meta.ResourceDefinitionProvider interface. +func (MachineResetSignalExtension) ResourceDefinition() meta.ResourceDefinitionSpec { + return meta.ResourceDefinitionSpec{ + Type: MachineResetSignalType, + Aliases: []resource.Type{}, + DefaultNamespace: NamespaceName, + } +} + +func init() { + proto.RegisterDefaultTypes() + + err := protobuf.RegisterDynamic[MachineResetSignalSpec](MachineResetSignalType, &MachineResetSignal{}) + if err != nil { + panic(err) + } +} diff --git a/pkg/machinery/resources/runtime/runtime.go b/pkg/machinery/resources/runtime/runtime.go index b92d5e90cbe..49f92ba026d 100644 --- a/pkg/machinery/resources/runtime/runtime.go +++ b/pkg/machinery/resources/runtime/runtime.go @@ -4,4 +4,4 @@ package runtime -//go:generate deep-copy -type DevicesStatusSpec -type EventSinkConfigSpec -type KernelModuleSpecSpec -type KernelParamSpecSpec -type KernelParamStatusSpec -type KmsgLogConfigSpec -type MaintenanceServiceConfigSpec -type MaintenanceServiceRequestSpec -type MachineStatusSpec -type MetaKeySpec -type MountStatusSpec -type PlatformMetadataSpec -type SecurityStateSpec -type MetaLoadedSpec -type UniqueMachineTokenSpec -header-file ../../../../hack/boilerplate.txt -o deep_copy.generated.go . +//go:generate deep-copy -type DevicesStatusSpec -type EventSinkConfigSpec -type KernelModuleSpecSpec -type KernelParamSpecSpec -type KernelParamStatusSpec -type KmsgLogConfigSpec -type MaintenanceServiceConfigSpec -type MaintenanceServiceRequestSpec -type MachineResetSignalSpec -type MachineStatusSpec -type MetaKeySpec -type MountStatusSpec -type PlatformMetadataSpec -type SecurityStateSpec -type MetaLoadedSpec -type UniqueMachineTokenSpec -header-file ../../../../hack/boilerplate.txt -o deep_copy.generated.go . diff --git a/pkg/machinery/resources/runtime/runtime_test.go b/pkg/machinery/resources/runtime/runtime_test.go index 142205775fc..2f007f625e9 100644 --- a/pkg/machinery/resources/runtime/runtime_test.go +++ b/pkg/machinery/resources/runtime/runtime_test.go @@ -33,6 +33,7 @@ func TestRegisterResource(t *testing.T) { &runtime.KernelParamStatus{}, &runtime.KmsgLogConfig{}, &runtime.MachineStatus{}, + &runtime.MachineResetSignal{}, &runtime.MaintenanceServiceConfig{}, &runtime.MaintenanceServiceRequest{}, &runtime.MetaKey{},