Skip to content

Commit

Permalink
Replace spec.ComputeNodes with spec.ExternalComputeNodes to contain a…
Browse files Browse the repository at this point in the history
… list

of compute nodes that are not directly matched with any of the nodes in
the StorageNodes list.

Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe committed Feb 5, 2024
1 parent f1cae45 commit 3bed1e6
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 19 deletions.
29 changes: 24 additions & 5 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,25 @@ func (src *SystemConfiguration) ConvertTo(dstRaw conversion.Hub) error {
if hasAnno {
dst.Spec.PortsCooldownInSeconds = restored.Spec.PortsCooldownInSeconds

// dst.Spec.ComputeNodes --The destination does not have this; instead,
// it finds the computes that are already in the dst.Spec.StorageNodes
// list.
// dst.Spec.ComputeNodes: The destination does not have this.
// Instead, it finds the computes that are already in the
// dst.Spec.StorageNodes list.

dst.Spec.ExternalComputeNodes = restored.Spec.ExternalComputeNodes
} else {
// The v1alpha1 resource's spec.ComputeNodes list is a
// combination of all compute nodes from the spec.StorageNodes
// list as well as any external computes.
// The v1alpha1.FindExternalComputes() method walks through
// the spec.Computes list to determine which ones are external.
externComputes := src.FindExternalComputes()
dstExternComputes := make([]dwsv1alpha2.SystemConfigurationExternalComputeNode, len(externComputes))
idx := 0
for _, name := range externComputes {
dstExternComputes[idx].Name = name
idx++
}
dst.Spec.ExternalComputeNodes = dstExternComputes
}
return nil
}
Expand All @@ -364,8 +380,11 @@ func (dst *SystemConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
return err
}

// The v1alpha1 resource has the compute nodes in both the spec.ComputeNodes
// list and in the spec.StorageNodes list.
// The v1alpha1 resource's spec.ComputeNodes list is a combination
// of all compute nodes from the spec.StorageNodes list as well as any
// external computes.
// The v1alpha2 src.Computes() method returns all of that resource's
// compute nodes, of any type.
computes := make([]SystemConfigurationComputeNode, 0)
for _, name := range src.Computes() {
computes = append(computes, SystemConfigurationComputeNode{Name: *name})
Expand Down
50 changes: 37 additions & 13 deletions api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,55 @@ func TestFuzzyConversion(t *testing.T) {

func SystemConfigurationFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
SystemConfigurationComputesFuzzer,
SystemConfigurationComputesv1Fuzzer,
SystemConfigurationComputesv2Fuzzer,
}
}

// Use the same compute names in both spec.ComputeNodes and spec.StorageNodes.
func SystemConfigurationComputesFuzzer(in *SystemConfigurationSpec, c fuzz.Continue) {
// Add a breadcrumb to the fuzzed names to aid in debugging.
func SystemConfigurationComputesv1Fuzzer(in *SystemConfigurationSpec, c fuzz.Continue) {
// Tell the fuzzer to begin by fuzzing everything in the object.
c.FuzzNoCustom(in)

newComputes := make([]SystemConfigurationComputeNode, 0)

// Now pull any fuzzed compute names out of the spec.StorageNodes list and
// use them to build a new spec.ComputeNodes list.
if in.StorageNodes != nil {
computes := make([]SystemConfigurationComputeNode, 0)
for sidx := range in.StorageNodes {
for cidx := range in.StorageNodes[sidx].ComputesAccess {
name := c.RandString()
in.StorageNodes[sidx].ComputesAccess[cidx].Name = name
computes = append(computes, SystemConfigurationComputeNode{Name: name})
}
for sidx := range in.StorageNodes {
for cidx := range in.StorageNodes[sidx].ComputesAccess {
name := c.RandString() + "-lilo"
in.StorageNodes[sidx].ComputesAccess[cidx].Name = name
newComputes = append(newComputes, SystemConfigurationComputeNode{Name: name})
}
in.ComputeNodes = computes
} else {
in.ComputeNodes = nil
}

// Preserve any fuzzed names that may already be in the
// spec.ComputesNodes list; these are the "external computes".
for _, node := range in.ComputeNodes {
newComputes = append(newComputes, SystemConfigurationComputeNode{Name: node.Name + "-stitch"})
}

if len(newComputes) > 0 {
in.ComputeNodes = newComputes
}
}

// Add a breadcrumb to the fuzzed names to aid in debugging.
func SystemConfigurationComputesv2Fuzzer(in *dwsv1alpha2.SystemConfigurationSpec, c fuzz.Continue) {
// Tell the fuzzer to begin by fuzzing everything in the object.
c.FuzzNoCustom(in)

for sidx := range in.StorageNodes {
for cidx := range in.StorageNodes[sidx].ComputesAccess {
name := c.RandString() + "-jumba"
in.StorageNodes[sidx].ComputesAccess[cidx].Name = name
}
}
for eidx := range in.ExternalComputeNodes {
name := c.RandString() + "-pleakley"
in.ExternalComputeNodes[eidx].Name = name
}
}

// Just touch ginkgo, so it's here to interpret any ginkgo args from
Expand Down
27 changes: 26 additions & 1 deletion api/v1alpha1/systemconfiguration_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021, 2022 Hewlett Packard Enterprise Development LP
* Copyright 2021-2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
Expand Down Expand Up @@ -100,3 +100,28 @@ type SystemConfigurationList struct {
func init() {
SchemeBuilder.Register(&SystemConfiguration{}, &SystemConfigurationList{})
}

// FindExternalComputes will search the ComputeNodes list and return any that
// are not also found in the StorageNodes list. These are the external
// computes.
func (in *SystemConfiguration) FindExternalComputes() []string {
// Make a map of all the computes in the StorageNodes list, so they're
// easy to find.
storageComputes := make(map[string]struct{})
for i2 := range in.Spec.StorageNodes {
for i3 := range in.Spec.StorageNodes[i2].ComputesAccess {
name := in.Spec.StorageNodes[i2].ComputesAccess[i3].Name
storageComputes[name] = struct{}{}
}
}

// Cross-reference the spec.ComputeNodes list against the
// computes from the StorageNodes list.
var externComputes []string
for _, compute := range in.Spec.ComputeNodes {
if _, present := storageComputes[compute.Name]; !present {
externComputes = append(externComputes, compute.Name)
}
}
return externComputes
}
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.conversion.go

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

18 changes: 18 additions & 0 deletions api/v1alpha2/systemconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ import (
"github.com/DataWorkflowServices/dws/utils/updater"
)

// SystemConfigurationExternalComputeNode describes a compute node that is
// not directly matched with any of the nodes in the StorageNodes list.
type SystemConfigurationExternalComputeNode struct {
// Name of the compute node
Name string `json:"name"`
}

// SystemConfigurationComputeNodeReference describes a compute node that
// has access to a server.
type SystemConfigurationComputeNodeReference struct {
Expand All @@ -51,6 +58,10 @@ type SystemConfigurationStorageNode struct {
// SystemConfigurationSpec describes the node layout of the system. This is filled in by
// an administrator at software installation time.
type SystemConfigurationSpec struct {
// ExternalComputeNodes is the list of computes nodes that are not
// directly matched with any of the StorageNodes.
ExternalComputeNodes []SystemConfigurationExternalComputeNode `json:"externalComputeNodes,omitempty"`

// StorageNodes is the list of storage nodes on the system
StorageNodes []SystemConfigurationStorageNode `json:"storageNodes,omitempty"`

Expand Down Expand Up @@ -114,6 +125,8 @@ func (in *SystemConfiguration) Computes() []*string {
for i1 := range in.Spec.StorageNodes {
num += len(in.Spec.StorageNodes[i1].ComputesAccess)
}
// Add room for the external computes.
num += len(in.Spec.ExternalComputeNodes)
computes := make([]*string, num)
idx := 0
for i2 := range in.Spec.StorageNodes {
Expand All @@ -122,5 +135,10 @@ func (in *SystemConfiguration) Computes() []*string {
idx++
}
}
// Add the external computes.
for i4 := range in.Spec.ExternalComputeNodes {
computes[idx] = &in.Spec.ExternalComputeNodes[i4].Name
idx++
}
return computes
}
20 changes: 20 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ spec:
system. This is filled in by an administrator at software installation
time.
properties:
externalComputeNodes:
description: ExternalComputeNodes is the list of computes nodes that
are not directly matched with any of the StorageNodes.
items:
description: SystemConfigurationExternalComputeNode describes a
compute node that is not directly matched with any of the nodes
in the StorageNodes list.
properties:
name:
description: Name of the compute node
type: string
required:
- name
type: object
type: array
ports:
description: Ports is the list of ports available for communication
between nodes in the system. Valid values are single integers, or
Expand Down

0 comments on commit 3bed1e6

Please sign in to comment.