Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how flannel-windows reserves an IP for kube-proxy vip #5661

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
Loading