Skip to content

Commit

Permalink
Merge pull request #178 from DataWorkflowServices/release-v0.0.16
Browse files Browse the repository at this point in the history
Release v0.0.16
  • Loading branch information
ajfloeder authored Feb 9, 2024
2 parents 071e418 + f49f216 commit 2b03433
Show file tree
Hide file tree
Showing 40 changed files with 189 additions and 4,432 deletions.
37 changes: 36 additions & 1 deletion api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Hewlett Packard Enterprise Development LP
* Copyright 2023-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 @@ -348,6 +348,26 @@ 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.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 @@ -360,6 +380,17 @@ func (dst *SystemConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
return err
}

// 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})
}
dst.Spec.ComputeNodes = computes

// Preserve Hub data on down-conversion except for metadata.
return utilconversion.MarshalData(src, dst)
}
Expand Down Expand Up @@ -509,6 +540,10 @@ func Convert_v1alpha2_WorkflowSpec_To_v1alpha1_WorkflowSpec(in *dwsv1alpha2.Work
return autoConvert_v1alpha2_WorkflowSpec_To_v1alpha1_WorkflowSpec(in, out, s)
}

func Convert_v1alpha1_SystemConfigurationSpec_To_v1alpha2_SystemConfigurationSpec(in *SystemConfigurationSpec, out *dwsv1alpha2.SystemConfigurationSpec, s apiconversion.Scope) error {
return autoConvert_v1alpha1_SystemConfigurationSpec_To_v1alpha2_SystemConfigurationSpec(in, out, s)
}

func Convert_v1alpha2_SystemConfigurationSpec_To_v1alpha1_SystemConfigurationSpec(in *dwsv1alpha2.SystemConfigurationSpec, out *SystemConfigurationSpec, s apiconversion.Scope) error {
return autoConvert_v1alpha2_SystemConfigurationSpec_To_v1alpha1_SystemConfigurationSpec(in, out, s)
}
63 changes: 60 additions & 3 deletions api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Hewlett Packard Enterprise Development LP
* Copyright 2023-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 All @@ -22,7 +22,10 @@ package v1alpha1
import (
"testing"

fuzz "github.com/google/gofuzz"
. "github.com/onsi/ginkgo/v2"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"

dwsv1alpha2 "github.com/DataWorkflowServices/dws/api/v1alpha2"
utilconversion "github.com/DataWorkflowServices/dws/github/cluster-api/util/conversion"
Expand Down Expand Up @@ -66,8 +69,9 @@ func TestFuzzyConversion(t *testing.T) {
}))

t.Run("for SystemConfiguration", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &dwsv1alpha2.SystemConfiguration{},
Spoke: &SystemConfiguration{},
Hub: &dwsv1alpha2.SystemConfiguration{},
Spoke: &SystemConfiguration{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{SystemConfigurationFuzzFunc},
}))

t.Run("for Workflow", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Expand All @@ -77,6 +81,59 @@ func TestFuzzyConversion(t *testing.T) {

}

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

// Use the same compute names in both spec.ComputeNodes and spec.StorageNodes.
// 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.
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})
}
}

// 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
// "make test", so that doesn't fail on this test file.
var _ = BeforeSuite(func() {})
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
}
51 changes: 8 additions & 43 deletions api/v1alpha1/zz_generated.conversion.go

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

2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

39 changes: 34 additions & 5 deletions api/v1alpha2/systemconfiguration_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 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 All @@ -26,8 +26,9 @@ import (
"github.com/DataWorkflowServices/dws/utils/updater"
)

// SystemConfigurationComputeNode describes a compute node in the system
type SystemConfigurationComputeNode struct {
// 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"`
}
Expand Down Expand Up @@ -57,8 +58,9 @@ 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 {
// ComputeNodes is the list of compute nodes on the system
ComputeNodes []SystemConfigurationComputeNode `json:"computeNodes,omitempty"`
// ExternalComputeNodes is the list of compute 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 @@ -113,3 +115,30 @@ type SystemConfigurationList struct {
func init() {
SchemeBuilder.Register(&SystemConfiguration{}, &SystemConfigurationList{})
}

func (in *SystemConfiguration) Computes() []*string {
// We expect that there can be a large number of compute nodes and we don't
// want to duplicate all of those names.
// So we'll walk spec.storageNodes twice so we can set the
// length/capacity for the array that will hold pointers to the names.
num := 0
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 {
for i3 := range in.Spec.StorageNodes[i2].ComputesAccess {
computes[idx] = &in.Spec.StorageNodes[i2].ComputesAccess[i3].Name
idx++
}
}
// Add the external computes.
for i4 := range in.Spec.ExternalComputeNodes {
computes[idx] = &in.Spec.ExternalComputeNodes[i4].Name
idx++
}
return computes
}
Loading

0 comments on commit 2b03433

Please sign in to comment.