mirror of https://github.com/k3s-io/k3s
[K3s][Windows Port] Build script, multi-call binary, and Flannel (#7259)
* initial windows port. Signed-off-by: Sean Yen <seanyen@microsoft.com> Signed-off-by: Derek Nola <derek.nola@suse.com> Co-authored-by: Derek Nola <derek.nola@suse.com> Co-authored-by: Wei Ran <weiran@microsoft.com>pull/8667/head
parent
aaf8409096
commit
0c9bf36fe0
@ -0,0 +1,20 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const programPostfix = ""
|
||||
|
||||
func runExec(cmd string, args []string, calledAsInternal bool) (err error) {
|
||||
if err := syscall.Exec(cmd, args, os.Environ()); err != nil {
|
||||
return errors.Wrapf(err, "exec %s failed", cmd)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
const programPostfix = ".exe"
|
||||
|
||||
func runExec(cmd string, args []string, calledAsInternal bool) (err error) {
|
||||
// syscall.Exec: not supported by windows
|
||||
if calledAsInternal {
|
||||
args = args[1:]
|
||||
}
|
||||
cmdObj := exec.Command(cmd, args...)
|
||||
cmdObj.Stdout = os.Stdout
|
||||
cmdObj.Stderr = os.Stderr
|
||||
cmdObj.Stdin = os.Stdin
|
||||
cmdObj.Env = os.Environ()
|
||||
return cmdObj.Run()
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package flannel
|
||||
|
||||
const (
|
||||
cniConf = `{
|
||||
"name":"cbr0",
|
||||
"cniVersion":"1.0.0",
|
||||
"plugins":[
|
||||
{
|
||||
"type":"flannel",
|
||||
"delegate":{
|
||||
"hairpinMode":true,
|
||||
"forceAddress":true,
|
||||
"isDefaultGateway":true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type":"portmap",
|
||||
"capabilities":{
|
||||
"portMappings":true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type":"bandwidth",
|
||||
"capabilities":{
|
||||
"bandwidth":true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
vxlanBackend = `{
|
||||
"Type": "vxlan"
|
||||
}`
|
||||
)
|
@ -0,0 +1,59 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package flannel
|
||||
|
||||
const (
|
||||
cniConf = `{
|
||||
"name":"flannel.4096",
|
||||
"cniVersion":"1.0.0",
|
||||
"plugins":[
|
||||
{
|
||||
"type":"flannel",
|
||||
"capabilities": {
|
||||
"portMappings": true,
|
||||
"dns": true
|
||||
},
|
||||
"delegate": {
|
||||
"type": "win-overlay",
|
||||
"apiVersion": 2,
|
||||
"Policies": [{
|
||||
"Name": "EndpointPolicy",
|
||||
"Value": {
|
||||
"Type": "OutBoundNAT",
|
||||
"Settings": {
|
||||
"Exceptions": [
|
||||
"%CLUSTER_CIDR%", "%SERVICE_CIDR%"
|
||||
]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"Name": "EndpointPolicy",
|
||||
"Value": {
|
||||
"Type": "SDNRoute",
|
||||
"Settings": {
|
||||
"DestinationPrefix": "%SERVICE_CIDR%",
|
||||
"NeedEncap": true
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"name": "EndpointPolicy",
|
||||
"value": {
|
||||
"Type": "ProviderAddress",
|
||||
"Settings": {
|
||||
"ProviderAddress": "%IPV4_ADDRESS%"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
vxlanBackend = `{
|
||||
"Type": "vxlan",
|
||||
"VNI": 4096,
|
||||
"Port": 4789
|
||||
}`
|
||||
)
|
@ -1,11 +1,17 @@
|
||||
package crictl
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/kubernetes-sigs/cri-tools/cmd/crictl"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func Run(ctx *cli.Context) error {
|
||||
if runtime.GOOS == "windows" {
|
||||
os.Args = os.Args[1:]
|
||||
}
|
||||
crictl.Main()
|
||||
return nil
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
//go:build ctrd
|
||||
// +build ctrd
|
||||
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package containerd
|
||||
|
||||
import (
|
||||
_ "github.com/containerd/containerd/diff/lcow"
|
||||
_ "github.com/containerd/containerd/diff/windows"
|
||||
_ "github.com/containerd/containerd/snapshots/lcow"
|
||||
_ "github.com/containerd/containerd/snapshots/windows"
|
||||
)
|
@ -0,0 +1,16 @@
|
||||
//go:build linux && !no_embedded_executor
|
||||
// +build linux,!no_embedded_executor
|
||||
|
||||
package executor
|
||||
|
||||
import (
|
||||
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
|
||||
|
||||
// registering k3s cloud provider
|
||||
_ "github.com/k3s-io/k3s/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
func platformKubeProxyArgs(nodeConfig *daemonconfig.Node) map[string]string {
|
||||
argsMap := map[string]string{}
|
||||
return argsMap
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
//go:build windows && !no_embedded_executor
|
||||
// +build windows,!no_embedded_executor
|
||||
|
||||
package executor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
// registering k3s cloud provider
|
||||
_ "github.com/k3s-io/k3s/pkg/cloudprovider"
|
||||
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
|
||||
)
|
||||
|
||||
const (
|
||||
networkName = "flannel.4096"
|
||||
)
|
||||
|
||||
type SourceVipResponse struct {
|
||||
IP4 struct {
|
||||
IP string `json:"ip"`
|
||||
} `json:"ip4"`
|
||||
}
|
||||
|
||||
func platformKubeProxyArgs(nodeConfig *daemonconfig.Node) map[string]string {
|
||||
argsMap := map[string]string{}
|
||||
argsMap["network-name"] = networkName
|
||||
if sourceVip := waitForSourceVip(networkName, nodeConfig); sourceVip != "" {
|
||||
argsMap["source-vip"] = sourceVip
|
||||
}
|
||||
return argsMap
|
||||
}
|
||||
|
||||
func waitForSourceVip(networkName string, nodeConfig *daemonconfig.Node) string {
|
||||
for range time.Tick(time.Second * 5) {
|
||||
network, err := hcsshim.GetHNSNetworkByName(networkName)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warningf("can't find HNS network, retrying %s", networkName)
|
||||
continue
|
||||
}
|
||||
if network.ManagementIP == "" {
|
||||
logrus.WithError(err).Warningf("wait for management IP, retrying %s", networkName)
|
||||
continue
|
||||
}
|
||||
|
||||
subnet := network.Subnets[0].AddressPrefix
|
||||
|
||||
configData := `{
|
||||
"cniVersion": "0.2.0",
|
||||
"name": "vxlan0",
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"ranges": [[{"subnet":"` + subnet + `"}]],
|
||||
"dataDir": "/var/lib/cni/networks"
|
||||
}
|
||||
}`
|
||||
|
||||
cmd := exec.Command("host-local.exe")
|
||||
cmd.Env = append(os.Environ(),
|
||||
"CNI_COMMAND=ADD",
|
||||
"CNI_CONTAINERID=dummy",
|
||||
"CNI_NETNS=dummy",
|
||||
"CNI_IFNAME=dummy",
|
||||
"CNI_PATH="+nodeConfig.AgentConfig.CNIBinDir,
|
||||
)
|
||||
|
||||
cmd.Stdin = strings.NewReader(configData)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warning("Failed to execute host-local.exe")
|
||||
continue
|
||||
}
|
||||
|
||||
var sourceVipResp SourceVipResponse
|
||||
err = json.Unmarshal(out, &sourceVipResp)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warning("Failed to unmarshal sourceVip response")
|
||||
continue
|
||||
}
|
||||
|
||||
return strings.TrimSpace(strings.Split(sourceVipResp.IP4.IP, "/")[0])
|
||||
}
|
||||
return ""
|
||||
}
|
Loading…
Reference in new issue