From 00515b4bae304ab8884a5e06ba2f4c35c5933950 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Thu, 26 May 2022 22:08:44 +0530 Subject: [PATCH] chore: rename memory to memorymodules Rename `memory` to `memorymodules` to be more explicit Signed-off-by: Noel Georgi --- .../machined/pkg/adapters/hardware/memory.go | 54 ------------------- .../pkg/adapters/hardware/memorymodule.go | 54 +++++++++++++++++++ .../pkg/controllers/hardware/system.go | 6 +-- .../pkg/controllers/hardware/system_test.go | 6 +-- .../pkg/runtime/v1alpha2/v1alpha2_state.go | 2 +- .../resources/hardware/deep_copy.generated.go | 4 +- pkg/machinery/resources/hardware/hardware.go | 2 +- .../resources/hardware/hardware_test.go | 2 +- .../hardware/{memory.go => memorymodule.go} | 32 +++++------ 9 files changed, 81 insertions(+), 81 deletions(-) delete mode 100644 internal/app/machined/pkg/adapters/hardware/memory.go create mode 100644 internal/app/machined/pkg/adapters/hardware/memorymodule.go rename pkg/machinery/resources/hardware/{memory.go => memorymodule.go} (58%) diff --git a/internal/app/machined/pkg/adapters/hardware/memory.go b/internal/app/machined/pkg/adapters/hardware/memory.go deleted file mode 100644 index 0c668fc747..0000000000 --- a/internal/app/machined/pkg/adapters/hardware/memory.go +++ /dev/null @@ -1,54 +0,0 @@ -// 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 hardware - -import ( - "github.com/talos-systems/go-smbios/smbios" - - "github.com/talos-systems/talos/pkg/machinery/resources/hardware" -) - -// Memory adapter provider conversion from smbios.SMBIOS. -// -//nolint:revive,golint -func Memory(m *hardware.Memory) memory { - return memory{ - Memory: m, - } -} - -type memory struct { - *hardware.Memory -} - -// Update current processor info. -func (m memory) Update(memory *smbios.MemoryDevice) { - translateProcessorInfo := func(in *smbios.MemoryDevice) hardware.MemorySpec { - var memorySpec hardware.MemorySpec - - if in.Size != 0 && in.Size != 0xFFFF { - var size uint32 - - if in.Size == 0x7FFF { - size = uint32(in.ExtendedSize) - } else { - size = uint32(in.Size) - } - - memorySpec.AssetTag = in.AssetTag - memorySpec.BankLocator = in.BankLocator - memorySpec.DeviceLocator = in.DeviceLocator - memorySpec.Manufacturer = in.Manufacturer - memorySpec.ProductName = in.PartNumber - memorySpec.SerialNumber = in.SerialNumber - memorySpec.Size = size - memorySpec.Speed = uint32(in.Speed) - } - - return memorySpec - } - - *m.Memory.TypedSpec() = translateProcessorInfo(memory) -} diff --git a/internal/app/machined/pkg/adapters/hardware/memorymodule.go b/internal/app/machined/pkg/adapters/hardware/memorymodule.go new file mode 100644 index 0000000000..29f0e7bcc0 --- /dev/null +++ b/internal/app/machined/pkg/adapters/hardware/memorymodule.go @@ -0,0 +1,54 @@ +// 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 hardware + +import ( + "github.com/talos-systems/go-smbios/smbios" + + "github.com/talos-systems/talos/pkg/machinery/resources/hardware" +) + +// MemoryModule adapter provider conversion from smbios.SMBIOS. +// +//nolint:revive,golint +func MemoryModule(m *hardware.MemoryModule) memoryModule { + return memoryModule{ + MemoryModule: m, + } +} + +type memoryModule struct { + *hardware.MemoryModule +} + +// Update current processor info. +func (m memoryModule) Update(memory *smbios.MemoryDevice) { + translateMemoryModuleInfo := func(in *smbios.MemoryDevice) hardware.MemoryModuleSpec { + var memoryModuleSpec hardware.MemoryModuleSpec + + if in.Size != 0 && in.Size != 0xFFFF { + var size uint32 + + if in.Size == 0x7FFF { + size = uint32(in.ExtendedSize) + } else { + size = uint32(in.Size) + } + + memoryModuleSpec.AssetTag = in.AssetTag + memoryModuleSpec.BankLocator = in.BankLocator + memoryModuleSpec.DeviceLocator = in.DeviceLocator + memoryModuleSpec.Manufacturer = in.Manufacturer + memoryModuleSpec.ProductName = in.PartNumber + memoryModuleSpec.SerialNumber = in.SerialNumber + memoryModuleSpec.Size = size + memoryModuleSpec.Speed = uint32(in.Speed) + } + + return memoryModuleSpec + } + + *m.MemoryModule.TypedSpec() = translateMemoryModuleInfo(memory) +} diff --git a/internal/app/machined/pkg/controllers/hardware/system.go b/internal/app/machined/pkg/controllers/hardware/system.go index 81eb5015b2..120f4cd694 100644 --- a/internal/app/machined/pkg/controllers/hardware/system.go +++ b/internal/app/machined/pkg/controllers/hardware/system.go @@ -41,7 +41,7 @@ func (ctrl *SystemInfoController) Outputs() []controller.Output { Kind: controller.OutputExclusive, }, { - Type: hardware.MemoryType, + Type: hardware.MemoryModuleType, Kind: controller.OutputExclusive, }, } @@ -84,8 +84,8 @@ func (ctrl *SystemInfoController) Run(ctx context.Context, r controller.Runtime, // replaces `SIMM 0` with `SIMM-0` id := strings.ReplaceAll(m.DeviceLocator, " ", "-") - if err := r.Modify(ctx, hardware.NewMemoryInfo(id), func(res resource.Resource) error { - hwadapter.Memory(res.(*hardware.Memory)).Update(&m) + if err := r.Modify(ctx, hardware.NewMemoryModuleInfo(id), func(res resource.Resource) error { + hwadapter.MemoryModule(res.(*hardware.MemoryModule)).Update(&m) return nil }); err != nil { diff --git a/internal/app/machined/pkg/controllers/hardware/system_test.go b/internal/app/machined/pkg/controllers/hardware/system_test.go index 279340118c..7d19d48701 100644 --- a/internal/app/machined/pkg/controllers/hardware/system_test.go +++ b/internal/app/machined/pkg/controllers/hardware/system_test.go @@ -70,7 +70,7 @@ func (suite *SystemInfoSuite) TestPopulateSystemInformation() { }, } - memorySpecs := map[string]hardware.MemorySpec{ + memorySpecs := map[string]hardware.MemoryModuleSpec{ "P1-DIMMA1": { Size: 4096, DeviceLocator: "P1-DIMMA1", @@ -111,8 +111,8 @@ func (suite *SystemInfoSuite) TestPopulateSystemInformation() { for k, v := range memorySpecs { suite.Assert().NoError( retry.Constant(1*time.Second, retry.WithUnits(100*time.Millisecond)).Retry( - suite.assertResource(*hardware.NewMemoryInfo(k).Metadata(), func(r resource.Resource) error { - status := *r.(*hardware.Memory).TypedSpec() + suite.assertResource(*hardware.NewMemoryModuleInfo(k).Metadata(), func(r resource.Resource) error { + status := *r.(*hardware.MemoryModule).TypedSpec() if !suite.Assert().Equal(v, status) { return retry.ExpectedError(fmt.Errorf("memory status doesn't match: %v != %v", v, status)) } diff --git a/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go b/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go index 90d5230d1d..ca1d1d0087 100644 --- a/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go +++ b/internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go @@ -90,7 +90,7 @@ func NewState() (*State, error) { &files.EtcFileSpec{}, &files.EtcFileStatus{}, &hardware.Processor{}, - &hardware.Memory{}, + &hardware.MemoryModule{}, &k8s.AdmissionControlConfig{}, &k8s.APIServerConfig{}, &k8s.ConfigStatus{}, diff --git a/pkg/machinery/resources/hardware/deep_copy.generated.go b/pkg/machinery/resources/hardware/deep_copy.generated.go index 01837744ff..954580101c 100644 --- a/pkg/machinery/resources/hardware/deep_copy.generated.go +++ b/pkg/machinery/resources/hardware/deep_copy.generated.go @@ -13,7 +13,7 @@ func (o ProcessorSpec) DeepCopy() ProcessorSpec { } // DeepCopy generates a deep copy of MemorySpec. -func (o MemorySpec) DeepCopy() MemorySpec { - var cp MemorySpec = o +func (o MemoryModuleSpec) DeepCopy() MemoryModuleSpec { + var cp MemoryModuleSpec = o return cp } diff --git a/pkg/machinery/resources/hardware/hardware.go b/pkg/machinery/resources/hardware/hardware.go index 4b9aa5ad52..9d59b8634b 100644 --- a/pkg/machinery/resources/hardware/hardware.go +++ b/pkg/machinery/resources/hardware/hardware.go @@ -8,7 +8,7 @@ import ( "github.com/cosi-project/runtime/pkg/resource" ) -//go:generate deep-copy -type ProcessorSpec -type MemorySpec -header-file ../../../../hack/boilerplate.txt -o deep_copy.generated.go . +//go:generate deep-copy -type ProcessorSpec -type MemoryModuleSpec -header-file ../../../../hack/boilerplate.txt -o deep_copy.generated.go . // NamespaceName contains resources related to hardware as a whole. const NamespaceName resource.Namespace = "hardware" diff --git a/pkg/machinery/resources/hardware/hardware_test.go b/pkg/machinery/resources/hardware/hardware_test.go index 41f41b3c37..2d57a82391 100644 --- a/pkg/machinery/resources/hardware/hardware_test.go +++ b/pkg/machinery/resources/hardware/hardware_test.go @@ -26,7 +26,7 @@ func TestRegisterResource(t *testing.T) { for _, resource := range []resource.Resource{ &hardware.Processor{}, - &hardware.Memory{}, + &hardware.MemoryModule{}, } { assert.NoError(t, resourceRegistry.Register(ctx, resource)) } diff --git a/pkg/machinery/resources/hardware/memory.go b/pkg/machinery/resources/hardware/memorymodule.go similarity index 58% rename from pkg/machinery/resources/hardware/memory.go rename to pkg/machinery/resources/hardware/memorymodule.go index e160ef75e1..e52e985bf0 100644 --- a/pkg/machinery/resources/hardware/memory.go +++ b/pkg/machinery/resources/hardware/memorymodule.go @@ -10,14 +10,14 @@ import ( "github.com/cosi-project/runtime/pkg/resource/typed" ) -// MemoryType is type of Memory resource. -const MemoryType = resource.Type("Memories.hardware.talos.dev") +// MemoryModuleType is type of MemoryModule resource. +const MemoryModuleType = resource.Type("MemoryModules.hardware.talos.dev") -// Memory resource holds node Memory information. -type Memory = typed.Resource[MemorySpec, MemoryRD] +// MemoryModule resource holds node MemoryModule information. +type MemoryModule = typed.Resource[MemoryModuleSpec, MemoryModuleRD] -// MemorySpec represents a single Memory. -type MemorySpec struct { +// MemoryModuleSpec represents a single Memory. +type MemoryModuleSpec struct { Size uint32 `yaml:"sizeMiB,omitempty"` DeviceLocator string `yaml:"deviceLocator,omitempty"` BankLocator string `yaml:"bankLocator,omitempty"` @@ -28,23 +28,23 @@ type MemorySpec struct { ProductName string `yaml:"productName,omitempty"` } -// NewMemoryInfo initializes a MemoryInfo resource. -func NewMemoryInfo(id string) *Memory { - return typed.NewResource[MemorySpec, MemoryRD]( - resource.NewMetadata(NamespaceName, MemoryType, id, resource.VersionUndefined), - MemorySpec{}, +// NewMemoryModuleInfo initializes a MemoryModuleInfo resource. +func NewMemoryModuleInfo(id string) *MemoryModule { + return typed.NewResource[MemoryModuleSpec, MemoryModuleRD]( + resource.NewMetadata(NamespaceName, MemoryModuleType, id, resource.VersionUndefined), + MemoryModuleSpec{}, ) } -// MemoryRD provides auxiliary methods for Memory info. -type MemoryRD struct{} +// MemoryModuleRD provides auxiliary methods for Memory info. +type MemoryModuleRD struct{} // ResourceDefinition implements typed.ResourceDefinition interface. -func (c MemoryRD) ResourceDefinition(resource.Metadata, MemorySpec) meta.ResourceDefinitionSpec { +func (c MemoryModuleRD) ResourceDefinition(resource.Metadata, MemoryModuleSpec) meta.ResourceDefinitionSpec { return meta.ResourceDefinitionSpec{ - Type: MemoryType, + Type: MemoryModuleType, Aliases: []resource.Type{ - "memory", + "memorymodules", "ram", }, DefaultNamespace: NamespaceName,