Skip to content

Commit

Permalink
chore: rename memory to memorymodules
Browse files Browse the repository at this point in the history
Rename `memory` to `memorymodules` to be more explicit

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed May 26, 2022
1 parent 9c4b7d6 commit 00515b4
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 81 deletions.
54 changes: 0 additions & 54 deletions internal/app/machined/pkg/adapters/hardware/memory.go

This file was deleted.

54 changes: 54 additions & 0 deletions internal/app/machined/pkg/adapters/hardware/memorymodule.go
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 3 additions & 3 deletions internal/app/machined/pkg/controllers/hardware/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (ctrl *SystemInfoController) Outputs() []controller.Output {
Kind: controller.OutputExclusive,
},
{
Type: hardware.MemoryType,
Type: hardware.MemoryModuleType,
Kind: controller.OutputExclusive,
},
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/app/machined/pkg/controllers/hardware/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewState() (*State, error) {
&files.EtcFileSpec{},
&files.EtcFileStatus{},
&hardware.Processor{},
&hardware.Memory{},
&hardware.MemoryModule{},
&k8s.AdmissionControlConfig{},
&k8s.APIServerConfig{},
&k8s.ConfigStatus{},
Expand Down
4 changes: 2 additions & 2 deletions pkg/machinery/resources/hardware/deep_copy.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/machinery/resources/hardware/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion pkg/machinery/resources/hardware/hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand Down

0 comments on commit 00515b4

Please sign in to comment.