Skip to content

Commit 82394d7

Browse files
phillipsjbrandond
authored andcommitted
Basic windows agent that will join a cluster without CNI.
Signed-off-by: Jamie Phillips <[email protected]>
1 parent 136dddc commit 82394d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2216
-1843
lines changed

Diff for: go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/rancher/k3s
33
go 1.16
44

55
replace (
6-
github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.8.9
6+
github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.8.10
77
github.com/benmoss/go-powershell => github.com/k3s-io/go-powershell v0.0.0-20201118222746-51f4c451fbd7
88
github.com/containerd/btrfs => github.com/containerd/btrfs v0.0.0-20201111183144-404b9149801e
99
github.com/containerd/cgroups => github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340
@@ -66,6 +66,7 @@ replace (
6666
)
6767

6868
require (
69+
github.com/Microsoft/hcsshim v0.8.10-0.20200715222032-5eafd1556990
6970
github.com/bronze1man/goStrongswanVici v0.0.0-20190828090544-27d02f80ba40 // indirect
7071
github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340
7172
github.com/containerd/containerd v1.5.0-beta.4

Diff for: go.sum

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YH
6161
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
6262
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
6363
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
64+
github.com/Microsoft/go-winio v0.4.15-0.20200908182639-5b44b70ab3ab/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
6465
github.com/Microsoft/go-winio v0.4.15 h1:qkLXKzb1QoVatRyd/YlXZ/Kg0m5K3SPuoD82jjSOaBc=
6566
github.com/Microsoft/go-winio v0.4.15/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
66-
github.com/Microsoft/hcsshim v0.8.9 h1:VrfodqvztU8YSOvygU+DN1BGaSGxmrNfqOv5oOuX2Bk=
67-
github.com/Microsoft/hcsshim v0.8.9/go.mod h1:5692vkUqntj1idxauYlpoINNKeqCiG6Sg38RRsjT5y8=
67+
github.com/Microsoft/hcsshim v0.8.10 h1:k5wTrpnVU2/xv8ZuzGkbXVd3js5zJ8RnumPo5RxiIxU=
68+
github.com/Microsoft/hcsshim v0.8.10/go.mod h1:g5uw8EV2mAlzqe94tfNBNdr89fnbD/n3HV0OhsddkmM=
6869
github.com/Microsoft/hcsshim/test v0.0.0-20200803203718-d80bc7196cb0 h1:+qqN+HZE55Zap8OE1BmcVStbX6JHVhqeWKPi0kzF1eA=
6970
github.com/Microsoft/hcsshim/test v0.0.0-20200803203718-d80bc7196cb0/go.mod h1:30A5igQ91GEmhYJF8TaRP79pMBOYynRsyOByfVV0dU4=
7071
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
@@ -940,7 +941,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1
940941
github.com/u-root/u-root v7.0.0+incompatible/go.mod h1:RYkpo8pTHrNjW08opNd/U6p/RJE7K0D8fXO0d47+3YY=
941942
github.com/ugorji/go v0.0.0-20170107133203-ded73eae5db7/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
942943
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
943-
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
944944
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
945945
github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ=
946946
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=

Diff for: pkg/agent/config/config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
461461
if !envInfo.Debug {
462462
nodeConfig.Containerd.Log = filepath.Join(envInfo.DataDir, "agent", "containerd", "containerd.log")
463463
}
464-
nodeConfig.Containerd.State = "/run/k3s/containerd"
465-
nodeConfig.Containerd.Address = filepath.Join(nodeConfig.Containerd.State, "containerd.sock")
464+
applyContainerdStateAndAddress(nodeConfig)
466465
nodeConfig.Containerd.Template = filepath.Join(envInfo.DataDir, "agent", "etc", "containerd", "config.toml.tmpl")
467466
nodeConfig.Certificate = servingCert
468467

Diff for: pkg/agent/config/config_linux.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// +build linux
2+
3+
package config
4+
5+
import (
6+
"path/filepath"
7+
8+
"github.com/rancher/k3s/pkg/daemons/config"
9+
)
10+
11+
func applyContainerdStateAndAddress(nodeConfig *config.Node) {
12+
nodeConfig.Containerd.State = "/run/k3s/containerd"
13+
nodeConfig.Containerd.Address = filepath.Join(nodeConfig.Containerd.State, "containerd.sock")
14+
}

Diff for: pkg/agent/config/config_windows.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package config
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/rancher/k3s/pkg/daemons/config"
7+
)
8+
9+
func applyContainerdStateAndAddress(nodeConfig *config.Node) {
10+
nodeConfig.Containerd.State = filepath.Join(nodeConfig.Containerd.Root, "state")
11+
nodeConfig.Containerd.Address = "npipe://///./pipe/containerd-containerd"
12+
}

Diff for: pkg/agent/containerd/config_linux.go

+39
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"io/ioutil"
88
"os"
9+
"time"
910

1011
"github.com/opencontainers/runc/libcontainer/system"
1112
"github.com/pkg/errors"
@@ -17,8 +18,22 @@ import (
1718
"github.com/rancher/wharfie/pkg/registries"
1819
"github.com/sirupsen/logrus"
1920
"golang.org/x/sys/unix"
21+
"google.golang.org/grpc"
22+
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
23+
"k8s.io/kubernetes/pkg/kubelet/util"
2024
)
2125

26+
func getContainerdArgs(cfg *config.Node) []string {
27+
args := []string{
28+
"containerd",
29+
"-c", cfg.Containerd.Config,
30+
"-a", cfg.Containerd.Address,
31+
"--state", cfg.Containerd.State,
32+
"--root", cfg.Containerd.Root,
33+
}
34+
return args
35+
}
36+
2237
// setupContainerdConfig generates the containerd.toml, using a template combined with various
2338
// runtime configurations and registry mirror settings provided by the administrator.
2439
func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
@@ -71,3 +86,27 @@ func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
7186

7287
return util2.WriteFile(cfg.Containerd.Config, parsedTemplate)
7388
}
89+
90+
// criConnection connects to a CRI socket at the given path.
91+
func CriConnection(ctx context.Context, address string) (*grpc.ClientConn, error) {
92+
addr, dialer, err := util.GetAddressAndDialer("unix://" + address)
93+
if err != nil {
94+
return nil, err
95+
}
96+
97+
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(3*time.Second), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
98+
if err != nil {
99+
return nil, err
100+
}
101+
102+
c := runtimeapi.NewRuntimeServiceClient(conn)
103+
_, err = c.Version(ctx, &runtimeapi.VersionRequest{
104+
Version: "0.1.0",
105+
})
106+
if err != nil {
107+
conn.Close()
108+
return nil, err
109+
}
110+
111+
return conn, nil
112+
}

Diff for: pkg/agent/containerd/config_windows.go

+75-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,86 @@ package containerd
44

55
import (
66
"context"
7+
"io/ioutil"
8+
"os"
9+
"time"
710

11+
"github.com/rancher/k3s/pkg/agent/templates"
12+
util2 "github.com/rancher/k3s/pkg/agent/util"
813
"github.com/rancher/k3s/pkg/daemons/config"
14+
"github.com/rancher/wharfie/pkg/registries"
15+
"github.com/sirupsen/logrus"
16+
"google.golang.org/grpc"
17+
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
18+
"k8s.io/kubernetes/pkg/kubelet/util"
919
)
1020

21+
func getContainerdArgs(cfg *config.Node) []string {
22+
args := []string{
23+
"containerd",
24+
"-c", cfg.Containerd.Config,
25+
}
26+
return args
27+
}
28+
1129
// setupContainerdConfig generates the containerd.toml, using a template combined with various
1230
// runtime configurations and registry mirror settings provided by the administrator.
1331
func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
14-
// TODO: Create windows config setup.
15-
return nil
32+
privRegistries, err := registries.GetPrivateRegistries(cfg.AgentConfig.PrivateRegistry)
33+
if err != nil {
34+
return err
35+
}
36+
37+
if cfg.SELinux {
38+
logrus.Warn("SELinux isn't supported on windows")
39+
}
40+
41+
var containerdTemplate string
42+
43+
containerdConfig := templates.ContainerdConfig{
44+
NodeConfig: cfg,
45+
DisableCgroup: true,
46+
IsRunningInUserNS: false,
47+
PrivateRegistryConfig: privRegistries.Registry(),
48+
}
49+
50+
containerdTemplateBytes, err := ioutil.ReadFile(cfg.Containerd.Template)
51+
if err == nil {
52+
logrus.Infof("Using containerd template at %s", cfg.Containerd.Template)
53+
containerdTemplate = string(containerdTemplateBytes)
54+
} else if os.IsNotExist(err) {
55+
containerdTemplate = templates.ContainerdConfigTemplate
56+
} else {
57+
return err
58+
}
59+
parsedTemplate, err := templates.ParseTemplateFromConfig(containerdTemplate, containerdConfig)
60+
if err != nil {
61+
return err
62+
}
63+
64+
return util2.WriteFile(cfg.Containerd.Config, parsedTemplate)
65+
}
66+
67+
// criConnection connects to a CRI socket at the given path.
68+
func CriConnection(ctx context.Context, address string) (*grpc.ClientConn, error) {
69+
addr, dialer, err := util.GetAddressAndDialer(address)
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(3*time.Second), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
c := runtimeapi.NewRuntimeServiceClient(conn)
80+
_, err = c.Version(ctx, &runtimeapi.VersionRequest{
81+
Version: "0.1.0",
82+
})
83+
if err != nil {
84+
conn.Close()
85+
return nil, err
86+
}
87+
88+
return conn, nil
1689
}

Diff for: pkg/agent/containerd/containerd.go

+1-32
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/sirupsen/logrus"
3333
"google.golang.org/grpc"
3434
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
35-
"k8s.io/kubernetes/pkg/kubelet/util"
3635
)
3736

3837
const (
@@ -42,13 +41,7 @@ const (
4241
// Run configures and starts containerd as a child process. Once it is up, images are preloaded
4342
// or pulled from files found in the agent images directory.
4443
func Run(ctx context.Context, cfg *config.Node) error {
45-
args := []string{
46-
"containerd",
47-
"-c", cfg.Containerd.Config,
48-
"-a", cfg.Containerd.Address,
49-
"--state", cfg.Containerd.State,
50-
"--root", cfg.Containerd.Root,
51-
}
44+
args := getContainerdArgs(cfg)
5245

5346
if err := setupContainerdConfig(ctx, cfg); err != nil {
5447
return err
@@ -116,30 +109,6 @@ func Run(ctx context.Context, cfg *config.Node) error {
116109
return preloadImages(ctx, cfg)
117110
}
118111

119-
// criConnection connects to a CRI socket at the given path.
120-
func CriConnection(ctx context.Context, address string) (*grpc.ClientConn, error) {
121-
addr, dialer, err := util.GetAddressAndDialer("unix://" + address)
122-
if err != nil {
123-
return nil, err
124-
}
125-
126-
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(3*time.Second), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
127-
if err != nil {
128-
return nil, err
129-
}
130-
131-
c := runtimeapi.NewRuntimeServiceClient(conn)
132-
_, err = c.Version(ctx, &runtimeapi.VersionRequest{
133-
Version: "0.1.0",
134-
})
135-
if err != nil {
136-
conn.Close()
137-
return nil, err
138-
}
139-
140-
return conn, nil
141-
}
142-
143112
// preloadImages reads the contents of the agent images directory, and attempts to
144113
// import into containerd any files found there. Supported compressed types are decompressed, and
145114
// any .txt files are processed as a list of images that should be pre-pulled from remote registries.

Diff for: pkg/agent/run.go

-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package agent
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
76
"net/url"
87
"os"
98
"path/filepath"
@@ -43,35 +42,6 @@ import (
4342
utilpointer "k8s.io/utils/pointer"
4443
)
4544

46-
const (
47-
dockershimSock = "unix:///var/run/dockershim.sock"
48-
containerdSock = "unix:///run/k3s/containerd/containerd.sock"
49-
)
50-
51-
// setupCriCtlConfig creates the crictl config file and populates it
52-
// with the given data from config.
53-
func setupCriCtlConfig(cfg cmds.Agent, nodeConfig *daemonconfig.Node) error {
54-
cre := nodeConfig.ContainerRuntimeEndpoint
55-
if cre == "" {
56-
switch {
57-
case cfg.Docker:
58-
cre = dockershimSock
59-
default:
60-
cre = containerdSock
61-
}
62-
}
63-
64-
agentConfDir := filepath.Join(cfg.DataDir, "agent", "etc")
65-
if _, err := os.Stat(agentConfDir); os.IsNotExist(err) {
66-
if err := os.MkdirAll(agentConfDir, 0700); err != nil {
67-
return err
68-
}
69-
}
70-
71-
crp := "runtime-endpoint: " + cre + "\n"
72-
return ioutil.WriteFile(agentConfDir+"/crictl.yaml", []byte(crp), 0600)
73-
}
74-
7545
func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
7646
nodeConfig := config.Get(ctx, cfg, proxy)
7747

Diff for: pkg/agent/run_linux.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// +build linux
2+
3+
package agent
4+
5+
import (
6+
"io/ioutil"
7+
"os"
8+
"path/filepath"
9+
10+
"github.com/rancher/k3s/pkg/cli/cmds"
11+
"github.com/rancher/k3s/pkg/daemons/config"
12+
)
13+
14+
const (
15+
dockershimSock = "unix:///var/run/dockershim.sock"
16+
containerdSock = "unix:///run/k3s/containerd/containerd.sock"
17+
)
18+
19+
// setupCriCtlConfig creates the crictl config file and populates it
20+
// with the given data from config.
21+
func setupCriCtlConfig(cfg cmds.Agent, nodeConfig *config.Node) error {
22+
cre := nodeConfig.ContainerRuntimeEndpoint
23+
if cre == "" {
24+
switch {
25+
case cfg.Docker:
26+
cre = dockershimSock
27+
default:
28+
cre = containerdSock
29+
}
30+
}
31+
32+
agentConfDir := filepath.Join(cfg.DataDir, "agent", "etc")
33+
if _, err := os.Stat(agentConfDir); os.IsNotExist(err) {
34+
if err := os.MkdirAll(agentConfDir, 0700); err != nil {
35+
return err
36+
}
37+
}
38+
39+
crp := "runtime-endpoint: " + cre + "\n"
40+
return ioutil.WriteFile(agentConfDir+"/crictl.yaml", []byte(crp), 0600)
41+
}

0 commit comments

Comments
 (0)