Skip to content

Commit

Permalink
fix(CSI-260): lookup of NFS interface group fails when empty name pro…
Browse files Browse the repository at this point in the history
…vided
  • Loading branch information
sergeyberezansky committed Sep 23, 2024
1 parent 1145363 commit 968dd78
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions pkg/wekafs/apiclient/interfacegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,42 +152,45 @@ func (a *ApiClient) fetchNfsInterfaceGroup(ctx context.Context, name *string, us
if len(*igs) == 0 {
return errors.New("no nfs interface groups found")
}
if name != nil {
for _, ig := range *igs {
if ig.Name == *name {
a.NfsInterfaceGroups[*name] = &ig

// according to calling function, if name is not provided, useDefault is set to true
if useDefault {
// If no name is provided, use the first IG that has at least one IP. useDefault is true -> name not provided!
for _, ig := range a.NfsInterfaceGroups {
if len(ig.Ips) > 0 {
a.NfsInterfaceGroups["default"] = ig
sort.Strings(a.NfsInterfaceGroups["default"].Ips)
return nil
}
}
} else if useDefault {
a.NfsInterfaceGroups["default"] = &(*igs)[0]
}

ig := &InterfaceGroup{}
if name != nil {
ig = a.NfsInterfaceGroups[*name]
} else {
ig = a.NfsInterfaceGroups["default"]
}
if ig == nil {
return errors.New("no nfs interface group found")
return errors.New("no nfs interface group with IP addresses found")
}

if len(ig.Ips) == 0 {
return errors.New("no IP addresses found for nfs interface group")
for _, ig := range *igs {
if ig.Name == *name {
if len(ig.Ips) == 0 {
return errors.New("no IP addresses found for nfs interface group \"" + *name + "\"")
}
a.NfsInterfaceGroups[ig.Name] = &ig
sort.Strings(a.NfsInterfaceGroups[ig.Name].Ips)
return nil
}
return errors.New(fmt.Sprintf("no nfs interface group named '%s' found", *name))
}
// Make sure the IPs are always sorted
sort.Strings(ig.Ips)
return nil
return errors.New("no valid nfs interface group found")
}

func (a *ApiClient) GetNfsInterfaceGroup(ctx context.Context, name *string) *InterfaceGroup {
igName := "default"
if name != nil {
useDefault := false
if name != nil && *name != "" {
igName = *name
} else {
useDefault = true
}
_, ok := a.NfsInterfaceGroups[igName]
if !ok {
err := a.fetchNfsInterfaceGroup(ctx, name, true)
err := a.fetchNfsInterfaceGroup(ctx, name, useDefault)
if err != nil {
return nil
}
Expand Down

0 comments on commit 968dd78

Please sign in to comment.