Skip to content

Commit

Permalink
Add some small fixes in flannel-windows
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Buil <[email protected]>
  • Loading branch information
manuelbuil committed Apr 5, 2024
1 parent 59a7770 commit 2f3f1d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/pebinaryexecutor/pebinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (p *PEBinaryConfig) KubeProxy(ctx context.Context, args []string) error {
CNIConfig := p.CNIPlugin.GetConfig()
vip, err := p.CNIPlugin.ReserveSourceVip(ctx)
if err != nil || vip == "" {
logrus.Errorf("Failed to reserve VIP for kube-proxy: %s", err)
logrus.Errorf("Failed to reserve VIP for kube-proxy: %v", err)
}
logrus.Infof("Reserved VIP for kube-proxy: %s", vip)

Expand Down
27 changes: 17 additions & 10 deletions pkg/windows/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ type Flannel struct {
}

type SourceVipResponse struct {
IP4 struct {
IP string `json:"ip"`
} `json:"ip4"`
CniVersion string `json:"cniVersion"`
IPs []struct {
Address string `json:"address"`
Gateway string `json:"gateway"`
} `json:"ips"`
DNS struct{} `json:"dns"`
}

const (
Expand Down Expand Up @@ -333,8 +336,8 @@ func (f *Flannel) ReserveSourceVip(ctx context.Context) (string, error) {
logrus.Debugf("host-local will use the following subnet: %v to reserve the sourceIP", subnet)

configData := `{
"cniVersion": "0.2.0",
"name": "vxlan0",
"cniVersion": "1.0.0",
"name": "flannel.4096",
"ipam": {
"type": "host-local",
"ranges": [[{"subnet":"` + subnet + `"}]],
Expand All @@ -345,17 +348,17 @@ func (f *Flannel) ReserveSourceVip(ctx context.Context) (string, error) {
cmd := exec.Command("host-local.exe")
cmd.Env = append(os.Environ(),
"CNI_COMMAND=ADD",
"CNI_CONTAINERID=dummy",
"CNI_NETNS=dummy",
"CNI_IFNAME=dummy",
"CNI_CONTAINERID=kube-proxy",
"CNI_NETNS=kube-proxy",
"CNI_IFNAME=source-vip",
"CNI_PATH="+f.CNICfg.CNIBinDir,
)

cmd.Stdin = strings.NewReader(configData)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.WithError(err).Warning("Failed to execute host-local.exe")
logrus.Errorf("This is the output: %v", strings.TrimSpace(string(out)))
logrus.Infof("This is the output: %v", strings.TrimSpace(string(out)))
return "", err
}

Expand All @@ -367,5 +370,9 @@ func (f *Flannel) ReserveSourceVip(ctx context.Context) (string, error) {
return "", err
}

return strings.TrimSpace(strings.Split(sourceVipResp.IP4.IP, "/")[0]), nil
if len(sourceVipResp.IPs) > 0 {
return strings.TrimSpace(strings.Split(sourceVipResp.IPs[0].Address, "/")[0]), nil
}

return "", errors.New("no source vip reserved")
}

0 comments on commit 2f3f1d6

Please sign in to comment.