Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sriov: Add WithRdmaMode method #790

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/sriov/poolconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,33 @@ func (builder *PoolConfigBuilder) WithMaxUnavailable(maxUnavailable intstrutil.I
return builder
}

// WithRDMAMode method sets rdmaMode to shared/exclusive.
func (builder *PoolConfigBuilder) WithRDMAMode(mode string) *PoolConfigBuilder {
if valid, _ := builder.validate(); !valid {
return builder
}

if mode == "" {
klaskosk marked this conversation as resolved.
Show resolved Hide resolved
glog.V(100).Info("PoolConfig RdmaMode cannot be empty")

builder.errorMsg = "rdmaMode cannot be empty"

return builder
}

if mode != "shared" && mode != "exclusive" {
glog.V(100).Info("Invalid RdmaMode. Acceptable values: shared or exclusive")

builder.errorMsg = "invalid value for rdmaMode. It should be 'shared' or 'exclusive'"

return builder
}

builder.Definition.Spec.RdmaMode = mode

return builder
}

// PullPoolConfig pulls existing SriovNetworkPoolConfig from cluster.
func PullPoolConfig(apiClient *clients.Settings, name, nsname string) (*PoolConfigBuilder, error) {
glog.V(100).Infof("Pulling existing SriovNetworkPoolConfig name %s under namespace %s from cluster", name, nsname)
Expand Down
34 changes: 34 additions & 0 deletions pkg/sriov/poolconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@ func TestWithMaxUnavailable(t *testing.T) {
}
}

func TestWithRDMAMode(t *testing.T) {
testCases := []struct {
RdmaMode string
ExpectedError string
}{
{
RdmaMode: "shared",
ExpectedError: "",
},
{
RdmaMode: "exclusive",
ExpectedError: "",
},
{
RdmaMode: "",
ExpectedError: "rdmaMode cannot be empty",
},
{
RdmaMode: "none",
ExpectedError: "invalid value for rdmaMode. It should be 'shared' or 'exclusive'",
},
}

for _, testCase := range testCases {
testSettings := buildTestPoolConfigClientWithDummyObject()
testBuilder := buildValidPoolConfigTestBuilder(testSettings).WithRDMAMode(testCase.RdmaMode)
assert.Equal(t, testCase.ExpectedError, testBuilder.errorMsg)

if testCase.ExpectedError == "" {
assert.Equal(t, testBuilder.Definition.Spec.RdmaMode, testCase.RdmaMode)
}
}
}

func TestPullPoolConfig(t *testing.T) {
testCases := []struct {
poolConfigName string
Expand Down
Loading