Skip to content

Commit b9ed77e

Browse files
authored
Default nconnect mount option for AKS extension
1 parent a1bd0b8 commit b9ed77e

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

operator/controllers/configurator/storage_drivers/anf.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
"github.com/netapp/trident/storage_drivers/azure/api"
2121
)
2222

23+
const (
24+
MountOptionNconnect = "4"
25+
)
26+
2327
type ANF struct {
2428
ANFConfig
2529

@@ -199,7 +203,7 @@ func (a *ANF) CreateStorageClass() error {
199203
}
200204

201205
for _, sc := range anfStorageClassMap.SCMap {
202-
scYAML := getANFStorageClassYAML(sc, config.AzureNASStorageDriverName, a.TridentNamespace)
206+
scYAML := getANFStorageClassYAML(sc, config.AzureNASStorageDriverName, a.TridentNamespace, MountOptionNconnect)
203207
err := a.ConfClient.CreateOrPatchObject(confClients.OStorageClass, sc.Name, "", scYAML)
204208
if err != nil {
205209
return err

operator/controllers/configurator/storage_drivers/yaml_factory.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package storage_drivers
44

55
import (
66
"fmt"
7+
"sort"
78
"strings"
89

910
"github.com/netapp/trident/config"
@@ -119,7 +120,7 @@ func constructClientCredentials(clientCred string) string {
119120
return cred
120121
}
121122

122-
func getANFStorageClassYAML(sc ANFStorageClass, backendType, namespace string) string {
123+
func getANFStorageClassYAML(sc ANFStorageClass, backendType, namespace, nconnect string) string {
123124
scYAML := anfStorageClassTemplate
124125

125126
scYAML = strings.ReplaceAll(scYAML, "{NAME}", sc.Name)
@@ -129,8 +130,11 @@ func getANFStorageClassYAML(sc ANFStorageClass, backendType, namespace string) s
129130

130131
if sc.NASType == sa.SMB {
131132
scYAML = strings.ReplaceAll(scYAML, "{AAD_SECRET}", constructAADSecret(namespace))
133+
scYAML = strings.ReplaceAll(scYAML, "{MOUNT_OPTIONS}", "")
132134
} else {
133135
scYAML = strings.ReplaceAll(scYAML, "{AAD_SECRET}", "")
136+
mountOptions := map[string]string{"nconnect": nconnect}
137+
scYAML = strings.ReplaceAll(scYAML, "{MOUNT_OPTIONS}", constructMountOptions(mountOptions))
134138
}
135139

136140
return scYAML
@@ -148,6 +152,7 @@ parameters:
148152
{AAD_SECRET}
149153
volumeBindingMode: Immediate
150154
allowVolumeExpansion: true
155+
{MOUNT_OPTIONS}
151156
`
152157

153158
func constructAADSecret(namespace string) string {
@@ -157,6 +162,26 @@ func constructAADSecret(namespace string) string {
157162
return aadSecret
158163
}
159164

165+
// constructMountOptions constructs the mount options for the storage class
166+
func constructMountOptions(mountOptions map[string]string) string {
167+
if len(mountOptions) == 0 {
168+
return ""
169+
}
170+
171+
keys := make([]string, 0, len(mountOptions))
172+
for key := range mountOptions {
173+
keys = append(keys, key)
174+
}
175+
sort.Strings(keys)
176+
177+
mountOptionsYAML := "mountOptions:\n"
178+
for _, key := range keys {
179+
mountOptionsYAML += fmt.Sprintf(" - %s=%s\n", key, mountOptions[key])
180+
}
181+
182+
return mountOptionsYAML
183+
}
184+
160185
// GetVolumeSnapshotClassYAML returns the VolumeSnapshotClass YAML
161186
func GetVolumeSnapshotClassYAML(name string) string {
162187
vscYAML := volumeSnapshotClassTemplate

operator/controllers/configurator/storage_drivers/yaml_factory_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,34 @@ func TestConstructANFSupportedTopologies(t *testing.T) {
7777
})
7878
}
7979
}
80+
81+
func TestConstructMountOptions(t *testing.T) {
82+
testCases := []struct {
83+
name string
84+
input map[string]string
85+
expected string
86+
}{
87+
{
88+
name: "No mount options",
89+
input: map[string]string{},
90+
expected: "",
91+
},
92+
{
93+
name: "Single mount option",
94+
input: map[string]string{"key1": "value1"},
95+
expected: "mountOptions:\n - key1=value1\n",
96+
},
97+
{
98+
name: "Multiple mount options",
99+
input: map[string]string{"key1": "value1", "key2": "value2"},
100+
expected: "mountOptions:\n - key1=value1\n - key2=value2\n",
101+
},
102+
}
103+
104+
for _, tc := range testCases {
105+
t.Run(tc.name, func(t *testing.T) {
106+
result := constructMountOptions(tc.input)
107+
assert.Equal(t, tc.expected, result, "Incorrect mount options string returned")
108+
})
109+
}
110+
}

0 commit comments

Comments
 (0)