Skip to content

Commit

Permalink
fix range loop
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Mar 14, 2022
1 parent 37937fc commit 5a52041
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,15 @@ func (c *Controller) initDefaultProviderNetwork() error {
pn.Spec.ExcludeNodes = append(pn.Spec.ExcludeNodes, node.Name)
newNode = node.DeepCopy()
} else if s := node.Annotations[interfaceAnno]; s != "" {
var index int
for index = range pn.Spec.CustomInterfaces {
if pn.Spec.CustomInterfaces[index].Interface == s {
var index *int
for i := range pn.Spec.CustomInterfaces {
if pn.Spec.CustomInterfaces[i].Interface == s {
index = &i
break
}
}
if index != len(pn.Spec.CustomInterfaces) {
pn.Spec.CustomInterfaces[index].Nodes = append(pn.Spec.CustomInterfaces[index].Nodes, node.Name)
if index != nil {
pn.Spec.CustomInterfaces[*index].Nodes = append(pn.Spec.CustomInterfaces[*index].Nodes, node.Name)
} else {
ci := kubeovnv1.CustomInterface{Interface: s, Nodes: []string{node.Name}}
pn.Spec.CustomInterfaces = append(pn.Spec.CustomInterfaces, ci)
Expand Down
11 changes: 6 additions & 5 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,15 @@ func (c *Controller) handleNodeAnnotationsForProviderNetworks(node *v1.Node) err
if newPn == nil {
newPn = pn.DeepCopy()
}
var index int
for index = range newPn.Spec.CustomInterfaces {
if newPn.Spec.CustomInterfaces[index].Interface == customInterface {
var index *int
for i := range newPn.Spec.CustomInterfaces {
if newPn.Spec.CustomInterfaces[i].Interface == customInterface {
index = &i
break
}
}
if index != len(newPn.Spec.CustomInterfaces) {
newPn.Spec.CustomInterfaces[index].Nodes = append(newPn.Spec.CustomInterfaces[index].Nodes, node.Name)
if index != nil {
newPn.Spec.CustomInterfaces[*index].Nodes = append(newPn.Spec.CustomInterfaces[*index].Nodes, node.Name)
} else {
ci := kubeovnv1.CustomInterface{Interface: customInterface, Nodes: []string{node.Name}}
newPn.Spec.CustomInterfaces = append(newPn.Spec.CustomInterfaces, ci)
Expand Down

0 comments on commit 5a52041

Please sign in to comment.