Skip to content

Commit

Permalink
fix(galaxy): galaxy-underlay-veth support current.Result
Browse files Browse the repository at this point in the history
  • Loading branch information
00pf00 committed Aug 4, 2023
1 parent 3d9d578 commit 18756b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 21 additions & 1 deletion cni/underlay/veth/veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/containernetworking/cni/pkg/types/current"
"net"
"runtime"

Expand Down Expand Up @@ -102,5 +103,24 @@ func cmdAdd(args *skel.CmdArgs) error {
}
args.IfName = ifName
result, _ := t020.GetResult(results[0])
return result.Print()
if conf.CNIVersion == result.CNIVersion || conf.CNIVersion == "" {
return result.Print()
}

currentResult := &current.Result{}
currentResult.IPs = []*current.IPConfig{
{
Version: "4",
Gateway: result.IP4.Gateway,
Address: result.IP4.IP,
},
}
currentResult.Routes = []*types.Route{}

for _, r := range result.IP4.Routes {
currentResult.Routes = append(currentResult.Routes, &r)
}
currentResult.CNIVersion = conf.CNIVersion
currentResult.DNS = result.DNS
return currentResult.Print()
}
5 changes: 3 additions & 2 deletions pkg/galaxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (g *Galaxy) requestFunc(req *galaxyapi.PodRequest) (data []byte, err error)
return
}
result, err1 := g.cmdAdd(req, pod)
glog.Infof("delegate add result %v", result)
if err1 != nil {
err = err1
return
Expand Down Expand Up @@ -444,11 +445,11 @@ func convertResult(result types.Result) (*t020.Result, error) {
return nil, fmt.Errorf("faild to convert result to current/020 result")
}
} else {
result, err := resultCurrent.GetAsVersion(t020.ImplementedSpecVersion)
targetResult, err := resultCurrent.GetAsVersion(t020.ImplementedSpecVersion)
if err != nil {
return nil, err
}
result020, ok = result.(*t020.Result)
result020, ok = targetResult.(*t020.Result)
if !ok {
return nil, fmt.Errorf("faild to convert result to 020 result")
}
Expand Down

0 comments on commit 18756b1

Please sign in to comment.