diff --git a/pkg/sriov/poolconfig.go b/pkg/sriov/poolconfig.go index 175f88704..a44744650 100644 --- a/pkg/sriov/poolconfig.go +++ b/pkg/sriov/poolconfig.go @@ -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 == "" { + 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) diff --git a/pkg/sriov/poolconfig_test.go b/pkg/sriov/poolconfig_test.go index 7e820431b..27146116d 100644 --- a/pkg/sriov/poolconfig_test.go +++ b/pkg/sriov/poolconfig_test.go @@ -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